revamped plugin interfaces
authorKevron Rees <kevron_m_rees@linux.intel.com>
Tue, 14 Aug 2012 23:04:26 +0000 (16:04 -0700)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Tue, 14 Aug 2012 23:04:26 +0000 (16:04 -0700)
ambd/core.cpp
ambd/core.h
ambd/pluginloader.cpp
ambd/pluginloader.h
lib/CMakeLists.txt
lib/abstractsink.cpp
lib/abstractsink.h
lib/abstractsource.cpp
lib/abstractsource.h
plugins/exampleplugin.cpp
plugins/exampleplugin.h

index 0935bb3..47f9b79 100644 (file)
 
 using namespace std::placeholders;
 
-Core::Core(SourceList sources, SinkList sinks)
-: mSources(sources), mSinks(sinks)
+Core::Core()
 {
-       ///Hook up signals for each source
        
-       for(SourceList::iterator itr = mSources.begin(); itr!=mSources.end(); itr++)
-       {
-               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::setSupported(PropertyList supported, AbstractSource* source)
+{
+       mSources.push_back(source);
 }
 
 
-void Core::supportedChanged(PropertyList added, PropertyList removed)
+void Core::updateSupported(PropertyList added, PropertyList removed)
 {
        
        /// add the newly supported to master list
@@ -75,7 +58,7 @@ void Core::supportedChanged(PropertyList added, PropertyList removed)
        
        for(SinkList::iterator itr = mSinks.begin(); itr != mSinks.end(); itr++)
        {
-               (*itr)->setSupported(mMasterPropertyList);
+               (*itr)->supportedChanged(mMasterPropertyList);
        }
        
        /// iterate through subscribed properties and resubscribe.  This catches newly supported properties in the process.
@@ -96,7 +79,7 @@ void Core::supportedChanged(PropertyList added, PropertyList removed)
        }
 }
 
-void Core::propertyChanged(VehicleProperty::Property property, boost::any value)
+void Core::updateProperty(VehicleProperty::Property property, boost::any value)
 {
 
 }
@@ -108,7 +91,7 @@ void Core::setProperty(VehicleProperty::Property , boost::any )
 
 void Core::subscribeToProperty(VehicleProperty::Property property, AbstractSink* self)
 {
-       
+       propertySinkMap[property].push_back(self);
 }
 
 void Core::unsubscribeToProperty(VehicleProperty::Property , AbstractSink* self)
index 564e8cb..0ee4cea 100644 (file)
 
 #include "abstractsink.h"
 #include "abstractsource.h"
+#include "abstractroutingengine.h"
 
 #include <unordered_map>
 
-class Core
+class Core: public AbstractRoutingEngine
 {
 
 public:
-    Core(SourceList sources, SinkList sinks);
-    
-    
-private: ///methods
+       Core();
+        
+       /// sources:
 
-       void supportedChanged(PropertyList added, PropertyList removed);
-       void propertyChanged(VehicleProperty::Property property, boost::any value);
+       void setSupported(PropertyList supported, AbstractSource* source);
+       void updateSupported(PropertyList added, PropertyList removed);
+       void updateProperty(VehicleProperty::Property property, boost::any value);
        
-       ///sinks:
+       /// sinks:
        
        void setProperty(VehicleProperty::Property, boost::any);
        void subscribeToProperty(VehicleProperty::Property, AbstractSink* self);
index a905354..a0643bb 100644 (file)
@@ -120,16 +120,6 @@ PluginLoader::PluginLoader(string configFile): f_create(NULL)
        
 }
 
-void PluginLoader::setSinkCreatedCb(SinkSignal cb)
-{
-       sinkCreatedCb = cb;
-}
-
-void PluginLoader::setSinkRemovedCb(SinkSignal cb)
-{
-       sinkRemovedCb = cb;
-}
-
 SinkList PluginLoader::sinks()
 {
        return mSinks;
index 773580e..cbb3971 100644 (file)
@@ -46,8 +46,6 @@ public:
 
        std::string errorString();
         
-       void setSinkCreatedCb(SinkSignal cb);
-       void setSinkRemovedCb(SinkSignal cb);
        
 private: ///methods:
        
@@ -95,9 +93,6 @@ private:
        SourceList mSources;
        SinkList mSinks;
        
-       SinkSignal sinkCreatedCb;
-       SinkSignal sinkRemovedCb;
-       
        create_t * f_create;
 };
 
index 8f0835c..fc2af68 100644 (file)
@@ -1,5 +1,5 @@
 
-set(amb_sources listplusplus.cpp abstractsink.cpp vehicleproperty.cpp abstractsource.cpp debugout.cpp)
+set(amb_sources abstractroutingengine.cpp listplusplus.cpp abstractsink.cpp vehicleproperty.cpp abstractsource.cpp debugout.cpp)
 set(amb_headers_install vehicleproperty.h debugout.h abstractsource.h)
 include_directories( ${include_dirs} )
 add_library(amb SHARED ${amb_sources})
index 3b49710..2629e35 100644 (file)
@@ -24,52 +24,13 @@ AbstractSink::AbstractSink()
 
 }
 
