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
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.
}
}
-void Core::propertyChanged(VehicleProperty::Property property, boost::any value)
+void Core::updateProperty(VehicleProperty::Property property, boost::any value)
{
}
void Core::subscribeToProperty(VehicleProperty::Property property, AbstractSink* self)
{
-
+ propertySinkMap[property].push_back(self);
}
void Core::unsubscribeToProperty(VehicleProperty::Property , AbstractSink* self)
#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);
}
-void PluginLoader::setSinkCreatedCb(SinkSignal cb)
-{
- sinkCreatedCb = cb;
-}
-
-void PluginLoader::setSinkRemovedCb(SinkSignal cb)
-{
- sinkRemovedCb = cb;
-}
-
SinkList PluginLoader::sinks()
{
return mSinks;
std::string errorString();
- void setSinkCreatedCb(SinkSignal cb);
- void setSinkRemovedCb(SinkSignal cb);
private: ///methods:
SourceList mSources;
SinkList mSinks;
- SinkSignal sinkCreatedCb;
- SinkSignal sinkRemovedCb;
-
create_t * f_create;
};
-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})
}
-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;
}
#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
#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;
-}
#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
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
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 )
public:
ExampleSourcePlugin();
- string name();
+ string uuid();
void setProperty(VehicleProperty::Property, boost::any);
void subscribeToPropertyChanges(VehicleProperty::Property property);
void unsubscribeToPropertyChanges(VehicleProperty::Property property);