SignalDeclaration.h

Go to the documentation of this file.
00001 #ifndef __SIGNALDECLARATION_H__
00002 #define __SIGNALDECLARATION_H__
00003 
00004 /*
00005 
00006 $Header$
00007 
00008 */
00009 
00010 #include "SignalBase.h"
00011 #include "Slot.h"
00012 
00013 // Messages.
00014 static const char *const MSG_SIGNAL_SLOT_ALREADY_EXISTS  = "Slot for this signal and this object (class = %s, id = %llu) already exists.";
00015 static const char *const MSG_SIGNAL_SLOT_DOES_NOT_EXISTS = "Slot for this signal and this object (class = %s, id = %llu) does not exist.";
00016 
00017 using namespace std;
00018 
00019 // Declaration.
00020 
00021 template<class M>
00022 class Signal : public SignalBase
00023 {
00024 
00025   PYLON_OBJECT
00026 
00027 public:
00028 
00029   Signal(const String &className, const String &signalName);
00030   virtual ~Signal();
00031 
00032   int connect(const Object *slotObject, const M slotMethod);
00033   virtual int disconnect(const Object *slotObject);
00034   int disconnect(const Object *slotObject, const M slotMethod);
00035 };
00036 
00037 #define SIGNAL(name, ...) \
00038 typedef int (Object::*Signal_##name##_SlotMethod)(__VA_ARGS__); \
00039 static String signal_##name##_ownerClassName() \
00040 { \
00041   return CLASS_NAME(); \
00042 } \
00043 class Signal_##name : public Signal<Signal_##name##_SlotMethod> \
00044 { \
00045   PYLON_OBJECT \
00046 public: \
00047   Signal_##name() : Signal<Signal_##name##_SlotMethod>(signal_##name##_ownerClassName(), #name) {} \
00048 }; \
00049 Signal_##name _signal_##name;
00050 
00051 #define EMIT(signalName, ...) \
00052 { \
00053   if (!suspended()) \
00054     if (_signal_##signalName._orphanSlotObject) { \
00055       if (!_signal_##signalName._orphanSlotObject->suspended()) { \
00056         ((Object *)(_signal_##signalName._orphanSlotObject))->profBegin(); \
00057         ((Object *)(_signal_##signalName._orphanSlotObject)->*(Signal_##signalName##_SlotMethod)(_signal_##signalName._orphanSlotMethod))(__VA_ARGS__); \
00058         ((Object *)(_signal_##signalName._orphanSlotObject))->profEnd(); \
00059       } \
00060     } else { \
00061         Object *slotObject; \
00062         Signal_##signalName##_SlotMethod slotMethod; \
00063         SlotMap::const_iterator i = _signal_##signalName._slots.begin(); \
00064         SlotMap::const_iterator ie = _signal_##signalName._slots.end(); \
00065         while (i != ie) { \
00066           slotObject = (Object *)(i->first); \
00067           if (!slotObject->suspended()) { \
00068             SlotList::const_iterator j = i->second.begin(); \
00069             SlotList::const_iterator je = i->second.end(); \
00070             while (j != je) { \
00071               slotMethod = (Signal_##signalName##_SlotMethod)(*j); \
00072               slotObject->profBegin(); \
00073               (slotObject->*slotMethod)(__VA_ARGS__); \
00074               slotObject->profEnd(); \
00075               ++j; \
00076             } \
00077           } \
00078           ++i; \
00079         } \
00080       } \
00081 }
00082 
00083 #define CONNECT(signalObjectPtr, signalName, slotObjectPtr, slotClassName, slotMethodName) \
00084   ((signalObjectPtr)->_signal_##signalName.connect(slotObjectPtr, static_cast<SlotMethod_##slotMethodName>(&slotClassName::slotMethodName)))
00085 
00086 #endif

Generated on Thu Sep 6 20:11:25 2007 for Pylon Application Platform by  doxygen 1.5.1