/* * ctkEventDefinitions.h * ctkEventBus * * Created by Paolo Quadrani on 27/03/09. * Copyright 2009 B3C. All rights reserved. * * See Licence at: http://tiny.cc/QXJ4D * */ #ifndef CTKEVENTDEFINITIONS_H #define CTKEVENTDEFINITIONS_H // Qt includes #include #include #include #include #include #include #include #include #include #include #include #include "org_commontk_eventbus_Export.h" //defines #define TOPIC "event.topics" #define TYPE "EventType" #define SIGTYPE "SignatureType" #define OBJECT "ObjectPointer" #define SIGNATURE "Signature" class ctkBusEvent; #define ctkRegisterLocalSignal(topic, sender, signature) \ {\ ctkBusEvent *properties = new ctkBusEvent(topic, ctkEventBus::ctkEventTypeLocal, ctkEventBus::ctkSignatureTypeSignal, static_cast(sender), signature); \ bool ok = ctkEventBus::ctkEventBusManager::instance()->addEventProperty(*properties);\ if(!ok) {\ qWarning("%s", tr("Some problem occourred during the signal registration with ID '%1'.").arg(topic).toAscii().data());\ if(properties) {delete properties; properties = NULL;} \ }\ } #define ctkRegisterRemoteSignal(topic, sender, signature) \ {\ ctkBusEvent *properties = new ctkBusEvent(topic, ctkEventBus::ctkEventTypeRemote, ctkEventBus::ctkSignatureTypeSignal, static_cast(sender), signature); \ bool ok = ctkEventBus::ctkEventBusManager::instance()->addEventProperty(*properties);\ if(!ok) {\ qWarning("%s", tr("Some problem occourred during the signal registration with ID '%1'.").arg(topic).toAscii().data());\ if(properties) {delete properties; properties = NULL;} \ }\ } #define ctkRegisterLocalCallback(topic, observer, signature) \ {\ ctkBusEvent *properties = new ctkBusEvent(topic, ctkEventBus::ctkEventTypeLocal, ctkEventBus::ctkSignatureTypeCallback, static_cast(observer), signature); \ bool ok = ctkEventBus::ctkEventBusManager::instance()->addEventProperty(*properties);\ if(!ok) {\ qWarning("%s", tr("Some problem occourred during the callback registration with ID '%1'.").arg(topic).toAscii().data());\ if(properties) {delete properties; properties = NULL;} \ }\ } #define ctkRegisterRemoteCallback(topic, sender, signature) \ {\ ctkBusEvent *properties = new ctkBusEvent(topic, ctkEventBus::ctkEventTypeRemote, ctkEventBus::ctkSignatureTypeCallback, static_cast(sender), signature); \ bool ok = ctkEventBus::ctkEventBusManager::instance()->addEventProperty(*properties);\ if(!ok) {\ qWarning("%s", tr("Some problem occourred during the callback registration with ID '%1'.").arg(topic).toAscii().data());\ if(properties) {delete properties; properties = NULL;} \ }\ } namespace ctkEventBus { //forward classes class ctkNetworkConnector; /// Hash table that associate the communication protocol with the corresponding network connector class (Eg. XMLRPC, ctkEventBus::ctkNetworkConnectorQXMLRPC) typedef QHash ctkNetworkConnectorHash; /// typedef that represents dictionary entries ( key , value ) typedef QHash ctkEventHash; ///< Enum that identify the ctkEventType's type: Local or Remote. typedef enum { ctkEventTypeLocal, ctkEventTypeRemote } ctkEventType; ///< Enum that identify the mafSignatureType's type: Signal or Callback. typedef enum { ctkSignatureTypeSignal = 0, ctkSignatureTypeCallback = 1 } ctkSignatureType; /// List of the arguments to be sent through the event bus. typedef QList ctkEventArgumentsList; typedef ctkEventArgumentsList * ctkEventArgumentsListPointer; #define ctkEventArgument(type, data) QArgument(#type, data) #define ctkGenericReturnArgument QGenericReturnArgument #define ctkEventReturnArgument(type, data) QReturnArgument(#type, data) /// Types definitions for events' hash (to be more readable). typedef QHash ctkEventsHashType; /// type definition for observers' properties list to be stored into the event's hash. typedef QList ctkEventItemListType; /// map which represent list of function to be registered in the server, with parameters typedef QMap > mafRegisterMethodsMap; } // namespace ctkEventBus Q_DECLARE_METATYPE(ctkEventBus::ctkEventArgumentsListPointer); Q_DECLARE_METATYPE(ctkEventBus::mafRegisterMethodsMap); #endif // CTKEVENTDEFINITIONS_H