Index: linknx/src/xmlserver.h =================================================================== RCS file: /cvsroot/linknx/linknx/linknx/src/xmlserver.h,v retrieving revision 1.2 diff -u -r1.2 xmlserver.h --- linknx/src/xmlserver.h 31 Jan 2008 01:26:39 -0000 1.2 +++ linknx/src/xmlserver.h 4 May 2009 23:32:37 -0000 @@ -28,6 +28,7 @@ #include #include #include "ticpp.h" +#include "objectcontroller.h" class ClientConnection; @@ -72,7 +73,7 @@ std::string path_m; }; -class ClientConnection : public Thread +class ClientConnection : public Thread, public ChangeListener { public: ClientConnection (XmlServer *server, int fd); @@ -85,11 +86,16 @@ int sendmessage (std::string msg, pth_event_t stop); int sendreject (const char* msgstr, const std::string& type, pth_event_t stop); + virtual void onChange(Object* object); + std::string msg_m; private: int fd_m; XmlServer *server_m; + typedef std::list NotifyList_t; + NotifyList_t notifyList_m; + void Run (pth_sem_t * stop); }; Index: linknx/src/xmlserver.cpp =================================================================== RCS file: /cvsroot/linknx/linknx/linknx/src/xmlserver.cpp,v retrieving revision 1.7 diff -u -r1.7 xmlserver.cpp --- linknx/src/xmlserver.cpp 23 Mar 2009 00:06:26 -0000 1.7 +++ linknx/src/xmlserver.cpp 4 May 2009 23:32:37 -0000 @@ -162,6 +162,12 @@ ClientConnection::~ClientConnection () { + NotifyList_t::iterator it; + for (it = notifyList_m.begin(); it != notifyList_m.end(); it++) + { + (*it)->removeChangeListener(this); + } + notifyList_m.clear(); if (server_m) server_m->deregister (this); close (fd_m); @@ -341,6 +347,29 @@ throw "Error writing config to file"; } } + else if (pAdmin->Value() == "notification") + { + ticpp::Iterator< ticpp::Element > pObjects; + for ( pObjects = pAdmin->FirstChildElement(); pObjects != pObjects.end(); pObjects++ ) + { + if (pObjects->Value() == "register") + { + std::string id = pObjects->GetAttribute("id"); + Object* obj = ObjectController::instance()->getObject(id); + notifyList_m.push_back(obj); + obj->addChangeListener(this); + } + else if (pObjects->Value() == "unregister") + { + std::string id = pObjects->GetAttribute("id"); + Object* obj = ObjectController::instance()->getObject(id); + notifyList_m.remove(obj); + obj->removeChangeListener(this); + } + else + throw "Unknown objects element"; + } + } else throw "Unknown admin element"; } @@ -414,3 +443,12 @@ return -1; } + +void ClientConnection::onChange(Object* object) +{ +// sendmessage ("\n", stop); + std::stringstream msg; + msg << "" << object->getValue() << "" << std::endl; + sendmessage (msg.str(), NULL); +} +