ctkEventDefinitions.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * ctkEventDefinitions.h
  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. #ifndef CTKEVENTDEFINITIONS_H
  12. #define CTKEVENTDEFINITIONS_H
  13. // Qt includes
  14. #include <QByteArray>
  15. #include <QList>
  16. #include <QMap>
  17. #include <QVariant>
  18. #include <QString>
  19. #include <QStringList>
  20. #include <QHash>
  21. #include <QThread>
  22. #include <QThreadPool>
  23. #include <QObject>
  24. #include <QDebug>
  25. #include "org_commontk_eventbus_Export.h"
  26. //defines
  27. #define TOPIC "event.topics"
  28. #define TYPE "EventType"
  29. #define SIGTYPE "SignatureType"
  30. #define OBJECT "ObjectPointer"
  31. #define SIGNATURE "Signature"
  32. class ctkBusEvent;
  33. #define ctkRegisterLocalSignal(topic, sender, signature) \
  34. {\
  35. ctkBusEvent *properties = new ctkBusEvent(topic, ctkEventBus::ctkEventTypeLocal, ctkEventBus::ctkSignatureTypeSignal, static_cast<QObject*>(sender), signature); \
  36. bool ok = ctkEventBus::ctkEventBusManager::instance()->addEventProperty(*properties);\
  37. if(!ok) {\
  38. qWarning("%s", tr("Some problem occourred during the signal registration with ID '%1'.").arg(topic).toAscii().data());\
  39. if(properties) {delete properties; properties = NULL;} \
  40. }\
  41. }
  42. #define ctkRegisterRemoteSignal(topic, sender, signature) \
  43. {\
  44. ctkBusEvent *properties = new ctkBusEvent(topic, ctkEventBus::ctkEventTypeRemote, ctkEventBus::ctkSignatureTypeSignal, static_cast<QObject*>(sender), signature); \
  45. bool ok = ctkEventBus::ctkEventBusManager::instance()->addEventProperty(*properties);\
  46. if(!ok) {\
  47. qWarning("%s", tr("Some problem occourred during the signal registration with ID '%1'.").arg(topic).toAscii().data());\
  48. if(properties) {delete properties; properties = NULL;} \
  49. }\
  50. }
  51. #define ctkRegisterLocalCallback(topic, observer, signature) \
  52. {\
  53. ctkBusEvent *properties = new ctkBusEvent(topic, ctkEventBus::ctkEventTypeLocal, ctkEventBus::ctkSignatureTypeCallback, static_cast<QObject*>(observer), signature); \
  54. bool ok = ctkEventBus::ctkEventBusManager::instance()->addEventProperty(*properties);\
  55. if(!ok) {\
  56. qWarning("%s", tr("Some problem occourred during the callback registration with ID '%1'.").arg(topic).toAscii().data());\
  57. if(properties) {delete properties; properties = NULL;} \
  58. }\
  59. }
  60. #define ctkRegisterRemoteCallback(topic, sender, signature) \
  61. {\
  62. ctkBusEvent *properties = new ctkBusEvent(topic, ctkEventBus::ctkEventTypeRemote, ctkEventBus::ctkSignatureTypeCallback, static_cast<QObject*>(sender), signature); \
  63. bool ok = ctkEventBus::ctkEventBusManager::instance()->addEventProperty(*properties);\
  64. if(!ok) {\
  65. qWarning("%s", tr("Some problem occourred during the callback registration with ID '%1'.").arg(topic).toAscii().data());\
  66. if(properties) {delete properties; properties = NULL;} \
  67. }\
  68. }
  69. namespace ctkEventBus {
  70. //forward classes
  71. class ctkNetworkConnector;
  72. /// Hash table that associate the communication protocol with the corresponding network connector class (Eg. XMLRPC, ctkEventBus::ctkNetworkConnectorQXMLRPC)
  73. typedef QHash<QString, ctkNetworkConnector *> ctkNetworkConnectorHash;
  74. /// typedef that represents dictionary entries ( key , value )
  75. typedef QHash<QString, QVariant> ctkEventHash;
  76. ///< Enum that identify the ctkEventType's type: Local or Remote.
  77. typedef enum {
  78. ctkEventTypeLocal,
  79. ctkEventTypeRemote
  80. } ctkEventType;
  81. ///< Enum that identify the mafSignatureType's type: Signal or Callback.
  82. typedef enum {
  83. ctkSignatureTypeSignal = 0,
  84. ctkSignatureTypeCallback = 1
  85. } ctkSignatureType;
  86. /// List of the arguments to be sent through the event bus.
  87. typedef QList<QGenericArgument> ctkEventArgumentsList;
  88. typedef ctkEventArgumentsList * ctkEventArgumentsListPointer;
  89. #define ctkEventArgument(type, data) QArgument<type >(#type, data)
  90. #define ctkGenericReturnArgument QGenericReturnArgument
  91. #define ctkEventReturnArgument(type, data) QReturnArgument<type >(#type, data)
  92. /// Types definitions for events' hash (to be more readable).
  93. typedef QHash<QString, ctkBusEvent *> ctkEventsHashType;
  94. /// type definition for observers' properties list to be stored into the event's hash.
  95. typedef QList<ctkBusEvent *> ctkEventItemListType;
  96. /// map which represent list of function to be registered in the server, with parameters
  97. typedef QMap<QString, QList<QVariant::Type> > mafRegisterMethodsMap;
  98. } // namespace ctkEventBus
  99. Q_DECLARE_METATYPE(ctkEventBus::ctkEventArgumentsListPointer);
  100. Q_DECLARE_METATYPE(ctkEventBus::mafRegisterMethodsMap);
  101. #endif // CTKEVENTDEFINITIONS_H