From: Kevron Rees Date: Fri, 17 Aug 2012 01:29:50 +0000 (-0700) Subject: added async and sync property getter X-Git-Tag: submit/release/20120910.223349~96 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fc73b56289be551657371b8b60e6d9b4fc2e49a1;p=profile%2Fivi%2Fautomotive-message-broker.git added async and sync property getter --- diff --git a/ambd/core.cpp b/ambd/core.cpp index 224d4e9..db97d7c 100644 --- a/ambd/core.cpp +++ b/ambd/core.cpp @@ -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(&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(&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 } } - diff --git a/ambd/core.h b/ambd/core.h index 282fd19..3be8e65 100644 --- a/ambd/core.h +++ b/ambd/core.h @@ -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); diff --git a/lib/abstractroutingengine.h b/lib/abstractroutingengine.h index d7d67ec..695b497 100644 --- a/lib/abstractroutingengine.h +++ b/lib/abstractroutingengine.h @@ -21,11 +21,33 @@ #define ABSTRACTROUTINGENGINE_H #include +#include #include "vehicleproperty.h" class AbstractSink; class AbstractSource; +typedef std::function 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; diff --git a/lib/abstractsource.h b/lib/abstractsource.h index d9ba3ce..5516f22 100644 --- a/lib/abstractsource.h +++ b/lib/abstractsource.h @@ -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; diff --git a/plugins/exampleplugin.cpp b/plugins/exampleplugin.cpp index 253c587..a79e502 100644 --- a/plugins/exampleplugin.cpp +++ b/plugins/exampleplugin.cpp @@ -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 ) { diff --git a/plugins/exampleplugin.h b/plugins/exampleplugin.h index bb622ae..f19c1a8 100644 --- a/plugins/exampleplugin.h +++ b/plugins/exampleplugin.h @@ -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); diff --git a/plugins/examplesink.cpp b/plugins/examplesink.cpp index 589ab9a..193be18 100644 --- a/plugins/examplesink.cpp +++ b/plugins/examplesink.cpp @@ -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"<getPropertyAsync(velocityRequest); }