-void AbstractSink::setProperty(VehicleProperty::Property prop, boost::any value)
+void AbstractSink::setRoutingEngine(AbstractRoutingEngine* engine)
 {
-       setPropertyCb(prop, value);
+       routingEngine = engine;
 }
 
-void AbstractSink::setSupported(PropertyList properties)
-{
-       mSupported = properties;
-}
-
-void AbstractSink::subscribeToProperty(VehicleProperty::Property property)
-{
-       subscribeToPropertyCb(property,this);
-}
-
-PropertyList AbstractSink::supported()
-{
-       return mSupported;
-}
-
-void AbstractSink::unsubscribeToProperty(VehicleProperty::Property property)
-{
-       unsubscribeToPropertyCb(property, this);
-}
-
-void AbstractSinkManager::sinkCreated(AbstractSink* sink)
-{
-       sinkCreatedCb(sink);
-}
-
-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)
+void AbstractSinkManager::setRoutingEngine(AbstractRoutingEngine* engine)
 {
-       unsubscribeToPropertyCb = cb;
+       routingEngine = engine;
 }
index 3788891..cabb7b1 100644 (file)
 #include <boost/any.hpp>
 
 #include "vehicleproperty.h"
+#include "abstractroutingengine.h"
 
 using namespace std;
 
 class AbstractSink;
 
-typedef function<void (VehicleProperty::Property, boost::any)> SetPropertySignal;
-typedef function<void (VehicleProperty::Property, AbstractSink*)> SubscriptionSignal;
-
 typedef list<AbstractSink*> SinkList;
-typedef function<void (AbstractSink*)> SinkSignal;
 
 class AbstractSink
 {
 
 public:
        AbstractSink();
-       
-       void setProperty(VehicleProperty::Property, boost::any);
-       void subscribeToProperty(VehicleProperty::Property property);
-       void unsubscribeToProperty(VehicleProperty::Property property);
-       PropertyList supported(); 
-       
-       void setSupported(PropertyList properties);
-       
-       ///callback setters:
-       void setSetPropertyCb(SetPropertySignal cb);
-       void setSubcribeToPropertyCb(SubscriptionSignal cb);
-       void setUnsubscribeToPropertyCb(SubscriptionSignal cb);
-       
+       void setRoutingEngine(AbstractRoutingEngine* engine);
        
        ///Pure virtual methods:
        
-       virtual string name() = 0;
-       virtual void propertyChanged(VehicleProperty::Property property, boost::any value) = 0;
+       virtual string uuid() = 0;
+       virtual void propertyChanged(VehicleProperty::Property property, boost::any value, string  uuid) = 0;
+       virtual void supportedChanged(PropertyList supportedProperties) = 0;
        virtual PropertyList subscriptions() = 0;
        
-       
-private:
-       SetPropertySignal setPropertyCb;
-       SubscriptionSignal subscribeToPropertyCb;
-       SubscriptionSignal unsubscribeToPropertyCb;
-       
-       PropertyList mSupported;
+protected:
+       AbstractRoutingEngine* routingEngine;
 };
 
 class AbstractSinkManager
 {
 public:
-       virtual SinkList sinks() = 0;
        
-       void sinkCreated(AbstractSink*);
-       void sinkRemoved(AbstractSink*);
+       virtual SinkList sinks() = 0;
+       void setRoutingEngine(AbstractRoutingEngine* engine);
        
-private:
-       SinkSignal sinkCreatedCb;
-       SinkSignal sinkRemovedCb;
+protected:
+       AbstractRoutingEngine* routingEngine;
 };
 
 #endif // ABSTRACTSINK_H
