refactored setProperty: made it async with callback 23/2323/1
authorKevron Rees <kevron_m_rees@linux.intel.com>
Fri, 26 Oct 2012 23:21:07 +0000 (16:21 -0700)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Fri, 26 Oct 2012 23:21:07 +0000 (16:21 -0700)
15 files changed:
ambd/core.cpp
ambd/core.h
lib/abstractroutingengine.h
lib/abstractsource.h
plugins/dbus/basicproperty.h
plugins/dbus/dbusplugin.h
plugins/exampleplugin.cpp
plugins/exampleplugin.h
plugins/obd2plugin/obd2source.cpp
plugins/obd2plugin/obd2source.h
plugins/websocketsink/websocketsinkmanager.cpp
plugins/websocketsourceplugin/websocketsource.cpp
plugins/websocketsourceplugin/websocketsource.h
plugins/wheel/wheelplugin.cpp
plugins/wheel/wheelplugin.h

index ff014b3..083b0b4 100644 (file)
@@ -205,15 +205,15 @@ AsyncRangePropertyReply *Core::getRangePropertyAsync(AsyncRangePropertyRequest r
        return reply;
 }
 
-void Core::setProperty(VehicleProperty::Property property, AbstractPropertyType *value)
+AsyncPropertyReply * Core::setProperty(AsyncSetPropertyRequest request)
 {
        for(SourceList::iterator itr = mSources.begin(); itr != mSources.end(); itr++)
        {
                AbstractSource* src = (*itr);
                PropertyList properties = src->supported();
-               if(ListPlusPlus<VehicleProperty::Property>(&properties).contains(property))
+               if(ListPlusPlus<VehicleProperty::Property>(&properties).contains(request.property))
                {
-                       src->setProperty(property, value);
+                       return src->setProperty(request);
                }
        }
 }
index 4f4b14a..61f3e90 100644 (file)
@@ -44,7 +44,7 @@ public:
        void unregisterSink(AbstractSink *self);
        AsyncPropertyReply* getPropertyAsync(AsyncPropertyRequest request);
        AsyncRangePropertyReply* getRangePropertyAsync(AsyncRangePropertyRequest request);
-       void setProperty(VehicleProperty::Property,AbstractPropertyType*);
+       AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request);
        void subscribeToProperty(VehicleProperty::Property, AbstractSink* self);
        void unsubscribeToProperty(VehicleProperty::Property, AbstractSink* self);
        PropertyList supported() { return mMasterPropertyList; }
index b01df5a..f25adb7 100644 (file)
@@ -31,7 +31,13 @@ class AbstractSource;
 class AsyncPropertyReply;
 
 
-typedef std::function<void (AsyncPropertyReply*)> CompletedSignal;
+typedef std::function<void (AsyncPropertyReply*)> GetPropertyCompletedSignal;
+
+class PropertyValueTime {
+public:
+       AbstractPropertyType* value;
+       time_t timestamp;
+};
 
 class AsyncPropertyRequest
 {
@@ -57,13 +63,32 @@ public:
        }
 
        VehicleProperty::Property property;
-       CompletedSignal completed;
+       GetPropertyCompletedSignal completed;
 };
 
 class AsyncPropertyReply: public AsyncPropertyRequest
 {
 public:
        AsyncPropertyReply(const AsyncPropertyRequest &request)
+               :AsyncPropertyRequest(request), value(NULL), success(false)
+       {
+
+       }
+
+       AbstractPropertyType* value;
+       bool success;
+};
+
+class AsyncSetPropertyRequest: public AsyncPropertyRequest
+{
+public:
+       AsyncSetPropertyRequest()
+               :value(NULL)
+       {
+
+       }
+
+       AsyncSetPropertyRequest(const AsyncPropertyRequest &request)
                :AsyncPropertyRequest(request), value(NULL)
        {
 
@@ -110,7 +135,7 @@ public:
 
        }
 
-       std::list<AbstractPropertyType*> values;
+       std::list<PropertyValueTime*> values;
 };
 
 class AbstractRoutingEngine
@@ -123,9 +148,9 @@ public:
        /// sinks:
        virtual void registerSink(AbstractSink* self) = 0;
        virtual void  unregisterSink(AbstractSink* self) = 0;
