ctkEventDispatcherRemote.cpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * ctkEventDispatcherRemote.cpp
  3. * ctkEventBus
  4. *
  5. * Created by Paolo Quadrani on 27/03/09.
  6. * Copyright 2009 B3C. All rights reserved.
  7. *
  8. * See Licence at: http://tiny.cc/QXJ4D
  9. *
  10. */
  11. #include "ctkEventDispatcherRemote.h"
  12. #include "ctkBusEvent.h"
  13. #include "ctkNetworkConnector.h"
  14. using namespace ctkEventBus;
  15. ctkEventDispatcherRemote::ctkEventDispatcherRemote() : ctkEventDispatcher(), m_NetworkConnectorServer(NULL), m_NetworkConnectorClient(NULL) {
  16. this->initializeGlobalEvents();
  17. }
  18. ctkEventDispatcherRemote::~ctkEventDispatcherRemote() {
  19. if(m_NetworkConnectorServer) delete m_NetworkConnectorServer;
  20. m_NetworkConnectorServer = NULL;
  21. if(m_NetworkConnectorClient) delete m_NetworkConnectorClient;
  22. m_NetworkConnectorClient = NULL;
  23. }
  24. ctkNetworkConnector *ctkEventDispatcherRemote::networkConnectorServer() {
  25. return m_NetworkConnectorServer;
  26. }
  27. ctkNetworkConnector *ctkEventDispatcherRemote::networkConnectorClient() {
  28. return m_NetworkConnectorClient;
  29. }
  30. void ctkEventDispatcherRemote::initializeGlobalEvents() {
  31. ctkBusEvent *properties = new ctkBusEvent("ctk/remote/eventBus/globalUpdate",ctkEventTypeRemote,ctkSignatureTypeSignal,this,"notifyDefaultEvent()");
  32. this->registerSignal(*properties);
  33. // events like remoteCommunicationDone or failed represents th bridge events between a remote communication
  34. // and the possibility to call local slots. The notifyEvent local sends events inside the local objects registered as observers
  35. // through the event bus manager while the remote notification (ctkEventTypeRemote) uses the network connector.
  36. }
  37. void ctkEventDispatcherRemote::setNetworkConnectorServer(ctkNetworkConnector *connector) {
  38. if(m_NetworkConnectorServer == NULL) {
  39. m_NetworkConnectorServer = connector->clone();
  40. m_NetworkConnectorServer->initializeForEventBus();
  41. } else {
  42. if(m_NetworkConnectorServer->protocol() != connector->protocol()) {
  43. delete m_NetworkConnectorServer; //if there will be multiprotocol , here there will be a problem for thread app
  44. m_NetworkConnectorServer = connector->clone();
  45. m_NetworkConnectorServer->initializeForEventBus();
  46. }
  47. }
  48. }
  49. void ctkEventDispatcherRemote::setNetworkConnectorClient(ctkNetworkConnector *connector) {
  50. if(m_NetworkConnectorClient == NULL) {
  51. m_NetworkConnectorClient = connector->clone();
  52. m_NetworkConnectorClient->initializeForEventBus();
  53. } else {
  54. if(m_NetworkConnectorClient->protocol() != connector->protocol()) {
  55. delete m_NetworkConnectorClient; //if there will be multiprotocol , here there will be a problem for thread app
  56. m_NetworkConnectorClient = connector->clone();
  57. m_NetworkConnectorClient->initializeForEventBus();
  58. }
  59. }
  60. }
  61. void ctkEventDispatcherRemote::notifyEvent(ctkBusEvent &event_dictionary, ctkEventArgumentsList *argList, ctkGenericReturnArgument *returnArg) const {
  62. //Q_UNUSED(event_dictionary);
  63. //Q_UNUSED(argList);
  64. Q_UNUSED(returnArg);
  65. // Call the notifyEventRemote converting the arguments...
  66. m_NetworkConnectorClient->send(event_dictionary[TOPIC].toString(), argList);
  67. }