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_DISPATCHER_H
00031 #define ULXR_DISPATCHER_H
00032
00033 #include <ulxmlrpcpp/ulxmlrpcpp.h>
00034
00035 #include <ulxmlrpcpp/ulxr_call.h>
00036 #include <ulxmlrpcpp/ulxr_response.h>
00037 #include <ulxmlrpcpp/ulxr_method_adder.h>
00038
00039
00040 namespace ulxr {
00041
00042
00043 class Protocol;
00044 class Connection;
00045 class Struct;
00046 class Signature;
00047
00048
00058 class ULXR_API_DECL0 Dispatcher : public MethodAdder
00059 {
00060 public:
00061
00062 struct ULXR_API_DECL0 MethodCallDescriptor
00063 {
00064
00065 friend class Dispatcher;
00066
00070 MethodCallDescriptor(const MethodCall &call);
00071
00079 MethodCallDescriptor(CallType calltype,
00080 const CppString &ret_sig,
00081 const CppString &name,
00082 const CppString &signature,
00083 const CppString &help);
00084
00088 bool operator == (const MethodCallDescriptor &desc) const
00089 { return getSignature(true, false) == desc.getSignature(true, false); }
00090
00094 bool operator < (const MethodCallDescriptor &desc) const
00095 { return getSignature(true, false) < desc.getSignature(true, false); }
00096
00102 CppString getSignature(bool with_name, bool with_return) const;
00103
00107 unsigned long getInvoked() const;
00108
00111 void incInvoked() const;
00112
00116 bool isEnabled() const;
00117
00121 void setEnabled(bool ena) const;
00122
00126 CppString getMethodName() const;
00127
00131 CppString getParameterSignature() const;
00132
00136 CppString getReturnValueSignature() const;
00137
00141 CppString getDocumentation() const;
00142
00146 CallType getCallType() const;
00147
00148 private:
00149
00150 CallType calltype;
00151 CppString method_name;
00152 CppString signature;
00153 CppString return_signature;
00154 CppString documentation;
00155
00156 mutable unsigned long invoked;
00157 mutable bool enabled;
00158 };
00159
00160 protected:
00161
00162 typedef std::map<MethodCallDescriptor, MethodCall_t> MethodCallMap;
00163
00164 friend void free_dynamic_method(const MethodCallMap::value_type &);
00165
00166 friend struct MethodCallDescriptor;
00167
00168 public:
00169
00174 Dispatcher (Protocol* prot = 0, bool wbxml_mode = false);
00175
00180 virtual ~Dispatcher ();
00181
00193 void addMethod (StaticMethodCall_t adr,
00194 const CppString &ret_signature,
00195 const CppString &name,
00196 const CppString &signature,
00197 const CppString &help);
00198
00211 void addMethod (DynamicMethodCall_t wrapper,
00212 const CppString &ret_signature,
00213 const CppString &name,
00214 const CppString &signature,
00215 const CppString &help);
00216
00228 void addMethod (SystemMethodCall_t adr,
00229 const CppString &ret_signature,
00230 const CppString &name,
00231 const CppString &signature,
00232 const CppString &help);
00233
00245 void addMethod (StaticMethodCall_t adr,
00246 const Signature &ret_signature,
00247 const CppString &name,
00248 const Signature &signature,
00249 const CppString &help);
00250
00263 void addMethod (DynamicMethodCall_t wrapper,
00264 const Signature &ret_signature,
00265 const CppString &name,
00266 const Signature &signature,
00267 const CppString &help);
00268
00280 void addMethod (SystemMethodCall_t adr,
00281 const Signature &ret_signature,
00282 const CppString &name,
00283 const Signature &signature,
00284 const CppString &help);
00285
00290 virtual MethodCall waitForCall(int timeout = 0);
00291
00296 virtual MethodResponse dispatchCall(const MethodCall &call) const;
00297
00304 virtual MethodResponse dispatchCallLoc(const MethodCall &call) const;
00305
00309 virtual void sendResponse(const MethodResponse &resp);
00310
00314 Protocol* getProtocol() const;
00315
00319 void setProtocol(Protocol *prot);
00320
00324 unsigned numMethods() const;
00325
00330 const MethodCallDescriptor * const getMethod(unsigned index);
00331
00336 bool hasMethod(const MethodCall &call) const;
00337
00341 void removeMethod(const CppString &name);
00342
00343 protected:
00344
00349 void addMethodDescriptor (const MethodCallDescriptor &desc,
00350 MethodCall_t mct);
00351
00354 void setupSystemMethods();
00355
00361 static MethodResponse xml_pretty_print(const MethodCall &calldata,
00362 const Dispatcher *disp);
00363
00369 static MethodResponse system_listMethods(const MethodCall &calldata,
00370 const Dispatcher *disp);
00371
00379 static MethodResponse system_methodSignature(const MethodCall &calldata,
00380 const Dispatcher *disp);
00381
00389 static MethodResponse system_methodHelp(const MethodCall &calldata,
00390 const Dispatcher *disp);
00391
00399 static MethodResponse system_getCapabilities(const MethodCall &calldata,
00400 const Dispatcher *disp);
00401
00405 virtual void getCapabilities (Struct &str) const;
00406
00407 private:
00408
00409 MethodCallMap methodcalls;
00410 Protocol *protocol;
00411 bool wbxml_mode;
00412 };
00413
00414
00415 }
00416
00417
00418 #endif // ULXR_DISPATCHER_H