more progress on core
authorKevron Rees <kevron_m_rees@linux.intel.com>
Mon, 13 Aug 2012 23:49:03 +0000 (16:49 -0700)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Mon, 13 Aug 2012 23:49:03 +0000 (16:49 -0700)
ambd/core.cpp
ambd/core.h
lib/abstractsink.cpp
lib/abstractsink.h
lib/listplusplus.h

index c94eed3..0935bb3 100644 (file)
@@ -30,31 +30,70 @@ Core::Core(SourceList sources, SinkList sinks)
        
        for(SourceList::iterator itr = mSources.begin(); itr!=mSources.end(); itr++)
        {
-               auto supportedChangedCb = std::bind(&Core::supportedChanged,this, _1, _2);
+               auto supportedChangedCb = std::bind(&Core::supportedChanged, this, _1, _2);
                (*itr)->setSupportedChangedCb(supportedChangedCb);
                
                auto propChangedDb = std::bind(&Core::propertyChanged, this, _1, _2);
                (*itr)->setPropertyChangedCb(propChangedDb);
        }
+       
+       for(SinkList::iterator itr = mSinks.begin(); itr != mSinks.end(); itr++)
+       {
+               auto setPropertyCb = std::bind(&Core::setProperty, this, _1, _2);
+               (*itr)->setSetPropertyCb(setPropertyCb);
+               
+               auto subscribeToPropertyCb = std::bind(&Core::subscribeToProperty, this, _1, _2);
+               (*itr)->setSubcribeToPropertyCb(subscribeToPropertyCb);
+               
+               auto unsubscribeToPropertyCb = std::bind(&Core::unsubscribeToProperty, this, _1, _2);
+               (*itr)->setUnsubscribeToPropertyCb(unsubscribeToPropertyCb);
+       }
 }
 
 
 void Core::supportedChanged(PropertyList added, PropertyList removed)
 {
        
+       /// add the newly supported to master list
+       
        for(PropertyList::iterator itr = added.begin(); itr != added.end(); itr++)
        {
-               if(ListPlusPlus<VehicleProperty::Property>(added).contains(*itr))
+               if(ListPlusPlus<VehicleProperty::Property>(&added).contains(*itr))
                {
                        mMasterPropertyList.push_back(*itr);
                }
        }
        
+       /// removed no longer supported properties from master list.
+       
        for(PropertyList::iterator itr = removed.begin(); itr != removed.end(); itr++)
        {
-               ListPlusPlus<VehicleProperty::Property>(removed).removeOne(*itr);
+               ListPlusPlus<VehicleProperty::Property>(&mMasterPropertyList).removeOne(*itr);
        }
        
+       /// tell all new sinks about the newly supported properties.
+       
+       for(SinkList::iterator itr = mSinks.begin(); itr != mSinks.end(); itr++)
+       {
+               (*itr)->setSupported(mMasterPropertyList);
+       }
+       
+       /// iterate through subscribed properties and resubscribe.  This catches newly supported properties in the process.
+       
+       for(unordered_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);
+                       }
+               }
+       }
 }
 
 void Core::propertyChanged(VehicleProperty::Property property, boost::any value)
@@ -62,3 +101,19 @@ void Core::propertyChanged(VehicleProperty::Property property, boost::any value)
 
 }
 
+void Core::setProperty(VehicleProperty::Property , boost::any )
+{
+
+}
+
+void Core::subscribeToProperty(VehicleProperty::Property property, AbstractSink* self)
+{
+       
+}
+
+void Core::unsubscribeToProperty(VehicleProperty::Property , AbstractSink* self)
+{
+
+}
+
+
index 57fecfc..564e8cb 100644 (file)
@@ -23,6 +23,8 @@
 #include "abstractsink.h"
 #include "abstractsource.h"
 
+#include <unordered_map>
+
 class Core
 {
 
@@ -33,14 +35,21 @@ public:
 private: ///methods
 
        void supportedChanged(PropertyList added, PropertyList removed);
-       
        void propertyChanged(VehicleProperty::Property property, boost::any value);
+       
+       ///sinks:
+       
+       void setProperty(VehicleProperty::Property, boost::any);
+       void subscribeToProperty(VehicleProperty::Property, AbstractSink* self);
+       void unsubscribeToProperty(VehicleProperty::Property, AbstractSink* self);
     
 private:
        PropertyList mMasterPropertyList;
        
        SourceList mSources;
        SinkList mSinks;
+       
+       unordered_map<VehicleProperty::Property, SinkList> propertySinkMap;
     
 };
 
index 0eeb27a..3b49710 100644 (file)
@@ -36,7 +36,7 @@ void AbstractSink::setSupported(PropertyList properties)
 
 void AbstractSink::subscribeToProperty(VehicleProperty::Property property)
 {
-       subscribeToPropertyCb(property);
+       subscribeToPropertyCb(property,this);
 }
 
 PropertyList AbstractSink::supported()
@@ -46,7 +46,7 @@ PropertyList AbstractSink::supported()
 
 void AbstractSink::unsubscribeToProperty(VehicleProperty::Property property)
 {
-       unsubscribeToPropertyCb(property);
+       unsubscribeToPropertyCb(property, this);
 }
 
 void AbstractSinkManager::sinkCreated(AbstractSink* sink)
@@ -58,3 +58,18 @@ void AbstractSinkManager::sinkRemoved(AbstractSink* sink)
 {
        sinkRemovedCb(sink);
 }
+
+void AbstractSink::setSetPropertyCb(SetPropertySignal cb)
+{
+       setPropertyCb = cb;
+}
+
+void AbstractSink::setSubcribeToPropertyCb(SubscriptionSignal cb)
+{
+       subscribeToPropertyCb = cb;
+}
+
+void AbstractSink::setUnsubscribeToPropertyCb(SubscriptionSignal cb)
+{
+       unsubscribeToPropertyCb = cb;
+}
index 1ef2ad9..3788891 100644 (file)
@@ -32,7 +32,7 @@ using namespace std;
 class AbstractSink;
 
 typedef function<void (VehicleProperty::Property, boost::any)> SetPropertySignal;
-typedef function<void (VehicleProperty::Property)> SubscriptionSignal;
+typedef function<void (VehicleProperty::Property, AbstractSink*)> SubscriptionSignal;
 
 typedef list<AbstractSink*> SinkList;
 typedef function<void (AbstractSink*)> SinkSignal;
index 04d3655..2821b08 100644 (file)
@@ -28,7 +28,7 @@ class ListPlusPlus
 {
 public:
        
-       ListPlusPlus(std::list<T> list)
+       ListPlusPlus(std::list<T> *list)
        :mList(list)
        {
                
@@ -37,22 +37,22 @@ public:
        
        void removeOne(T value)
        {
-               typename std::list<T>::iterator itr = std::find<T>(mList.begin(), mList.end(), value);
+               typename std::list<T>::iterator itr = std::find(mList->begin(), mList->end(), value);
                
-               if (itr != mList.end())
+               if (itr != mList->end())
                {
-                       mList.erase(itr);
+                       mList->erase(itr);
                }
        }
        
        
        bool contains(T value)
        {
-               return (std::find<T>(mList.begin(), mList.end(), value) != mList.end());
+               return (std::find(mList->begin(), mList->end(), value) != mList->end());
        }
        
 private:
-       std::list<T> mList;
+       std::list<T> *mList;
 };
 
 #endif // LISTPLUSPLUS_H