void Core::setSupported(PropertyList supported, AbstractSource* source)
{
mSources.push_back(source);
+
+ for(PropertyList::iterator itr = supported.begin(); itr != supported.end(); itr++)
+ {
+ if(!ListPlusPlus<VehicleProperty::Property>(&mMasterPropertyList).contains((*itr)))
+ {
+ DebugOut()<<__FUNCTION__<<"() adding suport for property "<<VehicleProperty::name((*itr))<<endl;
+ mMasterPropertyList.push_back((*itr));
+ }
+ }
}
void Core::updateProperty(VehicleProperty::Property property, boost::any value)
{
-
+ SinkList list = propertySinkMap[property];
+
+ DebugOut()<<__FUNCTION__<<"() there are "<<list.size()<<" sinks connected to property: "<<VehicleProperty::name(property)<<endl;
+
+ for(SinkList::iterator itr = list.begin(); itr != list.end(); itr++)
+ {
+ (*itr)->propertyChanged(property, value,(*itr)->uuid());
+ }
}
-void Core::setProperty(VehicleProperty::Property , boost::any )
+void Core::setProperty(VehicleProperty::Property property, boost::any value)
{
-
+ for(SourceList::iterator itr = mSources.begin(); itr != mSources.end(); itr++)
+ {
+ AbstractSource* src = (*itr);
+ PropertyList properties = src->supported();
+ if(ListPlusPlus<VehicleProperty::Property>(&properties).contains(property))
+ {
+ src->setProperty(property, value);
+ }
+ }
}
void Core::subscribeToProperty(VehicleProperty::Property property, AbstractSink* self)
{
- if(propertySinkMap.find(property) == propertySinkMap.end())
+ if(!ListPlusPlus<VehicleProperty::Property>(&mMasterPropertyList).contains((property)))
{
- DebugOut()<<__FUNCTION__<<"property not supported: "<<VehicleProperty::name(property);
+ DebugOut()<<__FUNCTION__<<"(): property not supported: "<<VehicleProperty::name(property)<<endl;
return;
}
+ if(propertySinkMap.find(property) == propertySinkMap.end())
+ {
+ propertySinkMap[property] = SinkList();
+ }
+
SinkList list = propertySinkMap[property];
if(!ListPlusPlus<AbstractSink*>(&list).contains(self))
{
- list.push_back(self);
+ propertySinkMap[property].push_back(self);
}
-
}
-void Core::unsubscribeToProperty(VehicleProperty::Property , AbstractSink* self)
+void Core::unsubscribeToProperty(VehicleProperty::Property property, AbstractSink* self)
{
-
+ if(propertySinkMap.find(property) == propertySinkMap.end())
+ {
+ DebugOut()<<__FUNCTION__<<"property not supported: "<<VehicleProperty::name(property);
+ return;
+ }
+
+ SinkList list = propertySinkMap[property];
+
+ ListPlusPlus<AbstractSink*>(&list).removeOne(self);
+
+ for(SourceList::iterator itr = mSources.begin(); itr != mSources.end(); itr++)
+ {
+ AbstractSource* src = (*itr);
+ PropertyList properties = src->supported();
+
+ if(ListPlusPlus<VehicleProperty::Property>(&properties).contains(property))
+ {
+ src->unsubscribeToPropertyChanges(property);
+ }
+ }
}
#endif
#include "pluginloader.h"
-#include "abstractsource.h"
+#include "core.h"
using namespace std;
g_type_init();
- PluginLoader loader(config);
+ PluginLoader loader(config, new Core());
if(!loader.sources().size())
{
}
+
#ifdef USE_QT_CORE
app.exec();
*
**********************************************/
-PluginLoader::PluginLoader(string configFile): f_create(NULL)
+PluginLoader::PluginLoader(string configFile, AbstractRoutingEngine* re): f_create(NULL), routingEngine(re)
{
DebugOut()<<"Loading config file: "<<configFile<<endl;
json_reader_read_element(reader,i);
string path = json_reader_get_string_value(reader);
- AbstractSink* plugin = loadPlugin<AbstractSink*>(path);
+ AbstractSinkManager* plugin = loadPlugin<AbstractSinkManager*>(path);
- if(plugin != nullptr)
- mSinks.push_back(plugin);
+ if(plugin == nullptr)
+ {
+ throw std::runtime_error("plugin is not a SinkManager");
+ }
json_reader_end_element(reader);
+
}
json_reader_end_member(reader);
///TODO: this will probably explode:
- g_error_free(error);
+ if(error) g_error_free(error);
+
g_object_unref(reader);
g_object_unref(parser);
#include "abstractsource.h"
#include "abstractsink.h"
+#include "abstractroutingengine.h"
#include "debugout.h"
using namespace std;
-typedef void* create_t();
+typedef void* create_t(AbstractRoutingEngine*);
class PluginLoader
{
public:
- PluginLoader(string configFile);
+ PluginLoader(string configFile, AbstractRoutingEngine* routingEngine);
SourceList sources();
SinkList sinks();
if(f_create)
{
- void* obj = f_create();
+ void* obj = f_create(routingEngine);
return static_cast<T>( obj );
}
std::string mPluginPath;
std::string mErrorString;
+ AbstractRoutingEngine* routingEngine;
+
SourceList mSources;
SinkList mSinks;
{
- "sources" : [ "../plugins/exampleplugin.so" ]
+ "sources" : [ "../plugins/examplesourceplugin.so" ],
+ "sinks": [ "../plugins/examplesinkplugin.so" ]
}
#include "abstractsink.h"
#include "abstractroutingengine.h"
-AbstractSink::AbstractSink()
+AbstractSink::AbstractSink(AbstractRoutingEngine* engine)
+:routingEngine(engine)
{
}
-void AbstractSink::setRoutingEngine(AbstractRoutingEngine* engine)
+AbstractSink::~AbstractSink()
{
- routingEngine = engine;
-}
+}
-void AbstractSinkManager::setRoutingEngine(AbstractRoutingEngine* engine)
+AbstractSinkManager::AbstractSinkManager(AbstractRoutingEngine* engine)
+:routingEngine(engine)
{
- routingEngine = engine;
+
}
+
+
{
public:
- AbstractSink();
- void setRoutingEngine(AbstractRoutingEngine* engine);
+ AbstractSink(AbstractRoutingEngine* engine);
+ virtual ~AbstractSink();
///Pure virtual methods:
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;
protected:
AbstractRoutingEngine* routingEngine;
{
public:
- virtual SinkList sinks() = 0;
- void setRoutingEngine(AbstractRoutingEngine* engine);
+ AbstractSinkManager(AbstractRoutingEngine* engine);
protected:
AbstractRoutingEngine* routingEngine;
#include "abstractsource.h"
-AbstractSource::AbstractSource()
-: routingEngine(nullptr)
+AbstractSource::AbstractSource(AbstractRoutingEngine* engine)
+: AbstractSink(engine), routingEngine(engine)
{
-
+
}
-void AbstractSource::setRoutingEngine(AbstractRoutingEngine* engine)
+AbstractSource::~AbstractSource()
{
- routingEngine = engine;
+
}
#include <list>
#include <boost/any.hpp>
+#include "abstractsink.h"
#include "vehicleproperty.h"
#include "abstractroutingengine.h"
typedef list<AbstractSource*> SourceList;
-class AbstractSource
+class AbstractSource: public AbstractSink
{
public:
- AbstractSource();
- void setRoutingEngine(AbstractRoutingEngine* engine);
+ AbstractSource(AbstractRoutingEngine* engine);
+ virtual ~AbstractSource();
///pure virtual methods:
- 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;
protected:
AbstractRoutingEngine* routingEngine;
-
+
+private:
+ AbstractSource():AbstractSink(nullptr) { }
};
#endif // ABSTRACTSOURCE_H
include_directories(${CMAKE_SOURCE_DIR}/lib ${include_dirs})
-set(exampleplugin_headers exampleplugin.h)
-set(exampleplugin_sources exampleplugin.cpp)
-add_library(exampleplugin MODULE ${exampleplugin_sources})
-set_target_properties(exampleplugin PROPERTIES PREFIX "")
-target_link_libraries(exampleplugin -lamb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries})
+set(examplesourceplugin_headers exampleplugin.h)
+set(examplesourceplugin_sources exampleplugin.cpp)
+add_library(examplesourceplugin MODULE ${examplesourceplugin_sources})
+set_target_properties(examplesourceplugin PROPERTIES PREFIX "")
+target_link_libraries(examplesourceplugin -lamb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries})
+
+
+set(examplesinkplugin_headers examplesink.h)
+set(examplesinkplugin_sources examplesink.cpp)
+
+add_library(examplesinkplugin MODULE ${examplesinkplugin_sources})
+set_target_properties(examplesinkplugin PROPERTIES PREFIX "")
+target_link_libraries(examplesinkplugin -lamb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries})
\ No newline at end of file
set_target_properties(exampleplugin PROPERTIES PREFIX "")
target_link_libraries(exampleplugin -lamb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries})
-if(use_qtcore)
- if(nobdy_compat)
- pkg_check_modules(nobdy REQUIRED nobdy)
- set(nobdyplugin_headers nobdycompatplugin.h)
- set(nobdyplugin_sources nobdycompatplugin.cpp)
- qt4_wrap_cpp(nobdy_moc_sources ${nobdyplugin_headers})
- add_library(nobdyplugin MODULE ${nobdyplugin_sources} ${nobdy_moc_sources})
- set_target_properties(nobdyplugin PROPERTIES PREFIX "")
- include_directories(${nobdy_INCLUDE_DIRS} ${include_dirs})
- target_link_libraries(nobdyplugin ${nobdy_LIBRARIES} -lamb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries})
- endif(nobdy_compat)
-endif(use_qtcore)
\ No newline at end of file
#include <iostream>
#include <boost/assert.hpp>
+#include <glib.h>
using namespace std;
#include "debugout.h"
-ExampleSourcePlugin::ExampleSourcePlugin()
+static gboolean timeoutCallback(gpointer data)
{
+ ExampleSourcePlugin* src = (ExampleSourcePlugin*)data;
+ src->randomizeProperties();
+
+ return true;
}
-extern "C" AbstractSource * create()
+ExampleSourcePlugin::ExampleSourcePlugin(AbstractRoutingEngine* re)
+:AbstractSource(re), velocity(0), engineSpeed(0)
{
- return new ExampleSourcePlugin();
+ re->setSupported(supported(), this);
+
+ debugOut("setting timeout");
+ g_timeout_add(1000, timeoutCallback, this );
+
+}
+
+
+
+extern "C" AbstractSource * create(AbstractRoutingEngine* routingengine)
+{
+ return new ExampleSourcePlugin(routingengine);
+
}
string ExampleSourcePlugin::uuid()
mRequests.remove(property);
}
+void ExampleSourcePlugin::randomizeProperties()
+{
+ velocity = 1 + (255.00 * (rand() / (RAND_MAX + 1.0)));
+ engineSpeed = 1 + (15000.00 * (rand() / (RAND_MAX + 1.0)));
+
+ DebugOut()<<"setting velocity to: "<<velocity<<endl;
+ DebugOut()<<"setting enginespeed to: "<<engineSpeed<<endl;
+
+ routingEngine->updateProperty(VehicleProperty::VehicleSpeed, velocity);
+ routingEngine->updateProperty(VehicleProperty::EngineSpeed, engineSpeed);
+}
{
public:
- ExampleSourcePlugin();
+ ExampleSourcePlugin(AbstractRoutingEngine* re);
+
string uuid();
void setProperty(VehicleProperty::Property, boost::any);
void subscribeToPropertyChanges(VehicleProperty::Property property);
void unsubscribeToPropertyChanges(VehicleProperty::Property property);
PropertyList supported();
+ void propertyChanged(VehicleProperty::Property property, boost::any value, string uuid) {}
+ void supportedChanged(PropertyList) {}
+
+ void randomizeProperties();
+
private:
PropertyList mRequests;
+ uint16_t velocity;
+ uint16_t engineSpeed;
};
#endif // EXAMPLEPLUGIN_H