index 2f70f11..ae2f25c 100644 (file)
 #include "abstractsource.h"
 
 AbstractSource::AbstractSource()
+: routingEngine(nullptr)
 {
 
 }
 
-void AbstractSource::propertyChanged(VehicleProperty::Property property, boost::any value)
+void AbstractSource::setRoutingEngine(AbstractRoutingEngine* engine)
 {
-       mPropertyChangedCb(property, value);
+       routingEngine = engine;
 }
 
-void AbstractSource::supportedChanged(PropertyList addedList, PropertyList removed)
-{
-       mSupportedChangedCb(addedList, removed);
-}
-
-
-void AbstractSource::setPropertyChangedCb(PropertyChangedSignal propertyChangedCb)
-{
-       mPropertyChangedCb = propertyChangedCb;
-}
-
-void AbstractSource::setSupportedChangedCb(SupportedChangedSignal supportedChangedCb)
-{
-       mSupportedChangedCb = supportedChangedCb;
-}
 
 
index 998a314..f4e37d2 100644 (file)
 
 #include <string>
 #include <list>
-#include <functional>
 #include <boost/any.hpp>
+
 #include "vehicleproperty.h"
+#include "abstractroutingengine.h"
 
 using namespace std;
 
 class AbstractSource;
 
-typedef function<void (VehicleProperty::Property, boost::any)> PropertyChangedSignal;
-
-/// [void](PropertyList added, PropertyList removed) { }
-
-typedef function<void (PropertyList, PropertyList)> SupportedChangedSignal;
-
 typedef list<AbstractSource*> SourceList;
 
 class AbstractSource
@@ -43,26 +38,20 @@ class AbstractSource
 
 public:
        AbstractSource();
-
-       void propertyChanged(VehicleProperty::Property property, boost::any value);
-       void supportedChanged(PropertyList added, PropertyList removed);
-
-       void setPropertyChangedCb(PropertyChangedSignal propertyChangedCb);
-       void setSupportedChangedCb(SupportedChangedSignal supportedChangedCb);
+       void setRoutingEngine(AbstractRoutingEngine* engine);
        
        ///pure virtual methods:
 
-       virtual string name() = 0;
+       virtual string uuid() = 0;
        virtual void setProperty(VehicleProperty::Property property, boost::any value) = 0;
        virtual void subscribeToPropertyChanges(VehicleProperty::Property property) = 0;
        virtual void unsubscribeToPropertyChanges(VehicleProperty::Property property) = 0;
        virtual PropertyList supported() = 0;
        
 
-private:
-       PropertyChangedSignal mPropertyChangedCb;
-       SupportedChangedSignal mSupportedChangedCb;
-    
+protected:
+       AbstractRoutingEngine* routingEngine;
+           
 };
 
 #endif // ABSTRACTSOURCE_H
index c80e8a3..5e02d67 100644 (file)
@@ -35,9 +35,9 @@ extern "C" AbstractSource * create()
        return new ExampleSourcePlugin();
 }
 
-string ExampleSourcePlugin::name()
+string ExampleSourcePlugin::uuid()
 {
-       return "example source plugin";
+       return "6dd4268a-c605-4a06-9034-59c1e8344c8e";
 }
 
 void ExampleSourcePlugin::setProperty(VehicleProperty::Property , boost::any )
index c267820..3371c8f 100644 (file)
@@ -29,7 +29,7 @@ class ExampleSourcePlugin: public AbstractSource
 
 public:
        ExampleSourcePlugin();
-       string name();
+       string uuid();
        void setProperty(VehicleProperty::Property, boost::any);
        void subscribeToPropertyChanges(VehicleProperty::Property property);
        void unsubscribeToPropertyChanges(VehicleProperty::Property property);