sinks auto-register with the routing engine
authorKevron Rees <tripzero.kev@gmail.com>
Tue, 28 Aug 2012 17:28:32 +0000 (10:28 -0700)
committerKevron Rees <tripzero.kev@gmail.com>
Tue, 28 Aug 2012 17:28:32 +0000 (10:28 -0700)
ambd/core.cpp
ambd/core.h
lib/abstractroutingengine.h
lib/abstractsink.cpp

index 34ed1af..24fd079 100644 (file)
@@ -37,7 +37,9 @@ Core::~Core()
 
 void Core::setSupported(PropertyList supported, AbstractSource* source)
 {
-       mSources.push_back(source);
+
+       if(!ListPlusPlus<AbstractSource*>(&mSources).contains(source))
+               mSources.push_back(source);
                
        for(PropertyList::iterator itr = supported.begin(); itr != supported.end(); itr++)
        {
@@ -47,6 +49,30 @@ void Core::setSupported(PropertyList supported, AbstractSource* source)
                        mMasterPropertyList.push_back((*itr));
                }
        }
+
+       /// tell all new sinks about the newly supported properties.
+
+       for(SinkList::iterator itr = mSinks.begin(); itr != mSinks.end(); itr++)
+       {
+               (*itr)->supportedChanged(mMasterPropertyList);
+       }
+
+       /// iterate through subscribed properties and resubscribe.  This catches newly supported properties in the process.
+
+       for(map<VehicleProperty::Property, SinkList>::iterator itr = propertySinkMap.begin(); itr != propertySinkMap.end(); itr++)
+       {
+               VehicleProperty::Property  property = (*itr).first;
+
+               for(SourceList::iterator source = mSources.begin(); source != mSources.end(); source++)
+               {
+                       PropertyList properties = (*source)->supported();
+
+                       if(ListPlusPlus<VehicleProperty::Property>(&properties).contains(property))
+                       {
+                               (*source)->subscribeToPropertyChanges(property);
+                       }
+               }
+       }
 }
 
 
@@ -107,19 +133,23 @@ void Core::updateProperty(VehicleProperty::Property property, boost::any value)
        }
 }
 
-boost::any Core::getProperty(VehicleProperty::Property property)
+void Core::registerSink(AbstractSink *self)
 {
-       for(SourceList::iterator itr = mSources.begin(); itr != mSources.end(); itr++)
+       if(!ListPlusPlus<AbstractSink*>(&mSinks).contains(self))
        {
-               AbstractSource* src = (*itr);
-               PropertyList properties = src->supported();
-               if(ListPlusPlus<VehicleProperty::Property>(&properties).contains(property))
-               {
-                       return src->getProperty(property);
-               }
+               mSinks.push_back(self);
        }
 }
 
+void Core::unregisterSink(AbstractSink *self)
+{
+       if(ListPlusPlus<AbstractSink*>(&mSinks).contains(self))
+       {
+               ListPlusPlus<AbstractSink*>(&mSinks).removeOne(self);
+       }
+}
+
+
 AsyncPropertyReply *Core::getPropertyAsync(AsyncPropertyRequest request)
 {
        AsyncPropertyReply * reply = new AsyncPropertyReply(request);
index f8ac47c..6c8dff5 100644 (file)
@@ -40,7 +40,8 @@ public:
        
        /// sinks:
        
-       boost::any getProperty(VehicleProperty::Property);
+       void registerSink(AbstractSink *self);
+       void unregisterSink(AbstractSink *self);
        AsyncPropertyReply* getPropertyAsync(AsyncPropertyRequest request);
        void setProperty(VehicleProperty::Property, boost::any);
        void subscribeToProperty(VehicleProperty::Property, AbstractSink* self);
index a841d6d..424c4d8 100644 (file)
@@ -58,8 +58,8 @@ public:
        virtual void updateProperty(VehicleProperty::Property property, boost::any value) = 0;
        
        /// sinks:
-
-       virtual boost::any getProperty(VehicleProperty::Property) = 0;
+       virtual void registerSink(AbstractSink* self) = 0;
+       virtual void  unregisterSink(AbstractSink* self) = 0;
        virtual AsyncPropertyReply *getPropertyAsync(AsyncPropertyRequest request) = 0;
        virtual void setProperty(VehicleProperty::Property, boost::any) = 0;
        virtual void subscribeToProperty(VehicleProperty::Property, AbstractSink* self) = 0;
index a52616b..d389404 100644 (file)
 AbstractSink::AbstractSink(AbstractRoutingEngine* engine)
 :routingEngine(engine)
 {
-
+       routingEngine->registerSink(this);
 }
 
 AbstractSink::~AbstractSink()
 {
-
+       routingEngine->unregisterSink(this);
 }
 
 AbstractSinkManager::AbstractSinkManager(AbstractRoutingEngine* engine)