Revision: 40765
          http://brlcad.svn.sourceforge.net/brlcad/?rev=40765&view=rev
Author:   davidloman
Date:     2010-09-28 19:46:41 +0000 (Tue, 28 Sep 2010)

Log Message:
-----------
Implement registration of NetMsg types with respective NetMsgHandlers.  
Implement routing of NetMsgs

Modified Paths:
--------------
    rt^3/trunk/include/NetMsgRouter.h
    rt^3/trunk/src/libNet/NetMsgRouter.cxx

Modified: rt^3/trunk/include/NetMsgRouter.h
===================================================================
--- rt^3/trunk/include/NetMsgRouter.h   2010-09-28 19:27:29 UTC (rev 40764)
+++ rt^3/trunk/include/NetMsgRouter.h   2010-09-28 19:46:41 UTC (rev 40765)
@@ -33,6 +33,7 @@
 
 #include <QtCore/QMap>
 #include <QtCore/QList>
+#include <QtCore/QMutex>
 
 class NetMsgRouter {
 public:
@@ -46,8 +47,17 @@
        static NetMsgRouter* pInstance;
        NetMsgRouter();
 
+       /*
+        * Gets a list of INetMsgHandler pointers associated with
+        * this msgType.  If no Mapping or list exists, one is made.
+        */
+       QList<INetMsgHandler*>* getListOfHandlers(quint16 type);
+
+
+       QMutex mapLock;
        QMap<quint16,QList<INetMsgHandler*>*>* routingTable;
 
+
 };
 
 #endif /* __NETMSGROUTER_H__ */

Modified: rt^3/trunk/src/libNet/NetMsgRouter.cxx
===================================================================
--- rt^3/trunk/src/libNet/NetMsgRouter.cxx      2010-09-28 19:27:29 UTC (rev 
40764)
+++ rt^3/trunk/src/libNet/NetMsgRouter.cxx      2010-09-28 19:46:41 UTC (rev 
40765)
@@ -24,6 +24,7 @@
  */
 
 #include "NetMsgRouter.h"
+#include <QtCore/QMutexLocker>
 
 NetMsgRouter* NetMsgRouter::pInstance = NULL;
 
@@ -36,23 +37,44 @@
 }
 
 NetMsgRouter::NetMsgRouter() {
-       this->routingTable = new QMap<quint16,QList<INetMsgHandler*>*>();
+       this->routingTable = new QMap<quint16, QList<INetMsgHandler*>*> ();
 }
 
 NetMsgRouter::~NetMsgRouter() {
        delete routingTable;
 }
 
+bool NetMsgRouter::registerType(quint16 type, INetMsgHandler* handler) {
+       //First get the appropriate list:
+       QList<INetMsgHandler*>* list = this->getListOfHandlers(type);
+       list->append(handler);
 
-bool
-NetMsgRouter::registerType(quint16 type, INetMsgHandler* handler) {
+       return true;
+}
 
+bool NetMsgRouter::routeMsg(NetMsg* msg) {
+       //First get the appropriate list:
+       QList<INetMsgHandler*>* list = 
this->getListOfHandlers(msg->getMsgType());
 
+       for (int i = 0; i < list->length(); ++i) {
+               list->at(i)->handleNetMsg(msg);
+       }
+
+       //Now delete msg
+       delete msg;
 }
 
-bool
-NetMsgRouter::routeMsg(NetMsg* msg) {
+QList<INetMsgHandler*>*
+NetMsgRouter::getListOfHandlers(quint16 type) {
+       QMutexLocker(&this->mapLock);
 
+       QList<INetMsgHandler*>* l = this->routingTable->value(type);
+
+       if (l == 0) {
+               l = new QList<INetMsgHandler*> ();
+               this->routingTable->insert(type, l);
+       }
+       return l;
 }
 
 // Local Variables:


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to