added async and sync property getter
authorKevron Rees <tripzero.kev@gmail.com>
Fri, 17 Aug 2012 01:29:50 +0000 (18:29 -0700)
committerKevron Rees <tripzero.kev@gmail.com>
Fri, 17 Aug 2012 01:29:50 +0000 (18:29 -0700)
ambd/core.cpp
ambd/core.h
lib/abstractroutingengine.h
lib/abstractsource.h
plugins/exampleplugin.cpp
plugins/exampleplugin.h
plugins/examplesink.cpp

index 224d4e9..db97d7c 100644 (file)
@@ -107,6 +107,36 @@ void Core::updateProperty(VehicleProperty::Property property, boost::any value)
        }
 }
 
+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++)
@@ -166,4 +196,3 @@ void Core::unsubscribeToProperty(VehicleProperty::Property property, AbstractSin
        }
 }
 
-
index 282fd19..3be8e65 100644 (file)
@@ -40,6 +40,8 @@ public:
        
        /// 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);
index d7d67ec..695b497 100644 (file)
 #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:
@@ -34,7 +56,9 @@ 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;
index d9ba3ce..5516f22 100644 (file)
@@ -43,6 +43,8 @@ public:
        
        ///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;
index 253c587..a79e502 100644 (file)
@@ -58,6 +58,32 @@ string ExampleSourcePlugin::uuid()
        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 )
 {
 
index bb622ae..f19c1a8 100644 (file)
@@ -31,6 +31,8 @@ public:
        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);
index 589ab9a..193be18 100644 (file)
@@ -30,6 +30,12 @@ ExampleSink::ExampleSink(AbstractRoutingEngine* engine): AbstractSink(engine)
 {
        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);
 }