Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

server_template.h

Go to the documentation of this file.
00001 /*
00002  * server_template.h -- Template and server class deriving from
00003  *                      the MutableServerBase class.
00004  *
00005  *                      The base class handles communications, so this class
00006  *                      primarily must only concern itself with the specific
00007  *                      handling for this type of server (to include relevant
00008  *                      configuration, passports and calculations.
00009  */
00010  
00011 // STEP 1: Do a global replacement of the string "ServerTemplate"
00012 //         with the name of your new class
00013 //
00014 #if ! defined(_MSM_ServerTemplate_H)
00015 #define _MSM_ServerTemplate_H
00016 
00017 
00018 // IF THE NEW SERVER WILL NOT NEED DATABASE CONNECTIVITY, THIS MAY BE
00019 // CHANGED TO <mutableserverbase.h>
00020 #include <dbmutableserver.h>
00021 
00022 
00023 // STEP 2: Declare a structure type to contain configuration parameters
00024 //         that may change due to arriving passport data.
00025 //
00026 typedef _ServerTemplate_PARAMS
00027 {
00028    // These are just examples used in the source
00029    long      ExampleLongParam;
00030    char      ExampleStringParam[31];
00031    bool      ExampleFlagParam;
00032 } ServerTemplate_PARAMS;
00033 
00034 
00035 // IF THE NEW SERVER WILL NOT NEED DATABASE CONNECTIVITY, THE PARENT CLASS
00036 // MAY BE CHANGE TO MutableServerBase
00037 class ServerTemplate : public DBMutableServer
00038 {
00039 protected:
00040 
00041    // =======================================================================
00042    //                  from TConfigurable
00043    // =======================================================================
00044 
00045    /* CheckConfig() -- allows derivative classes to report the status of their
00046    **                  the configuration state.
00047    **
00048    ** Set ConfigStatus = WORM_STAT_BADSTATE if there
00049    ** is a configuration problem, otherwise take no action.
00050    */
00051    void CheckConfig();
00052 
00053 
00054    // =======================================================================
00055    //                  from WormServerBase
00056    // =======================================================================
00057 
00058    // PrepareToRun() -- actions to take prior to entering main loop
00059    // 
00060    //   ALWAYS call base class's PrepareToRun() at the top
00061    //
00062    // RETURN:  true if ready
00063    //          false if some condition prevents proper execution
00064    //
00065    bool PrepareToRun();
00066 
00067 
00068    // =======================================================================
00069    //                  from MutableServerBase
00070    // =======================================================================
00071 
00072 // STEP 3: Replace the TYPE_XXXXXXX with the appropriate Earthworm message type
00073 //         that will be returned if this server runs in module mode.
00074 //
00075    // OutputMessageTypeKey() -- Returns the string used to identify 
00076    //                           result messages sent in Module mode
00077    //                           via the ring (e.g.:  TYPE_XXXXXXX).
00078    //                           This is intended to allow different
00079    //                           derivative servers to emit different
00080    //                           message types.
00081    //
00082    const char * OutputMessageTypeKey() { return "TYPE_XXXXXXX"; }
00083 
00084 // STEP 4: Set an appropriate size for the socket buffer.
00085 //
00086    /*
00087    ** GetMaxSocketBufferSize() -- Server mode uses this to allocate
00088    **                             a buffer of sufficient size to
00089    **                             parse the arriving and format
00090    **                             the outgoing message
00091    */
00092    long GetMaxSocketBufferSize() { return 1024L; }
00093    
00094 
00095    /*
00096     * GetRequestContainer(), 
00097     *  GetResultContainer() -- gets a container to hold the request
00098     *                          (e.g. passport & event info) or result info.
00099     *                          Since we don't know what all
00100     *                          possible content that can be in a
00101     *                          request or returned for the various derivative
00102     *                          classes of servers, the container
00103     *                          is returned as a base class pointer,
00104     *                          This base class code does not need
00105     *                          to know about the container, only
00106     *                          the following virtual methods do.
00107     *
00108     * RETURNS:
00109     *      a pointer to the container
00110     *   or NULL on failure
00111     */
00112    MutableServerRequest * GetRequestContainer();
00113 
00114    MutableServerResult * GetResultContainer();
00115 
00116 
00117    // - - - - - - - - - - - - - - - - - - - - - - - - -
00118    // For Standalone or Client modes
00119    //
00120    // Gets request parameters/instructions from command line args
00121    // or stdin
00122    //
00123    // r_container = a pointer to the appropriate type of
00124    //               MutableServerRequest derivative class
00125    //               (cast to the specific type in the method).
00126    //
00127    // RETURN:
00128    //     WORM_STAT_SUCCESS
00129    //     WORM_STAT_FAILURE
00130    //
00131    WORM_STATUS_CODE GetRequestFromInput( int    p_argc
00132                                        , char * p_argv[]
00133                                        , void * r_container
00134                                        );
00135    
00136    // - - - - - - - - - - - - - - - - - - - - - - - - -
00137    // For Server, Module or Standalone modes
00138    //
00139    // The actual processing
00140    //
00141    // PARAMETERS:
00142    //
00143    //      p_requestcontainer = pointer to a request object
00144    //                           appropriate for this server class
00145    //
00146    //      r_resultcontainer = pointer to an object of a type
00147    //                          derived from the MutableServerResult class
00148    //                          which is appropriate for this type of server.
00149    //                          (cast to the specific type in the method).
00150    //
00151    // RETURN:
00152    //      WORM_STAT_SUCCESS  = good results
00153    //      WORM_STAT_BADSTATE = algorithmic, not system, failure (no results obtained)
00154    //      WORM_STAT_FAILURE  = system failure
00155    //
00156    WORM_STATUS_CODE ProcessRequest( void * p_requestcontainer
00157                                   , void * r_resultcontainer
00158                                   );
00159 
00160 
00161    // - - - - - - - - - - - - - - - - - - - - - - - - -
00162    // For Client, Module or Standalone modes
00163    //
00164    // What to do with the results;
00165    //
00166    // PARAMETERS:
00167    //
00168    //      p_resultcontainer = pointer to an object of a type
00169    //                          derived from the MutableServerResult class
00170    //                          which is appropriate for this type of server.
00171    //                          (cast to the specific type in the method).
00172    //
00173    // MUST RETURN:
00174    //      WORM_STAT_SUCCESS  = good results
00175    //      WORM_STAT_BADSTATE = algorithmic, not system, failure (no results obtained)
00176    //      WORM_STAT_FAILURE  = system failure
00177    //
00178    WORM_STATUS_CODE HandleResult( void * p_resultcontainer );
00179 
00180 
00181    // =======================================================================
00182    //                  from DBMutableServerBase
00183    // =======================================================================
00184    
00185    // HandleParameterLine() -- handle configuration lines which may be either
00186    //                          lines from a .d file, or passport lines from
00187    //                          the database.
00188    // 
00189    // PARAMETERS:
00190    //       p_parser = pointer to a ComFile or OracleConfigSource object
00191    //       p_params = pointer to either a struct holding default parameters,
00192    //                  or to a struct that is being used to hold parameters
00193    //                  for an arriving processing request.
00194    // 
00195    // RETURNS:
00196    //          HANDLE_INVALID --  line invalid
00197    //          HANDLE_UNUSED  --  line not used
00198    //          HANDLE_USED    --  line used okay
00199    //
00200    HANDLE_STATUS HandleParameterLine( ConfigSource * p_parser
00201                                     , void         * p_params
00202                                     );
00203 
00204 
00205 
00206    // =======================================================================
00207    //                  for ServerTemplate
00208    // =======================================================================
00209 
00210    // Structure to hold the default parameters
00211    //
00212    ServerTemplate_PARAMS   DefaultParameters;
00213 
00214 
00215 public:
00216 
00217 
00218    // =======================================================================
00219    //                  from TConfigurable
00220    // =======================================================================
00221 
00222    /*
00223     *  HandleConfigLine() -- allows programs to handle configuration in a
00224     *                        consistent manner.
00225     *
00226     *  PARMS:
00227     *          p_parser -- Pointer to some type of configuration source object,
00228     *                      such as ComFile or OracleConfigSource.  The object
00229     *                      will have a command string already in the current
00230     *                      token for comparison using the Its() method.
00231     *
00232     * RETURN:
00233     *          HANDLE_INVALID --  line invalid
00234     *          HANDLE_UNUSED  --  line not used
00235     *          HANDLE_USED    --  line used okay
00236     *
00237     *  Override for child classes to handle parameter lines
00238     *  Call <super_class::HandleConfigLine() within derivative classes
00239     *  to allow them a whack at the parameter as well.
00240     */
00241    HANDLE_STATUS HandleConfigLine( ConfigSource * p_parser );
00242 
00243 
00244    // =======================================================================
00245    //                  for ServerTemplate
00246    // =======================================================================
00247 
00248    ServerTemplate();
00249    
00250    ~ServerTemplate();
00251    
00252 
00253 };
00254 
00255 #endif // _MSM_ServerTemplate_H

Generated on Tue May 6 09:16:09 2003 for Earthworm Libs by doxygen1.3-rc3