FFL
1.0
Finfly Foundation Library
|
00001 /* $Id: service.h 2926 2013-02-05 19:07:32Z roma $ */ 00002 #ifndef _FFL_CSSC_MULTITHREADED_SERVICE_H_ 00003 #define _FFL_CSSC_MULTITHREADED_SERVICE_H_ 00004 00005 #include "../service.h" 00006 #include "server.h" 00007 00008 namespace ffl 00009 { 00010 00011 namespace cssc 00012 { 00013 00014 namespace multithreaded 00015 { 00016 00019 class service:public cssc::service 00020 { 00021 public: 00022 00028 class server:public multithreaded::server 00029 { 00030 public: 00031 00044 server(service& _service, int _max_users, int _max_processors, const char* _log_path, long _idle_timeout) throw(): 00045 Service(_service), 00046 LogPath(_log_path), 00047 multithreaded::server(_max_users, _max_processors, (std::string(_log_path) + "/server.Log").c_str(), _idle_timeout) 00048 {} 00049 00050 private: 00051 00052 service& Service; 00053 00059 void just_started() throw(){Service.Context.checkpoint();} 00060 00065 void just_ready() throw(){Service.Context.state(RUNNING, service::STOP);} 00066 00071 void just_canceled() throw(){Service.Context.pending(STOP_PENDING, 5000);} 00072 00073 protected: 00074 00075 std::string LogPath; 00076 00077 }; 00078 00082 service(cssc::service::context& _c) throw():cssc::service(_c){} 00083 00099 void run(int _argc, const char* _argv[]) throw(); 00100 00101 protected: 00102 00111 virtual server* create(int _max_users, int _max_processors, const char* _path, long _idle_timeout) throw(...) = 0; 00112 00125 virtual void adjust(int &_max_users, int &_max_processors, std::string &_path, long &_idle_timeout) throw(...){} 00126 00127 private: 00128 00129 std::auto_ptr<server> Server; 00130 00131 server* initialize(int _argc, const char* _argv[]) throw(...); 00132 00137 void stop() throw(){Server->cancel();} 00138 00139 }; 00140 00141 } 00142 00143 } 00144 00145 } 00146 00147 #endif