00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef FUNTIK_MPROCESS_RPC_SERVER_H
00032 #define FUNTIK_MPROCESS_RPC_SERVER_H
00033
00034 #include <ulxmlrpcpp/ulxmlrpcpp.h>
00035
00036
00037 #include <vector>
00038 #include <map>
00039 #include <memory>
00040
00041 #include <ulxmlrpcpp/ulxr_dispatcher.h>
00042 #include <ulxmlrpcpp/ulxr_tcpip_connection.h>
00043
00044 #include <sys/types.h>
00045 #include <unistd.h>
00046 #include <time.h>
00047
00048 #include <signal.h>
00049
00050
00051 namespace funtik {
00052
00053
00054 class ULXR_API_DECL0 MultiProcessRpcServerError : public std::exception
00055 {
00056 std::string _what;
00057 public:
00058 MultiProcessRpcServerError(const std::string& what_arg);
00059 ~MultiProcessRpcServerError() throw();
00060 const char* what () const throw();
00061 };
00062
00071 class ULXR_API_DECL0 MultiProcessRpcServer
00072 {
00073 public:
00074 struct ProcessContext
00075 {
00076
00077 time_t timeStart;
00078 int iState;
00079 };
00080
00092 MultiProcessRpcServer(unsigned uNumProcess=0,bool bHandleSigchld=true, bool wbxml_mode = false);
00093
00107 MultiProcessRpcServer(ulxr::Protocol* poProtocol, unsigned uNumProcess,bool bHandleSigchld=true, bool wbxml_mode = false);
00108
00109
00116 virtual ~MultiProcessRpcServer();
00117
00125 virtual unsigned getNumProcesses() const;
00126
00138 virtual bool terminateAllProcess(bool bForce,long lTimeout = 3000);
00139
00147 void setMaxNumProcesses(unsigned uNumProcesses);
00148
00157 unsigned getMaxNumProcesses() const;
00158
00159
00168 ulxr::Dispatcher* getDispatcher() const;
00169
00170
00178 void resetDispatcher(ulxr::Protocol* poProtocol=0);
00179
00180
00188 virtual void serverLoop();
00189
00190
00205 static void sigchild_handler(int signal);
00206
00216 virtual void handleRequest();
00217
00225 virtual bool waitConnection(bool bInterruptBySig=true);
00226
00234 void setState(int iState);
00235
00236
00243 void printProcess() const;
00244
00252 int getState() const;
00253
00254
00260 virtual std::map<pid_t,ProcessContext> getProcInfo() const;
00261
00269 virtual bool waitChildren(long lTimeout=-1) const;
00270
00271 enum ProcessState
00272 {
00273 RUN = 1,
00274 FINISH = 2
00275 };
00276
00277 protected:
00278
00286 virtual void doChild();
00287
00288 virtual void acceptConnection();
00289
00297 virtual void storeFuncResult(const ulxr::MethodCall& callMethod,const ulxr::MethodResponse& respMethod) const;
00298
00304 virtual ulxr::MethodCall handleXmlRequest();
00305
00310 virtual void blockSigchld();
00311
00319 virtual void unblockSigchld();
00320
00324 virtual void storeProcessData(pid_t pid);
00325
00332 virtual void sweepProcessData();
00333
00339 virtual void sigchild_register();
00340
00346 virtual void sigchild_unregister();
00347
00348 struct sigaction old_sigchld;
00349
00350
00351 unsigned m_maxProcesses;
00352 static std::map<pid_t,ProcessContext> m_mapProcesses;
00353 std::auto_ptr<ulxr::Dispatcher> m_poDispatcher;
00354 int m_iState;
00355 bool m_wbxml_mode;
00356 private:
00357 bool m_bHandleSigchld;
00358 };
00359
00360
00361 }
00362
00363
00364 #endif // FUNTIK_MPROCESS_RPC_SERVER_H