#ifndef CIPRES_SIMPLE_SERVER_HPP #define CIPRES_SIMPLE_SERVER_HPP #include #include #include #include #include #if defined(HAVE_OMNIORB4) && HAVE_OMNIORB4 # include #endif /// To avoid repitition of the same code for interacting with the facilitator in each phycas /// module that is contributing services to CIPRES, MTH wrote the CipresSimpleServer /// class to mimic the server setup that TL had implemented for PAUP and DCM3 /// /// A CipresSimpleServer is instantiated with callback functions that generate servants. /// If multiple services are supports, multiple callbacks can be registered, but the service names must be unique. /// /// Currently there is some redundancy, the functions take an argument specifying the type of service /// but the CipresSimpleServer also stores them in a map of service name -> callback. /// This is so the user or CipresSimpleServer can just code one function that does a switch on service name and returns the /// appropriate servant OR the user of CipresSimpleServer can ignore the argument to this servant factory /// function if the server only implements one service. class CipresSimpleServer { public: enum MainReturnCode { NO_PROBLEM = 0, SERVANT_CREATION_FAILED = 1, CORBA_ERROR = 2, UNKOWN_EXCEPTION_ERROR = 3, NO_FACILITATOR_ERROR = 4, UNCAUGHT_EXCEPTION = 5 }; typedef std::pair NamedServantPtr; typedef boost::function1 ServantFactoryFunc; // should return using _retn() or equivalent CipresSimpleServer(const char * serviceName, ServantFactoryFunc callback, bool multithreaded, bool persistent) :isMultithreaded(multithreaded), isPersistent(persistent) { addCallback(serviceName, callback); } void addCallback(const char * serviceName, ServantFactoryFunc callback); // used to register additional services MainReturnCode initializeAndRun(int argc, char *argv[]); /// acts like a main() function for the server int usage() const; ///print usage string protected: typedef std::map MapServantFactoryFunc; MapServantFactoryFunc servantFactoryFunctions; // list of callback objects called immediately before facilitator->run is called std::string name; // taken from argv[0] of initializeAndRun() bool isMultithreaded; bool isPersistent; }; #endif