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 #ifndef ULXR_MTRPC_SERVER_H
00031 #define ULXR_MTRPC_SERVER_H
00032
00033 #include <ulxmlrpcpp/ulxmlrpcpp.h>
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
00224
00225
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
00263 MultiThreadRpcServer(const MultiThreadRpcServer&);
00264 MultiThreadRpcServer& operator=(const MultiThreadRpcServer&);
00265 };
00266
00267
00268 }
00269
00270
00271 #endif // ULXR_MULTITHREADED
00272
00273
00274 #endif // ULXR_MTRPC_SERVER_H