Class: DimServer 
Library: DIM
Author: Ph. Charpentier  
Version: v1.0 Update :Thu Feb 11 15:52:46 1999

Description :

    To be used by DIM Servers - Implements mainly static methods related to the Server.
    DimServer::start(<server name>) should be called after DimServices and/or DimCommands
    have been created, in order to register them within the DIM Name Server.
    DimServices created after "start" has been called will be automatically registered.
    The class DimServer can be inherited by user classes wishing to handle multiple DimCommands
    in the same class. Please refer to Usage for examples on the use of DimServer.

Constructors :

Public Functions :     Virtual methods for Command Handling Usage :

    The DimServer class implements Server functions - the most important is "start".
    Example:

            DimService runNumber("DELPHI/RUN_NUMBER",123);
            DimServer::start("DelphiServer");

    DimServer can be used as a base class when the user class wishes to handle DimCommands using
    Handlers.
    Example:

                class Handler : public DimServer
                {
                    DimCommand cmd;
                    int val;
                    void commandHandler( ) { val = cmd.getInt( ); };
                public:
                    Handler( ) :
                         cmd("TEST/CMD", "I", this) {val = 0; };
                };
 

    The DimServer can also be used to set up exit handlers to be executed when "special" clients die.
    The installation of a exit handler for a client can be done in two ways:

        - The client decides it is one of the "special" ones. Example: The Server should die when the
        client dies.

            Server Part:

                class ClientHandler : public DimServer
                {
                public:
                    ClientHandler() {
                        DimServer::addClientExitHandler(this);
                        DimServer::start("TheServer"); };
                    void clientExitHandler( ) {
                        cout << "Client " << getClientName() << " died" << endl;
                        exit(0);
                    };
                };

             Client Part:

                main()
                {
                     DimClient::setExitHandler("TheServer");
                     ...
                }

        - The server decides a client is "special" - example: The Server wants to be "released" when the
          client that "allocated" it dies.

                class Allocation : public Server
                {
                    DimCommand *allocate;
                    int allocationState;
                public:
                    Allocation( ) {
                        allocate = new DimCommand("SRV/ALLOCATE","I",this);
                        DimServer::addClientExitHandler(this);
                        DimServer::start("SRV"};
                    void commandHandler( ); {
                        if ( getInt( ) == 1) {                     // Client Allocated
                            allocateState = 1;
                            DimServer::setClientExitHandler(DimServer::getClientId( )); // Set the exitHandler for this client
                        }
                        else {                                                 // Client Released
                            allocateState = 0;
                            DimServer::clearClientExitHandler(DimServer::getClientId( )); // Clear the exitHandler for this client
                        }
                     void clientExitHandler( ) {                       // Client died  (while Allocated) - Release
                        cout << "Client " << getClientName() << " died" << endl;
                        allocateState = 0;
                    };
                };
 


Last update : 02/15/99 17:40:42 by MkHelp 1.1.0