next up previous contents index
Next: The Value Class Up: The Glish Client Library Previous: An Example of a

The Client Class


  As discussed in § 13.2, page gif, above, Glish clients should construct a single Client object using the argc and argv with which the client program was invoked.

Standard Client Member Functions

Client objects provide the following public member functions:

Multiplexing Input Sources


  Some Glish clients need to receive input from multiple sources, such as   both user-interface input and event input. The Client class provides three additional member functions to support input multiplexing. The basic idea is that the Client class makes   available an fd_set identifying which file descriptors it uses to receive events. This fd_set can then be used in a call to select() to determine whether any of the client's event sources are active. Another Client member function takes the fd_set returned by select() and reports whether or not the modified   fd_set indicates that an event is pending. If so then a special version of NextEvent() is called with the fd_set passed as an argument; it decodes the fd_set and returns the pending event.

The additional member functions are:

Putting these member functions together, suppose we have an fd_set called mask which already has set in it the non-Glish file descriptors we use for input. Then the following fragment illustrates how we can multiplex between these input sources and the Glish sources:  

    // Assume c is a pointer to our Client object.
    // Add c's input sources into the mask.
    c->AddInputMask( &mask );

    // Now select between the different sources.
    if ( select( FD_SETSIZE, &mask, 0, 0, 0 ) < 0 )
        if ( c->HasClientInput( &mask ) )
            GlishEvent* e = c->NextEvent( &mask );
            handle_event( e );

        // Check our other input sources for activity, too.

Shared Clients


The most recent change to clients is the ability for clients to be shared among multiple interpreters. For this to work, the glishd must be running as root on the machines where shared clients will be running (see § 14.2.1). These shared clients allow multiple Glish interpreters to connect to the same Client object. The type of users allowed to connect is controlled by a parameter to the Client constructor (see § 13.5.1). Each of the PostEvent() functions take an optional parameter which specifies to which context the event should be sent. And the EventSources() function provides access to all of the sources a given client is managing.

The shared client member functions are:

Below is an example of how these functions work. This client forwards events which it receives to all of the other sources that are connected to it. It is like a multi-way tee connecting its event sources.  

    int main( int argc, char** argv )
        Client c( argc, argv, Client::GROUP );

        for ( GlishEvent* e; (e = c.NextEvent()); )
            source_list &sources = c.EventSources();
            loop_over_list( sources, i )
                if ( sources[i]->Context() != c.LastContext() )
                    c.PostEvent( e, sources[i]->Context() );
        return 0;
The Client c, in this example, will only accept connections from other users in the same (Unix) group as the user group who starts this client.    

next up previous contents index
Next: The Value Class Up: The Glish Client Library Previous: An Example of a

Thu Nov 13 16:44:05 EST 1997