This chapter provides a programming guide and library reference for programmers of LASH clients.
In this section we give an overview of how the LASH system operates, describing the server and client objects and operations that make it work. The @command{lashd} server must be running in order for clients to participate in the system; clients cannot interoperate soley between themselves. The server maintains a list of connected clients and a list of projects with which these clients are associated.
The server and clients exchange events and configs over their connections. There is one, and only one, bi-directional connection between a client and the server. The transport for this connection is currently TCP.
An event is a very simple object having two relevant properties:
a type and an optional arbitrary character string. The type defines
what the event means to the recipient, and the string allows additional
information to be included with it. For example, if a client wishes
the server to save the current project, it sends a LASH_Save
event to the server. While saving the project, the server may wish to
tell a client to save its data in a certain directory. To so, it sends
a LASH_Save_File
event to the client with a string containing
the name of a directory into which the client should save its data files.
Clients can save data on the server if they wish. To do this, the
client declares that it wants to save data on the server when it
initialises the server connection and then later sends one or more
configs to the server. A config is also a very simple object.
It has a client-unique character string key, and a value of arbitrary
size and type (well, almost arbitrary; its size must be able to be
described by a uint32_t
integer due to byte-order conversions
done when sending data over the network.)
In this section we will examine a typical session in some detail, describing the server and client operations that take place. In the session, the server is started, a number of clients connect, the session is saved and then restored.
Before all else, the user starts the server. It starts up and begins listening for connections from clients. It doesn't do much else.
To keep track of what is happening with LASH, the user can run the @command{lash_panel} program (though this is not necessary, and it can be started later at any time).
Unless the environment variable LASH_NO_START_SERVER
is set any
LASH client will automatically start the server if one isn't already running.
Doing this you can simply run applications normally (e.g. from a terminal or
your Applications menu) and have LASH automatically work without having to
remember to start the server manually.
Starting the server can also be disabled by specifying the @command{--lash-no-start-server} option on the client's command line.
If you're using a Bourne compatible shell like bash
(if you don't
know, you probably are) you can disable auto-start with the following
command:
@command{export LASH_NO_START_SERVER=1}
Some applications may also choose themselves whether to start the server (or have a configurable option), however risabling the automatic start (by any method) is not recommended if you want to gain the benefits of LASH. With auto launching enabled you don't need to worry about LASH until you actually want to save a session.
The user then starts a JACK client program. It opens a connection to the server and provides it with all information that the server will need to run the application again. This information includes: the current directory that the user was in when they ran the program, the command line that started the application and the class of the client (a character string that the client application provides the initialisation routine that will never change over all initialisations.)
With this information is included a set of flags that describe the client
to the server. This particular client saves data to files and wants
the server to tell it where to save files when the project is saved,
so it has the LASH_Config_File
flag set.
The client library starts two threads for communication with the server, one for sending data and the other for recieving. It also sends, along with the client supplied data, a number of parameters that were extracted from the client's command line options before it checked them. This optionally includes the name of the project that the client should initially be associated with and a 128-bit, world-unique identifier for this particular client instance (the LASH ID.)
Server-side, the server wakes up to the fact that a new connection has arrived and immediately adds it to a list of open connections and then goes back to waiting. When the client sends the requisite information, the server looks at it and decides what to do with the client. This client has not requested a specific project to which it should be connected. However, there are no existing projects so the server creates a new project with the name `project-1' in the directory `/home/user/audio-projects/project-1' (assuming the user didn't specify a different default directory when running configure.) It also generates a new LASH ID for the client. It then adds the client to the new project and goes back to listening.
If the user has the @command{lash_panel} client running, the new project will appear as a tab with the title `project-1', and the new client will appear in the client list for that project.
The client then connects up to the JACK server and, after having done
this, sends a LASH_Jack_Client_Name
event to the server with the
name that it registered to JACK with as the string. This notifies the
server that it is a JACK client and needs its JACK port connections saved
and restored. The server will now pay attention to any activity regarding
the client (ie, port creation and destruction and port connection and
disconnection.)
The user then starts a second client that uses the ALSA sequencer
interface and wishes to save data on the server. It connects to
the server with a different class to the JACK client and with the
LASH_Config_Data_Set
flag set.
The server sees that this client also didn't specify a project, and so adds it to the first available project; the same one as the previous project, `project-1'. It also sees that the client wants to store data on the server, and so it creates a directory within the project directory for this data to be stored in and creates a database-style object to manage the client's data.
If the user has the @command{lash_panel} client running, both clients will now be visible in the clients list for `project-1'.
The client then connects to the ALSA sequencer and sends its
client ID to the server in the first character of the string of a
LASH_Alsa_Client_Name
event. The server regards this similarly
to the other client's JACK client name.
After the user has done some work in the two clients, they want to
save their work. They click the Save button in @command{lash_panel}
(or use the @command{save} command in @command{lash_control}), and a
LASH_Save
event is sent to the server. The server recieves this
and then iterates through each client in the project and checks its flags.
The JACK client saves data by itself (it has the LASH_Config_File
flag set,) so the server creates a directory under the project directory
for it to save in and then sends a LASH_Save_File
event to the
client with a string containing the name of the directory it made.
The client recieves the event and saves its data into the specified
directory.
Next, the server examines the ALSA client. It wishes to save data on the
server, so the server sends a LASH_Save_Data_Set
to the client.
With all of the clients iterated through, it now saves all the information
it needs to be able to restore them; their working directory, command
line options, etc. In order to do this, it asks the JACK server to
find the connections for the JACK client, and asks the ALSA sequencer to
find the connections for the ALSA client. It uses the client name and
ID that both clients sent to the server after opening their connections
to the respective systems. All of this information is stored in a file
under the project's directory. When this is done, the server goes back
to listening for events and configs.
The client, meanwhile, has recieved the LASH_Save_Data_Set
event
and sends back a number of configs to the server. When it has sent all
the data it wishes to be saved, it sends back a LASH_Save_Data_Set
event. The server passes all of the configs to the object managing
the data store for the ALSA client. When the server recieves the
LASH_Save_Data_Set
event from the client, it tells the data store
to write the data to disk. The save is now complete.
Unfortunately for the user, the ALSA client crashes. The server detects
that the client has disconnected, and puts the client on a list of lost
clients for the project. The user then starts another copy of the client,
which connects to the server in the same way it did before. This time,
however, the server checks through the list of lost clients and finds
that the class of the new client matches the class of the lost client
and so it resumes the lost client using the new one. It gives it the
128-bit ID of the lost client, adds it to the project, and then sends
a LASH_Restore_Data_Set
event to the client. The client then
cleans itself up, ready to recieve the data set. The server sends the
client the configs, and then another LASH_Restore_Data_Set
event.
The client recieves this data and its state has been restored that of
the client that crashed.
The user can stop this behaviour by specifying the @option{--lash-no-autoresume} option on the client's command line.
The user has to go off and do other things, and so they close down the
clients and the server. Some time later, the user comes back and wants
to start working again so first, as always, they start up the server.
They then start the @command{lash_panel} program. Using the File->Open
menu item, the user selects the directory (not file!) where they saved
the project (by default `~/audio-projects/project-1', but you
can save to a more descriptive name). The lash_panel client sends a
LASH_Restore
event to the server with the specified directory as
the string. The server opens the file that it saved before, and reads
in all the information about the project and its clients. It creates
a new project with this information. The clients are created as lost
clients, however.
The server then iterates through each client and starts a new copy of it using the information provided when the original client connected. It also adds some command line options that are extracted by the client library. These specify the LASH ID of the client, the project name that it should be connecting to and the server's hostname and port. It then goes back to waiting.
The new JACK client then connects to the server as normal. When the
server recieves it connection, it checks the client against the project's
list of lost clients. This time, however, it has its ID specified, so
the server will only resume a client with a matching ID. Lo and behold,
such a client exists. The server resumes the old JACK client, telling it
to load its state from the files in the project directory that the client
previously stored. It does so with a LASH_Restore_File
event with
the string as the directory name. The ALSA client does exactly the same,
except having its data restored through LASH_Restore_Data_Set
as described above.
Only one thing remains for the clients to be fully restored: the JACK and
ALSA sequencer connections. This happens when the clients send their
LASH_Jack_Client_Name
and LASH_Alsa_Client_ID
events.
The connections are stored with the LASH ID rather than the JACK client
name or ALSA client ID. When the client registers its name or ID, the
connections are converted from the LASH ID to the JACK client name or ALSA
client ID, and the connections are restored. It also pays attention to
connections to other clients within the same project, converting between
JACK client names, ALSA client IDs and LASH IDs as appropriate.
NULL
on failure.
The args argument must be obtained using lash_extract_args
.
The client_class argument must be a string that will never change over
invocations of the program. If using GNU automake, the best way to do this is to use
the PACKAGE_NAME
macro that is automatically defined.
The client_flags argument should be 0 or bitwise-OR'd values from this list:
LASH_Config_Data_Set
LASH_Config_File
LASH_Server_Interface
LASH_No_Autoresume
LASH_Terminal
LASH_No_Start_Server
The protocol argument should be the version of the high-level protocol that the client
implements See @xref{Protocol versioning} for information on how to contruct a lash_protocol_t
variable.
lash_init
. This should be done before the
client checks the arguments, obviously. Returned object must be cleaned up with lash_args_destroy.
lash_event_destroy
.
Returns NULL
if there are no events pending.
lash_config_destroy
.
Returns NULL
if there are no configs pending.
lash_event_new
or lash_event_new_with_type
. The library takes over
ownership of the memory and it should not be freed by the client.
lash_config_new
, lash_config_new_with_key
or
lash_config_dup
. The library takes
over ownership of the memory (including the key, etc) and it should not be freed by the client.
NULL
, and if it
isn't, that the server is still connected.
@anchor{lash_alsa_client_id}
@anchor{Protocol versioning}
The event protocol (See section 6.3 Event protocol,) is versioned with a major and minor component.
The lash_protocol_t
type represents a version number
in a 32-bit unsigned integer split 16:16. A protocol is comptible with the server's
protocol if the major numbers are the same and the minor number is less than,
or equal to, the server's minor number (ie, 1.0 is compatible with a server
using 1.0, 1.1 is compatible with a server using 1.3, but neither 2.0 or 1.6 are
compatible with a server using 1.4. The minor component may be dropped in
the future.
lash_protocol_t
protocol version.
lash_protocol_t
protocol version.
@anchor{Events}
@anchor{Server interface events}
All events have a LASH ID and project name property. They are only relevant to server interfaces, however, which need to refer to clients other than themselves and to projects (server interfaces are never assigned to a project.)
@anchor{Configs}
With these functions, no type checking is done; you can do
lash_config_get_value_int
on a config that was set with
lash_config_set_value_float
. The integer values are converted
to and from network byte order as appropriate.
This section describes version 2.0 of the event protocol.
This section deals with normal clients (as opposed to section 6.3.2 Server interfaces.)
LASH_Client_Name
NULL
string
NULL
string
LASH_Client_Name
with a
NULL
string. The string will be NULL
if the client has not
set a user-visible name, and the name itself if it has.
LASH_Jack_Client_Name
NULL
string
NULL
LASH_Jack_Client_Name
event. Note that you must send this event after calling
jack_activate()
; otherwise, the server will not be able to connect
the client's ports.
NULL
string
LASH_Jack_Client_Name
with a
NULL
string. The string will be NULL
if the client has not
set a JACK client name, and the client name itself if it has.
LASH_Alsa_Client_ID
{ id, '\0' }
as the
event string. A
convenience function, lash_alsa_client_id
, exists to do this for you
(see @xref{lash_alsa_client_id}.)
NULL
string
NULL
LASH_Alsa_Client_ID
event.
NULL
string
LASH_Alsa_Client_ID
with a
NULL
string. The string will be NULL
if the client has not
set an ALSA client ID, and a string containing the ALSA client ID as described
above if it has.
LASH_Save_File
NULL
and will contain the name of the
directory in which the client should save its data. Clients must always
send a LASH_Save_File
event back to the server when they have finished
saving their data. The client should not
rely on the directory existing after it has sent its LASH_Save_File
event back. It is valid behaviour for a client to save no files within the
directory. Files should always be overwritten (ie, using the "w" flag
with fopen()
,) preferably without user confirmation if you care
for their sanity.
LASH_Restore_File
NULL
and will contain the name of the
directory from which the client should load its data. Clients must always
send a LASH_Restore_File
event back to the server when they have finished
restoring their data. The client should not
rely on the directory existing after it has sent its LASH_Restore_File
event back.
LASH_Save_Data_Set
LASH_Save_Data_Set
event back to the server when it has finished sending its configs. The
event string will always be NULL
.
LASH_Restore_Data_Set
NULL
. The client must always send
a LASH_Restore_Data_Set
back to the server when it has recieved
all of its configs.
LASH_Save
LASH_Quit
Server interfaces are treated very differently to normal interfaces. Events from and
to server interfaces are, for the most part, in order to describe and manipulate existing
projects and clients. For this reason, the lash_event_t
type has
project
and client_id
properties which facilitate this. @xref{Server interface events}. The project
property contains the name of the project.
A server interface should start up with the default assumption that there are no projects. Upon
connection, the server will send appropriate events (LASH_Project_Add
,
LASH_Client_Add
, LASH_Client_Name
, etc) that describe the current state of the
system. From then on, events will be sent to keep the interface up to date with the
server's state.
LASH_Project_Add
project
client_id
project
NULL
client_id
LASH_Project_Remove
project
client_id
project
client_id
LASH_Project_Dir
NULL
string
project
client_id
NULL
string
project
client_id
project
client ID
LASH_Project_Name
project
client_id
project
client ID
LASH_Client_Add
project
client ID
LASH_Client_Name
NULL
string
NULL
string
project
client ID
project
client ID
LASH_Jack_Client_Name
NULL
string
NULL
string
project
client ID
project
client ID
LASH_Alsa_Client_ID
NULL
string
NULL
string
project
client ID
project
client ID
LASH_Percentage
sprintf
ing an int
.
project
client ID
Go to the first, previous, next, last section, table of contents.