ctkNetworkConnectorQXMLRPC.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * ctkNetworkConnectorQXMLRPC.h
  3. * ctkEventBus
  4. *
  5. * Created by Daniele Giunchi on 11/04/10.
  6. * Copyright 2009 B3C. All rights reserved.
  7. *
  8. * See Licence at: http://tiny.cc/QXJ4D
  9. *
  10. */
  11. #ifndef ctkNetworkConnectorQXMLRPC_H
  12. #define ctkNetworkConnectorQXMLRPC_H
  13. // include list
  14. #include "ctkNetworkConnector.h"
  15. // Foundation Library include list
  16. #include <xmlrpc/client.h>
  17. #include <xmlrpc/server.h>
  18. namespace ctkEventBus {
  19. /**
  20. Class name: ctkNetworkConnectorQXMLRPC
  21. This class is the implementation class for client/server objects that works over network
  22. with xml-rpc protocol. The server side part also create a new ID named REGISTER_SERVER_METHODS_XXX
  23. (where the XXX is the port on which run the server) that allows you to register your own remote
  24. callbacks. The library used is qxmlrpc.
  25. */
  26. class org_commontk_eventbus_EXPORT ctkNetworkConnectorQXMLRPC : public ctkNetworkConnector {
  27. Q_OBJECT
  28. public:
  29. /// object constructor.
  30. ctkNetworkConnectorQXMLRPC();
  31. /// object destructor.
  32. /*virtual*/ ~ctkNetworkConnectorQXMLRPC();
  33. /// create the unique instance of the client.
  34. /*virtual*/ void createClient(const QString hostName, const unsigned int port);
  35. /// create the unique instance of the server.
  36. /*virtual*/ void createServer(const unsigned int port);
  37. /// Start the server.
  38. /*virtual*/ void startListen();
  39. //retrieve an instance of the object
  40. /*virtual*/ ctkNetworkConnector *clone();
  41. /// register all the signals and slots
  42. /*virtual*/ void initializeForEventBus();
  43. Q_SIGNALS:
  44. /// signal for the registration of the functions with parameters
  45. void registerMethodsServer(mafRegisterMethodsMap registerMethodsList);
  46. public Q_SLOTS:
  47. /// register methods on the server
  48. void registerServerMethod(mafRegisterMethodsMap registerMethodsList);
  49. /// Allow to send a network request.
  50. /** Contains the conversion between maf datatypes and qxmlrpc datatype based both on QVariant. */
  51. /*virtual*/ void send(const QString event_id, ctkEventArgumentsList *argList);
  52. private Q_SLOTS:
  53. /// callback for the client which retrieve the variable from the server
  54. virtual void processReturnValue( int requestId, QVariant value );
  55. /// callback which manage a fault in the connection
  56. void processFault( int requestId, int errorCode, QString errorString );
  57. /// callback for the server which receive a request to be processed
  58. virtual void processRequest( int requestId, QString methodName, QList<xmlrpc::Variant> parameters );
  59. protected:
  60. xmlrpc::Client *m_Client; ///< xml-rpc client provided by qxmlrpc library
  61. xmlrpc::Server *m_Server; ///< xml-rpc server provided by qxmlrpc library
  62. private:
  63. /// send a request from the client to the network.
  64. void xmlrpcSend(const QString &methodName, QList<xmlrpc::Variant> parameters);
  65. /// stop and destroy the server instance.
  66. void stopServer();
  67. int m_RequestId; ///< id test for a specific (experimental) request
  68. };
  69. } //namespace ctkEventBus
  70. Q_DECLARE_METATYPE(xmlrpc::Variant);
  71. #endif // ctkNetworkConnectorQXMLRPC_H