ctkEventHandlerWrapper_p.h

Go to the documentation of this file.
00001 #ifndef CTKEVENTHANDLERWRAPPER_P_H
00002 #define CTKEVENTHANDLERWRAPPER_P_H
00003 
00004 #include <QStringList>
00005 
00006 #include <EventBus/ctkEventBus.h>
00007 #include <EventBus/ctkEventConstants.h>
00008 #include <ctkLDAPSearchFilter.h>
00009 
00010 #include <iostream>
00011 
00012 class ctkEventHandlerWrapper : public QObject {
00013 
00014   Q_OBJECT
00015 
00016 private:
00017 
00018   ctkEventBus::Properties properties;
00019   QStringList topicList;
00020   ctkLDAPSearchFilter filter;
00021 
00022 public:
00023 
00024   ctkEventHandlerWrapper(const QObject* subscriber, const char* handler, const ctkEventBus::Properties& properties)
00025     : properties(properties)
00026   {
00027     connect(this, SIGNAL(notifySubscriber(Event)), subscriber, handler);
00028   }
00029 
00030   QStringList topics() const
00031   {
00032     return topicList;
00033   }
00034 
00035   bool init()
00036   {
00037     topicList.clear();
00038 
00039     // Get topic names
00040     QVariant v = properties[EventConstants::EVENT_TOPIC];
00041     topicList = v.toStringList();
00042 
00043     if (topicList.empty())
00044     {
00045       return false;
00046     }
00047 
00048     v = properties[EventConstants::EVENT_FILTER];
00049     filter = ctkLDAPSearchFilter(v.toString());
00050   }
00051 
00052   void handleEvent(const ctkEvent& event /*, const Permission& perm */)
00053   {
00054     if (!event.matches(filter)) return;
00055 
00056     // should do permissions checks now somehow
00057     // ...
00058 
00059     try {
00060       emit notifySubscriber(event);
00061     }
00062     catch (const std::exception& e)
00063     {
00064       // TODO logging
00065       std::cerr << "Exception occured during publishing " << qPrintable(event.topic()) << ": " << e.what() << std::endl;
00066     }
00067 
00068   }
00069 
00070 signals:
00071 
00072   void notifySubscriber(const ctkEvent&);
00073 
00074 };
00075 
00076 #endif // CTKEVENTHANDLERWRAPPER_P_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated on 21 May 2010 for CTK by  doxygen 1.6.1