ulxr_mtrpc_server.h

Go to the documentation of this file.
00001 /***************************************************************************
00002            ulxr_mtrpc_server.h  -  a simple multithreaded rpc server
00003                              -------------------
00004     begin                : Wed Oct 10 2003
00005     copyright            : (C) 2002-2007 by Ewald Arnold
00006     email                : ulxmlrpcpp@ewald-arnold.de
00007 
00008     $Id: ulxr_mtrpc_server.h 991 2007-07-15 09:02:35Z 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 #ifndef ULXR_MTRPC_SERVER_H
00031 #define ULXR_MTRPC_SERVER_H
00032 
00033 #include <ulxmlrpcpp/ulxmlrpcpp.h>  // always first header
00034 
00035 #ifdef ULXR_MULTITHREADED
00036 
00037 #include <vector>
00038 
00039 #include <ulxmlrpcpp/ulxr_dispatcher.h>
00040 #include <ulxmlrpcpp/ulxr_method_adder.h>
00041 
00042 #ifdef __WIN32__
00043 #include <process.h>
00044 #include <windows.h>
00045 #endif
00046 
00047 #ifdef __unix__
00048 #include <pthread.h>
00049 #endif
00050 
00051 
00052 namespace ulxr {
00053 
00054 
00055 class Exception;
00056 class Protocol;
00057 
00061 class ULXR_API_DECL0 MultiThreadRpcServer : public MethodAdder
00062 {
00063   public:
00064     class ThreadData;
00065 
00066     typedef void* (*ThreadLoopFunction)(ThreadData*);
00067 
00073     MultiThreadRpcServer(Protocol *prot, unsigned num, bool wbxml_mode = false);
00074 
00077     virtual ~MultiThreadRpcServer();
00078 
00082     unsigned dispatchAsync();
00083 
00087     unsigned numThreads() const;
00088 
00093     void terminateAllThreads(unsigned time = 0);
00094 
00099     void shutdownAllThreads(unsigned time = 0);
00100 
00105     void waitAsync(bool term, bool stat = false);
00106 
00118    void addMethod (MethodAdder::StaticMethodCall_t adr,
00119                    const CppString &ret_signature,
00120                    const CppString &name,
00121                    const CppString &signature,
00122                    const CppString &help);
00123 
00136    void addMethod (MethodAdder::DynamicMethodCall_t wrapper,
00137                    const CppString &ret_signature,
00138                    const CppString &name,
00139                    const CppString &signature,
00140                    const CppString &help);
00141 
00153    void addMethod (MethodAdder::SystemMethodCall_t adr,
00154                    const CppString &ret_signature,
00155                    const CppString &name,
00156                    const CppString &signature,
00157                    const CppString &help);
00158 
00170    void addMethod (MethodAdder::StaticMethodCall_t adr,
00171                    const Signature &ret_signature,
00172                    const CppString &name,
00173                    const Signature &signature,
00174                    const CppString &help);
00175 
00188    void addMethod (MethodAdder::DynamicMethodCall_t wrapper,
00189                    const Signature &ret_signature,
00190                    const CppString &name,
00191                    const Signature &signature,
00192                    const CppString &help);
00193 
00205    void addMethod (MethodAdder::SystemMethodCall_t adr,
00206                    const Signature &ret_signature,
00207                    const CppString &name,
00208                    const Signature &signature,
00209                    const CppString &help);
00210 
00214    void removeMethod(const CppString &name);
00215 
00216   protected:
00217 
00221    virtual void forwardThreadedError(const Exception &ex) const;
00222 
00223   /* The threaded function that does the work.
00224    * @param  conn  pointer to communication object
00225    * @param  td    pointer to working data
00226    */
00227    void *serverLoop(Protocol *protocol, ThreadData *td);
00228 
00231    void printStatistics() const;
00232 
00236    virtual void preProcessCall(MethodCall &call);
00237 
00241    virtual void preProcessResponse(MethodResponse &resp);
00242 
00243   private:
00244 
00248    static void *startThread(ThreadData *td);
00249 
00252    void releaseThreads();
00253 
00254    typedef void *(Thread_t) (ThreadData*);
00255 
00256    std::vector<ThreadData*>       threads;
00257    Dispatcher                     dispatcher;
00258    bool                           wbxml_mode;
00259 
00260  private:
00261 
00262    // forbid them all due to internal pointers
00263    MultiThreadRpcServer(const MultiThreadRpcServer&);
00264    MultiThreadRpcServer& operator=(const MultiThreadRpcServer&);
00265 };
00266 
00267 
00268 }  // namespace ulxr
00269 
00270 
00271 #endif // ULXR_MULTITHREADED
00272 
00273 
00274 #endif // ULXR_MTRPC_SERVER_H

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