-       virtual AsyncPropertyReply *getPropertyAsync(AsyncPropertyRequest request) = 0;
+       virtual AsyncPropertyReply * getPropertyAsync(AsyncPropertyRequest request) = 0;
        virtual AsyncRangePropertyReply * getRangePropertyAsync(AsyncRangePropertyRequest request) = 0;
-       virtual void setProperty(VehicleProperty::Property, AbstractPropertyType*) = 0;
+       virtual AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request) = 0;
        virtual void subscribeToProperty(VehicleProperty::Property, AbstractSink* self) = 0;
        virtual void unsubscribeToProperty(VehicleProperty::Property, AbstractSink* self) = 0;
        virtual PropertyList supported() = 0;
index d9a0ee3..d4c1e52 100644 (file)
@@ -46,7 +46,7 @@ public:
 
        virtual void getPropertyAsync(AsyncPropertyReply *reply) = 0;
        virtual void getRangePropertyAsync(AsyncRangePropertyReply *reply) = 0;
-       virtual void setProperty(VehicleProperty::Property property, AbstractPropertyType* value) = 0;
+       virtual AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request) = 0;
        virtual void subscribeToPropertyChanges(VehicleProperty::Property property) = 0;
        virtual void unsubscribeToPropertyChanges(VehicleProperty::Property property) = 0;
        virtual PropertyList supported() = 0;
index bedf1c2..cbd79e7 100644 (file)
@@ -56,10 +56,18 @@ public:
                AbstractPropertyType* apt = VehicleProperty::getPropertyTypeForPropertyNameValue(mAmbPropertyName,"");
                apt->setValue(val);
 
-               routingEngine->setProperty(mAmbPropertyName, apt);
+               AsyncSetPropertyRequest request;
+               request.property = mAmbPropertyName;
+               request.value = apt;
+               request.completed = [apt](AsyncPropertyReply* reply)
+               {
+                       if(!reply->success) {
+                               //TODO: throw DBus exception
+                       }
+                       delete apt;
+               };
 
-               ///delete this because we should be done
-               delete apt;
+               routingEngine->setProperty(request);
        }
 
 private:
index 2803eb1..103cfaa 100644 (file)
@@ -43,10 +43,14 @@ protected:
                propertyDBusMap[property] = new BasicProperty<T>(routingEngine, property, propertyName, signature, access, this);
        }
 
-       virtual void setProperty(VehicleProperty::Property name, AbstractPropertyType* value)
+       /*virtual void setProperty(VehicleProperty::Property name, AbstractPropertyType* value)
        {
-               routingEngine->setProperty(name, value);
-       }
+               AsyncSetPropertyRequest request;
+               request.property = name;
+               request.value = value;
+               request.completed = [](AsyncPropertyReply* reply) { delete reply; };
+               routingEngine->setProperty(request);
+       }*/
 
        PropertyDBusMap propertyDBusMap;
 private:
index 923ccd8..3fc5e4b 100644 (file)
@@ -126,7 +126,7 @@ void ExampleSourcePlugin::getRangePropertyAsync(AsyncRangePropertyReply *reply)
 
 }
 
-void ExampleSourcePlugin::setProperty(VehicleProperty::Property , AbstractPropertyType *)
+AsyncPropertyReply *ExampleSourcePlugin::setProperty(AsyncSetPropertyRequest request )
 {
 
 }
index 5bd2776..8f4327b 100644 (file)
@@ -33,7 +33,7 @@ public:
        string uuid();
        void getPropertyAsync(AsyncPropertyReply *reply);
        void getRangePropertyAsync(AsyncRangePropertyReply *reply);
-       void setProperty(VehicleProperty::Property, AbstractPropertyType*);
+       AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request);
        void subscribeToPropertyChanges(VehicleProperty::Property property);
        void unsubscribeToPropertyChanges(VehicleProperty::Property property);
        PropertyList supported();
index 81b42c3..5807fbc 100644 (file)
@@ -715,7 +715,17 @@ void OBD2Source::getPropertyAsync(AsyncPropertyReply *reply)
        g_async_queue_push(singleShotQueue,requ);
 }
 
