#include <ulxr_dispatcher.h>
Inheritance diagram for ulxr::Dispatcher:
Public Member Functions | |
Dispatcher (Protocol *prot=0, bool wbxml_mode=false) | |
Constructs a dispatcher. | |
virtual | ~Dispatcher () |
Destroys the dispatcher. | |
void | addMethod (StaticMethodCall_t adr, const CppString &ret_signature, const CppString &name, const CppString &signature, const CppString &help) |
Adds a user defined (static) method to the dispatcher. | |
void | addMethod (DynamicMethodCall_t wrapper, const CppString &ret_signature, const CppString &name, const CppString &signature, const CppString &help) |
Adds a user defined (dynamic) method to the dispatcher. | |
void | addMethod (SystemMethodCall_t adr, const CppString &ret_signature, const CppString &name, const CppString &signature, const CppString &help) |
Adds a system internal method to the dispatcher. | |
void | addMethod (StaticMethodCall_t adr, const Signature &ret_signature, const CppString &name, const Signature &signature, const CppString &help) |
Adds a user defined (static) method to the dispatcher. | |
void | addMethod (DynamicMethodCall_t wrapper, const Signature &ret_signature, const CppString &name, const Signature &signature, const CppString &help) |
Adds a user defined (dynamic) method to the dispatcher. | |
void | addMethod (SystemMethodCall_t adr, const Signature &ret_signature, const CppString &name, const Signature &signature, const CppString &help) |
Adds a system internal method to the dispatcher. | |
virtual MethodCall | waitForCall (int timeout=0) |
Waits for an incoming method call. | |
virtual MethodResponse | dispatchCall (const MethodCall &call) const |
Dispatches the call to the according implementation. | |
virtual MethodResponse | dispatchCallLoc (const MethodCall &call) const |
Dispatches the call to the according implementation. | |
virtual void | sendResponse (const MethodResponse &resp) |
Sends the response back to the requester. | |
Protocol * | getProtocol () const |
Returns the current connection. | |
void | setProtocol (Protocol *prot) |
Sets the current connection. | |
unsigned | numMethods () const |
Gets the number of available methods. | |
const MethodCallDescriptor *const | getMethod (unsigned index) |
Gets method data. | |
bool | hasMethod (const MethodCall &call) const |
Checks if a method is available. | |
void | removeMethod (const CppString &name) |
Removes a method if available. | |
Protected Types | |
typedef std::map< MethodCallDescriptor, MethodCall_t > | MethodCallMap |
Protected Member Functions | |
void | addMethodDescriptor (const MethodCallDescriptor &desc, MethodCall_t mct) |
Adds a methode descriptor to the dispatcher. | |
void | setupSystemMethods () |
Adds internal "system.x" methods. | |
virtual void | getCapabilities (Struct &str) const |
Returns a struct containing the capabilities of this system. | |
Static Protected Member Functions | |
static MethodResponse | xml_pretty_print (const MethodCall &calldata, const Dispatcher *disp) |
Enable pretty-printed xml responses. | |
static MethodResponse | system_listMethods (const MethodCall &calldata, const Dispatcher *disp) |
Lists all methods implemented by this server. | |
static MethodResponse | system_methodSignature (const MethodCall &calldata, const Dispatcher *disp) |
Returns an array of possible signatures for this method. | |
static MethodResponse | system_methodHelp (const MethodCall &calldata, const Dispatcher *disp) |
Returns a documentation string describing the use of this method. | |
static MethodResponse | system_getCapabilities (const MethodCall &calldata, const Dispatcher *disp) |
Returns a struct containing the capabilities of this system. | |
Private Attributes | |
MethodCallMap | methodcalls |
Protocol * | protocol |
bool | wbxml_mode |
Friends | |
struct | MethodCallDescriptor |
void | free_dynamic_method (const MethodCallMap::value_type &) |
Classes | |
struct | MethodCallDescriptor |
The dispacher waits for incoming requests. The request is parsed and the according method is called afterwards the response is converted into xml and sent back to the requester. Direct use of this class is intended for proprietary connections. If you go the usual way via http you ought to use the HttpServer class and run "picoHttpd"
Definition at line 58 of file ulxr_dispatcher.h.
typedef std::map<MethodCallDescriptor, MethodCall_t> ulxr::Dispatcher::MethodCallMap [protected] |
Definition at line 162 of file ulxr_dispatcher.h.
ulxr::Dispatcher::Dispatcher | ( | Protocol * | prot = 0 , |
|
bool | wbxml_mode = false | |||
) |
Constructs a dispatcher.
prot | pointer to an existing Protocol | |
wbxml_mode | true: data is sent as wbxml |
Definition at line 181 of file ulxr_dispatcher.cpp.
References protocol, setupSystemMethods(), and wbxml_mode.
ulxr::Dispatcher::~Dispatcher | ( | ) | [virtual] |
Destroys the dispatcher.
Important: Also frees wrapper objects to worker classes since Dispatcher owns them!
Definition at line 200 of file ulxr_dispatcher.cpp.
References free_dynamic_method, methodcalls, ULXR_PCHAR, and ULXR_TRACE.
void ulxr::Dispatcher::addMethod | ( | StaticMethodCall_t | adr, | |
const CppString & | ret_signature, | |||
const CppString & | name, | |||
const CppString & | signature, | |||
const CppString & | help | |||
) |
Adds a user defined (static) method to the dispatcher.
You access a remote method by sending the "official" name. Sometimes a method accepts different parameter sets (overloading in C++). In this case you add the according signature. Finally you can add a description to show the usage of this method.
adr | the pointer to the implementation of the method | |
ret_signature | the signature of the return value | |
name | the name of the method | |
signature | the signature of the parameters | |
help | short usage description |
Definition at line 223 of file ulxr_dispatcher.cpp.
References ULXR_PCHAR, and ULXR_TRACE.
void ulxr::Dispatcher::addMethod | ( | DynamicMethodCall_t | wrapper, | |
const CppString & | ret_signature, | |||
const CppString & | name, | |||
const CppString & | signature, | |||
const CppString & | help | |||
) | [virtual] |
Adds a user defined (dynamic) method to the dispatcher.
You access a remote method by sending the "official" name. Sometimes a method accepts different parameter sets (overloading in C++). In this case you add the according signature. Finally you can add a description to show the usage of this method.
wrapper | the pointer to the wrapper to the method. Important: Dispatcher owns now and deletes this wrapper object! | |
ret_signature | the signature of the return value | |
name | the name of the method | |
signature | the signature of the parameters | |
help | short usage description |
Implements ulxr::MethodAdder.
Definition at line 237 of file ulxr_dispatcher.cpp.
References ULXR_PCHAR, and ULXR_TRACE.
void ulxr::Dispatcher::addMethod | ( | SystemMethodCall_t | adr, | |
const CppString & | ret_signature, | |||
const CppString & | name, | |||
const CppString & | signature, | |||
const CppString & | help | |||
) |
Adds a system internal method to the dispatcher.
You access a remote method by sending the "official" name. Sometimes a method accepts different parameter sets (overloading in C++). In this case you add the according signature. Finally you can add a description to show the usage of this method.
adr | the pointer to the implementation of the method | |
ret_signature | the signature of the return value | |
name | the name of the method | |
signature | the signature of the parameters | |
help | short usage description |
Definition at line 251 of file ulxr_dispatcher.cpp.
References ULXR_PCHAR, and ULXR_TRACE.
void ulxr::Dispatcher::addMethod | ( | StaticMethodCall_t | adr, | |
const Signature & | ret_signature, | |||
const CppString & | name, | |||
const Signature & | signature, | |||
const CppString & | help | |||
) |
Adds a user defined (static) method to the dispatcher.
You access a remote method by sending the "official" name. Sometimes a method accepts different parameter sets (overloading in C++). In this case you add the according signature. Finally you can add a description to show the usage of this method.
adr | the pointer to the implementation of the method | |
ret_signature | the signature of the return value | |
name | the name of the method | |
signature | the signature of the parameters | |
help | short usage description |
Definition at line 265 of file ulxr_dispatcher.cpp.
void ulxr::Dispatcher::addMethod | ( | DynamicMethodCall_t | wrapper, | |
const Signature & | ret_signature, | |||
const CppString & | name, | |||
const Signature & | signature, | |||
const CppString & | help | |||
) | [virtual] |
Adds a user defined (dynamic) method to the dispatcher.
You access a remote method by sending the "official" name. Sometimes a method accepts different parameter sets (overloading in C++). In this case you add the according signature. Finally you can add a description to show the usage of this method.
wrapper | the pointer to the wrapper to the method. Important: Dispatcher owns now and deletes this wrapper object! | |
ret_signature | the signature of the return value | |
name | the name of the method | |
signature | the signature of the parameters | |
help | short usage description |
Implements ulxr::MethodAdder.
Definition at line 275 of file ulxr_dispatcher.cpp.
void ulxr::Dispatcher::addMethod | ( | SystemMethodCall_t | adr, | |
const Signature & | ret_signature, | |||
const CppString & | name, | |||
const Signature & | signature, | |||
const CppString & | help | |||
) |
Adds a system internal method to the dispatcher.
You access a remote method by sending the "official" name. Sometimes a method accepts different parameter sets (overloading in C++). In this case you add the according signature. Finally you can add a description to show the usage of this method.
adr | the pointer to the implementation of the method | |
ret_signature | the signature of the return value | |
name | the name of the method | |
signature | the signature of the parameters | |
help | short usage description |
Definition at line 285 of file ulxr_dispatcher.cpp.
MethodCall ulxr::Dispatcher::waitForCall | ( | int | timeout = 0 |
) | [virtual] |
Waits for an incoming method call.
timeout | the timeout value [sec] (0 - no timeout) |
Definition at line 308 of file ulxr_dispatcher.cpp.
References ulxr::Protocol::ConnBody, ulxr::Protocol::ConnError, ulxr::Protocol::ConnSwitchToBody, ulxr::MethodCallParserBase::getMethodCall(), ulxr::MethodCall::getXml(), ulxr::NotConformingError, ulxr::TransportError, ULXR_DOUT_READ, ULXR_DOUT_XML, ULXR_GET_STRING, ulxr_i18n, ULXR_PCHAR, ULXR_RECV_BUFFER_SIZE, and ULXR_TRACE.
Referenced by ulxr::MultiThreadRpcServer::serverLoop().
MethodResponse ulxr::Dispatcher::dispatchCall | ( | const MethodCall & | call | ) | const [virtual] |
Dispatches the call to the according implementation.
call | the call data |
Definition at line 442 of file ulxr_dispatcher.cpp.
References ulxr::ApplicationError, ulxr::Exception::getFaultCode(), ulxr::SystemError, ULXR_GET_STRING, ulxr_i18n, ULXR_PCHAR, ULXR_TRACE, and ulxr::Exception::why().
MethodResponse ulxr::Dispatcher::dispatchCallLoc | ( | const MethodCall & | call | ) | const [virtual] |
Dispatches the call to the according implementation.
Does not catch any exceptions
call | the call data |
Definition at line 467 of file ulxr_dispatcher.cpp.
References ulxr::MethodNotFoundError, ulxr_i18n, ULXR_PCHAR, and ULXR_TRACE.
void ulxr::Dispatcher::sendResponse | ( | const MethodResponse & | resp | ) | [virtual] |
Sends the response back to the requester.
resp | the response data |
Definition at line 524 of file ulxr_dispatcher.cpp.
References ULXR_PCHAR, and ULXR_TRACE.
Protocol * ulxr::Dispatcher::getProtocol | ( | ) | const |
Returns the current connection.
Definition at line 717 of file ulxr_dispatcher.cpp.
void ulxr::Dispatcher::setProtocol | ( | Protocol * | prot | ) |
Sets the current connection.
prot | pointer to the new protcol |
Definition at line 723 of file ulxr_dispatcher.cpp.
unsigned ulxr::Dispatcher::numMethods | ( | ) | const |
Gets the number of available methods.
Definition at line 424 of file ulxr_dispatcher.cpp.
References ULXR_PCHAR, and ULXR_TRACE.
const Dispatcher::MethodCallDescriptor *const ulxr::Dispatcher::getMethod | ( | unsigned | index | ) |
Gets method data.
index | index for method |
Definition at line 410 of file ulxr_dispatcher.cpp.
References ulxr::ApplicationError, methodcalls, ulxr_i18n, ULXR_PCHAR, and ULXR_TRACE.
bool ulxr::Dispatcher::hasMethod | ( | const MethodCall & | call | ) | const |
Checks if a method is available.
call | call data |
Definition at line 435 of file ulxr_dispatcher.cpp.
void ulxr::Dispatcher::removeMethod | ( | const CppString & | name | ) | [virtual] |
Removes a method if available.
name | method name |
Implements ulxr::MethodAdder.
Definition at line 208 of file ulxr_dispatcher.cpp.
References ulxr::free_dynamic_method(), ULXR_PCHAR, and ULXR_TRACE.
void ulxr::Dispatcher::addMethodDescriptor | ( | const MethodCallDescriptor & | desc, | |
MethodCall_t | mct | |||
) | [protected] |
Adds a methode descriptor to the dispatcher.
desc | descriptor data | |
mct | pointer to the function |
Definition at line 296 of file ulxr_dispatcher.cpp.
References ulxr::ApplicationError, ulxr_i18n, ULXR_PCHAR, and ULXR_TRACE.
void ulxr::Dispatcher::setupSystemMethods | ( | ) | [protected] |
Adds internal "system.x" methods.
Definition at line 531 of file ulxr_dispatcher.cpp.
References system_getCapabilities(), system_listMethods(), system_methodHelp(), system_methodSignature(), ulxr_i18n, ULXR_PCHAR, ULXR_TRACE, and xml_pretty_print().
Referenced by Dispatcher().
MethodResponse ulxr::Dispatcher::xml_pretty_print | ( | const MethodCall & | calldata, | |
const Dispatcher * | disp | |||
) | [static, protected] |
Enable pretty-printed xml responses.
calldata | parameters, must be one bool with new status | |
disp | pointer to actual dispatcher |
Definition at line 564 of file ulxr_dispatcher.cpp.
References ulxr::enableXmlPrettyPrint(), ulxr::InvalidMethodParameterError, ulxr::RpcBoolean, ulxr_i18n, ULXR_PCHAR, and ULXR_TRACE.
Referenced by setupSystemMethods().
MethodResponse ulxr::Dispatcher::system_listMethods | ( | const MethodCall & | calldata, | |
const Dispatcher * | disp | |||
) | [static, protected] |
Lists all methods implemented by this server.
calldata | parameters, must be none | |
disp | pointer to actual dispatcher |
Definition at line 584 of file ulxr_dispatcher.cpp.
References ulxr::Array::addItem(), ulxr::InvalidMethodParameterError, ulxr::RpcStrType, ulxr_i18n, ULXR_PCHAR, and ULXR_TRACE.
Referenced by setupSystemMethods().
MethodResponse ulxr::Dispatcher::system_methodSignature | ( | const MethodCall & | calldata, | |
const Dispatcher * | disp | |||
) | [static, protected] |
Returns an array of possible signatures for this method.
The signature consists of the return value and all parameters divided by commas.
calldata | 1 parameter with method name. | |
disp | pointer to actual dispatcher |
Definition at line 615 of file ulxr_dispatcher.cpp.
References ulxr::Array::addItem(), ulxr::RpcString::getString(), ulxr::InvalidMethodParameterError, ulxr::RpcStrType, ulxr::Array::size(), ulxr_i18n, ULXR_PCHAR, and ULXR_TRACE.
Referenced by setupSystemMethods().
MethodResponse ulxr::Dispatcher::system_methodHelp | ( | const MethodCall & | calldata, | |
const Dispatcher * | disp | |||
) | [static, protected] |
Returns a documentation string describing the use of this method.
If appropriate the return string contains html markup. If there are overloaded methods a description for each may be returned.
calldata | 1 parameter with method name. | |
disp | pointer to actual dispatcher |
Definition at line 656 of file ulxr_dispatcher.cpp.
References ulxr::RpcString::getString(), ulxr::InvalidMethodParameterError, ulxr::RpcStrType, ulxr_i18n, ULXR_PCHAR, and ULXR_TRACE.
Referenced by setupSystemMethods().
MethodResponse ulxr::Dispatcher::system_getCapabilities | ( | const MethodCall & | calldata, | |
const Dispatcher * | disp | |||
) | [static, protected] |
Returns a struct containing the capabilities of this system.
Derived class should re-implement addCapabilities() if appropriate and invode parents accordingly.
calldata | 0 parameters included | |
disp | pointer to actual dispatcher |
Definition at line 701 of file ulxr_dispatcher.cpp.
References ulxr::Struct::addMember(), ulxr::InvalidMethodParameterError, ulxr_i18n, and ULXR_PCHAR.
Referenced by setupSystemMethods().
void ulxr::Dispatcher::getCapabilities | ( | Struct & | str | ) | const [protected, virtual] |
Returns a struct containing the capabilities of this system.
str | reference to a Struct to return the capabilities |
Definition at line 691 of file ulxr_dispatcher.cpp.
References ULXR_PCHAR.
friend struct MethodCallDescriptor [friend] |
Definition at line 166 of file ulxr_dispatcher.h.
void free_dynamic_method | ( | const MethodCallMap::value_type & | ) | [friend] |
Referenced by ~Dispatcher().
MethodCallMap ulxr::Dispatcher::methodcalls [private] |
Protocol* ulxr::Dispatcher::protocol [private] |
bool ulxr::Dispatcher::wbxml_mode [private] |