mprocess_rpc_server.h

Go to the documentation of this file.
00001 /***************************************************************************
00002              mprocess_rpc_server.h  -  multi process rpc server
00003                              -------------------
00004     begin                : Sun May 29 2005
00005     copyright            : (C) 2005 Dmitry Nizovtsev <funt@alarit.com>
00006                                     Olexander Shtepa <isk@alarit.com>
00007 
00008     $Id: mprocess_rpc_server.h 945 2007-01-03 13:05:48Z ewald-arnold $
00009 
00010  ***************************************************************************/
00011 
00012 /**************************************************************************
00013  *
00014  * This program is free software; you can redistribute it and/or modify
00015  * it under the terms of the GNU Lesser General Public License as
00016  * published by the Free Software Foundation; either version 2 of the License,
00017  * or (at your option) any later version.
00018  *
00019  * This program is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  * GNU General Public License for more details.
00023  *
00024  * You should have received a copy of the GNU Lesser General Public License
00025  * along with this program; if not, write to the Free Software
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00027  *
00028  ***************************************************************************/
00029 
00030 
00031 #ifndef FUNTIK_MPROCESS_RPC_SERVER_H
00032 #define FUNTIK_MPROCESS_RPC_SERVER_H
00033 
00034 #include <ulxmlrpcpp/ulxmlrpcpp.h>  // always first header
00035 
00036 //STL
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 //      pid_t   pidProcess;
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 } // namespace funtik
00362 
00363 
00364 #endif // FUNTIK_MPROCESS_RPC_SERVER_H

Generated on Sun Aug 19 20:08:57 2007 for ulxmlrpcpp by  doxygen 1.5.1