-void OBD2Source::setProperty(VehicleProperty::Property , AbstractPropertyType * )
+AsyncPropertyReply *OBD2Source::setProperty(AsyncSetPropertyRequest request )
 {
+       AsyncPropertyReply* reply = new AsyncPropertyReply (request);
+       reply->success = false;
+       try
+       {
+               reply->completed(reply);
+       }
+       catch (...)
+       {
 
+       }
+       return reply;
 }
index 2a66c1b..931bc0b 100644 (file)
@@ -78,7 +78,7 @@ public:
        int portHandle;
        void getPropertyAsync(AsyncPropertyReply *reply);
        void getRangePropertyAsync(AsyncRangePropertyReply *reply){}
-       void setProperty(VehicleProperty::Property, AbstractPropertyType*);
+       AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request);
        void subscribeToPropertyChanges(VehicleProperty::Property property);
        void unsubscribeToPropertyChanges(VehicleProperty::Property property);
        PropertyList supported();
index 5039c05..002e3ef 100644 (file)
@@ -171,7 +171,17 @@ void WebSocketSinkManager::removeSink(libwebsocket* socket,VehicleProperty::Prop
 void WebSocketSinkManager::setValue(string property,string value)
 {
        AbstractPropertyType* type = VehicleProperty::getPropertyTypeForPropertyNameValue(property,value);
-       m_engine->setProperty(property, type);
+
+       AsyncSetPropertyRequest request;
+       request.property = property;
+       request.value = type;
+       request.completed = [](AsyncPropertyReply* reply)
+       {
+               ///TODO: do something here on !reply->success
+               delete reply;
+       };
+
+       m_engine->setProperty(request);
        DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "AbstractRoutingEngine::setProperty called with arguments:" << property << value << "\n";
        delete type;
        
index 16a4a45..aa1bdf2 100644 (file)
@@ -325,11 +325,7 @@ PropertyList WebSocketSource::supported()
 {
        return m_supportedProperties;
 }
-extern "C" AbstractSource * create(AbstractRoutingEngine* routingengine, map<string, string> config)
-{
-       return new WebSocketSource(routingengine, config);
-       
-}
+
 string WebSocketSource::uuid()
 {
        return "d293f670-f0b3-11e1-aff1-0800200c9a66";
@@ -366,7 +362,14 @@ void WebSocketSource::getRangePropertyAsync(AsyncRangePropertyReply *reply)
        ///TODO: fill in
 }
 
-void WebSocketSource::setProperty(VehicleProperty::Property , AbstractPropertyType * )
+AsyncPropertyReply * WebSocketSource::setProperty( AsyncSetPropertyRequest request )
 {
        ///TODO: fill in
+       return NULL;
+}
+
+extern "C" AbstractSource * create(AbstractRoutingEngine* routingengine, map<string, string> config)
+{
+       return new WebSocketSource(routingengine, config);
+
 }
index b5eeb5c..7854c80 100644 (file)
@@ -36,7 +36,7 @@ public:
     string uuid();
        void getPropertyAsync(AsyncPropertyReply *reply);
        void getRangePropertyAsync(AsyncRangePropertyReply *reply);
-       void setProperty(VehicleProperty::Property, AbstractPropertyType*);
+       AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request);
        void subscribeToPropertyChanges(VehicleProperty::Property property);
        void unsubscribeToPropertyChanges(VehicleProperty::Property property);
        PropertyList supported();
index 3e8d03f..2e80906 100644 (file)
@@ -137,7 +137,7 @@ void WheelSourcePlugin::getPropertyAsync(AsyncPropertyReply *reply)
        delete reply->value;
 }
 
-void WheelSourcePlugin::setProperty(VehicleProperty::Property , AbstractPropertyType * )
+AsyncPropertyReply *WheelSourcePlugin::setProperty(AsyncSetPropertyRequest request )
 {
 
 }
index 5ac1528..ab7e662 100644 (file)
@@ -36,7 +36,7 @@ public:
        string uuid();
        void getPropertyAsync(AsyncPropertyReply *reply);
        void getRangePropertyAsync(AsyncRangePropertyReply *reply){}
-       void setProperty(VehicleProperty::Property, AbstractPropertyType*);
+       AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request);
        void subscribeToPropertyChanges(VehicleProperty::Property property);
        void unsubscribeToPropertyChanges(VehicleProperty::Property property);
        PropertyList supported();