}
}
+boost::any Core::getProperty(VehicleProperty::Property property)
+{
+ for(SourceList::iterator itr = mSources.begin(); itr != mSources.end(); itr++)
+ {
+ AbstractSource* src = (*itr);
+ PropertyList properties = src->supported();
+ if(ListPlusPlus<VehicleProperty::Property>(&properties).contains(property))
+ {
+ return src->getProperty(property);
+ }
+ }
+}
+
+AsyncPropertyReply *Core::getPropertyAsync(AsyncPropertyRequest request)
+{
+ AsyncPropertyReply * reply = new AsyncPropertyReply(request);
+
+ for(SourceList::iterator itr = mSources.begin(); itr != mSources.end(); itr++)
+ {
+ AbstractSource* src = (*itr);
+ PropertyList properties = src->supported();
+ if(ListPlusPlus<VehicleProperty::Property>(&properties).contains(request.property))
+ {
+ src->getPropertyAsync(reply);
+ }
+ }
+
+ return reply;
+}
+
void Core::setProperty(VehicleProperty::Property property, boost::any value)
{
for(SourceList::iterator itr = mSources.begin(); itr != mSources.end(); itr++)
}
}
-
/// sinks:
+ boost::any getProperty(VehicleProperty::Property);
+ AsyncPropertyReply* getPropertyAsync(AsyncPropertyRequest request);
void setProperty(VehicleProperty::Property, boost::any);
void subscribeToProperty(VehicleProperty::Property, AbstractSink* self);
void unsubscribeToProperty(VehicleProperty::Property, AbstractSink* self);
#define ABSTRACTROUTINGENGINE_H
#include <boost/any.hpp>
+#include <functional>
#include "vehicleproperty.h"
class AbstractSink;
class AbstractSource;
+typedef std::function<void (void)> CompletedSignal;
+
+class AsyncPropertyRequest
+{
+public:
+ VehicleProperty::Property property;
+ CompletedSignal completed;
+};
+
+class AsyncPropertyReply: public AsyncPropertyRequest
+{
+public:
+ AsyncPropertyReply(AsyncPropertyRequest request)
+ {
+ this->property = request.property;
+ this->completed = request.completed;
+ }
+
+ boost::any value;
+};
+
class AbstractRoutingEngine
{
public:
virtual void updateProperty(VehicleProperty::Property property, boost::any value) = 0;
/// sinks:
-
+
+ virtual boost::any getProperty(VehicleProperty::Property) = 0;
+ virtual AsyncPropertyReply *getPropertyAsync(AsyncPropertyRequest request) = 0;
virtual void setProperty(VehicleProperty::Property, boost::any) = 0;
virtual void subscribeToProperty(VehicleProperty::Property, AbstractSink* self) = 0;
virtual void unsubscribeToProperty(VehicleProperty::Property, AbstractSink* self) = 0;
///pure virtual methods:
+ virtual boost::any getProperty(VehicleProperty::Property) = 0;
+ virtual void getPropertyAsync(AsyncPropertyReply *reply) = 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;
return "6dd4268a-c605-4a06-9034-59c1e8344c8e";
}
+boost::any ExampleSourcePlugin::getProperty(VehicleProperty::Property property)
+{
+ if(property == VehicleProperty::VehicleSpeed)
+ {
+ return velocity;
+ }
+ else if(property == VehicleProperty::EngineSpeed)
+ {
+ return engineSpeed;
+ }
+}
+
+void ExampleSourcePlugin::getPropertyAsync(AsyncPropertyReply *reply)
+{
+ if(reply->property == VehicleProperty::VehicleSpeed)
+ {
+ reply->value = velocity;
+ reply->completed();
+ }
+ else if(reply->property == VehicleProperty::EngineSpeed)
+ {
+ reply->value = engineSpeed;
+ reply->completed();
+ }
+}
+
void ExampleSourcePlugin::setProperty(VehicleProperty::Property , boost::any )
{
ExampleSourcePlugin(AbstractRoutingEngine* re);
string uuid();
+ boost::any getProperty(VehicleProperty::Property property);
+ void getPropertyAsync(AsyncPropertyReply *reply);
void setProperty(VehicleProperty::Property, boost::any);
void subscribeToPropertyChanges(VehicleProperty::Property property);
void unsubscribeToPropertyChanges(VehicleProperty::Property property);
{
routingEngine->subscribeToProperty(VehicleProperty::EngineSpeed, this);
routingEngine->subscribeToProperty(VehicleProperty::VehicleSpeed, this);
+
+ AsyncPropertyRequest velocityRequest;
+ velocityRequest.property = VehicleProperty::VehicleSpeed;
+ velocityRequest.completed = [](void) { DebugOut()<<"Velocity Async request completed"<<endl; };
+
+ AsyncPropertyReply* reply = routingEngine->getPropertyAsync(velocityRequest);
}