set uses zone filter properly. updated example to include setProperty example
authorKevron Rees <kevron.m.rees@intel.com>
Thu, 7 Nov 2013 23:55:15 +0000 (15:55 -0800)
committerKevron Rees <kevron.m.rees@intel.com>
Fri, 8 Nov 2013 22:55:29 +0000 (14:55 -0800)
lib/abstractpropertytype.cpp
lib/abstractpropertytype.h
lib/abstractroutingengine.cpp
lib/abstractroutingengine.h
plugins/dbus/varianttype.cpp
plugins/exampleplugin.cpp
plugins/exampleplugin.h

index 03ba0de..5ad2588 100644 (file)
@@ -1,2 +1,8 @@
 #include "abstractpropertytype.h"
 
+const Zone::Type Zone::FrontRight = Zone::Type(Zone::Front | Zone::Right);
+const Zone::Type Zone::FrontLeft = Zone::Type(Zone::Front | Zone::Left);
+const Zone::Type Zone::MiddleRight = Zone::Type(Zone::Middle | Zone::Right);
+const Zone::Type Zone::MiddleLeft = Zone::Type(Zone::Middle | Zone::Left);
+const Zone::Type Zone::RearRight = Zone::Type(Zone::Rear | Zone::Right);
+const Zone::Type Zone::RearLeft = Zone::Type(Zone::Rear | Zone::Left);
index ebe1cf5..3e9dcba 100644 (file)
@@ -54,12 +54,12 @@ public:
                BackSide = 1 << 9
        };
 
-static const Zone::Type FrontRight = Zone::Type(Front | Right);
-static const Zone::Type FrontLeft = Zone::Type(Front | Left);
-static const Zone::Type MiddleRight = Zone::Type(Middle | Right);
-static const Zone::Type MiddleLeft = Zone::Type(Middle | Left);
-static const Zone::Type RearRight = Zone::Type(Rear | Right);
-static const Zone::Type RearLeft = Zone::Type(Rear | Left);
+static const Zone::Type FrontRight;
+static const Zone::Type FrontLeft;
+static const Zone::Type MiddleRight;
+static const Zone::Type MiddleLeft;
+static const Zone::Type RearRight;
+static const Zone::Type RearLeft;
 
 typedef std::list<Zone::Type> ZoneList;
 
index 190d864..ce153d0 100644 (file)
@@ -28,6 +28,18 @@ AbstractRoutingEngine::~AbstractRoutingEngine()
 AsyncPropertyReply::AsyncPropertyReply(const AsyncPropertyRequest &request)
        :AsyncPropertyRequest(request), value(NULL), success(false), timeoutSource(nullptr)
 {
+       setTimeout();
+}
+
+AsyncPropertyReply::AsyncPropertyReply(const AsyncSetPropertyRequest &request)
+       :AsyncPropertyRequest(request), value(request.value), success(false), timeoutSource(nullptr)
+{
+       setTimeout();
+       value->zone = request.zoneFilter;
+}
+
+void AsyncPropertyReply::setTimeout()
+{
        auto timeoutfunc = [](gpointer userData) {
                AsyncPropertyReply* thisReply = static_cast<AsyncPropertyReply*>(userData);
                if(thisReply->success == false)
index f6273bd..46e2a09 100644 (file)
@@ -35,6 +35,7 @@ class AbstractSink;
 class AbstractSource;
 class AsyncPropertyReply;
 class AsyncRangePropertyReply;
+class AsyncSetPropertyRequest;
 
 
 typedef std::function<void (AsyncPropertyReply*)> GetPropertyCompletedSignal;
@@ -118,6 +119,8 @@ class AsyncPropertyReply: public AsyncPropertyRequest
 public:
        AsyncPropertyReply(const AsyncPropertyRequest &request);
 
+       AsyncPropertyReply(const AsyncSetPropertyRequest &request);
+
        virtual ~AsyncPropertyReply()
        {
                if(timeoutSource)
@@ -156,12 +159,13 @@ public:
        Error error;
 
 private:
+       void setTimeout();
        GSource* timeoutSource;
 };
 
 /*!
  * \brief The AsyncSetPropertyRequest class is used by sinks to set a property to the 'value'.  The source will reply
- * with a AsyncPropertyReply containing the new value or an error
+ * with a AsyncPropertyReply containing the new value or an error.
  * \see AbstractRoutingEngine::setProperty
  * \see AsyncPropertyReply
  */
@@ -180,7 +184,10 @@ public:
 
        }
 
-       virtual ~AsyncSetPropertyRequest() { }
+       virtual ~AsyncSetPropertyRequest()
+       {
+
+       }
 
        /*!
         * \brief value the new value to set the property to.
index a43b491..ea7983d 100644 (file)
@@ -58,19 +58,21 @@ GVariant *VariantType::toGVariant()
 
 void VariantType::fromGVariant(GVariant *val)
 {
-       AbstractPropertyTypev = VehicleProperty::getPropertyTypeForPropertyNameValue(mAmbPropertyName);
+       AbstractPropertyType *v = VehicleProperty::getPropertyTypeForPropertyNameValue(mAmbPropertyName);
        v->fromVariant( val );
 
        AsyncSetPropertyRequest request;
        request.property = mAmbPropertyName;
        request.value = v;
-       request.completed = [](AsyncPropertyReply* reply)
+       request.zoneFilter = mZoneFilter;
+       request.completed = [&](AsyncPropertyReply* reply)
        {
                /// TODO: throw dbus exception
                if(!reply->success)
                {
                        DebugOut(DebugOut::Error)<<"setProperty fail: "<<reply->error<<endl;
                }
+               delete v;
                delete reply;
        };
 
index 26bc53a..5c1f6e5 100644 (file)
@@ -63,7 +63,7 @@ ExampleSourcePlugin::ExampleSourcePlugin(AbstractRoutingEngine* re, map<string,
        addPropertySupport(VehicleProperty::MachineGunTurretStatus, Zone::None);
        addPropertySupport(VehicleProperty::ExteriorBrightness, Zone::None);
        addPropertySupport(VehicleProperty::DoorsPerRow, Zone::None);
-       addPropertySupport(VehicleProperty::AirbagStatus, Zone::FrontLeft);
+       addPropertySupport(VehicleProperty::AirbagStatus, Zone::None);
 
        Zone::ZoneList airbagZones;
        airbagZones.push_back(Zone::FrontLeft | Zone::FrontSide);
@@ -80,6 +80,18 @@ ExampleSourcePlugin::ExampleSourcePlugin(AbstractRoutingEngine* re, map<string,
 
        propertyInfoMap[VehicleProperty::AirbagStatus] = airbagInfo;
 
+       addPropertySupport(VehicleProperty::AirConditioning, Zone::None);
+
+       Zone::ZoneList acZones;
+       acZones.push_back(Zone::FrontLeft);
+       acZones.push_back(Zone::Front | Zone::Right);
+
+       acStatus[Zone::Front | Zone::Left] = true;
+       acStatus[Zone::Front | Zone::Right] = false;
+
+       PropertyInfo acInfo(0,acZones);
+       propertyInfoMap[VehicleProperty::AirConditioning] = acInfo;
+
        re->setSupported(supported(), this);
 }
 
@@ -240,6 +252,22 @@ void ExampleSourcePlugin::getPropertyAsync(AsyncPropertyReply *reply)
                        reply->completed(reply);
                }
        }
+       else if(reply->property == VehicleProperty::AirConditioning)
+       {
+               if(acStatus.find(reply->zoneFilter) == acStatus.end())
+               {
+                       reply->success = false;
+                       reply->error = AsyncPropertyReply::ZoneNotSupported;
+                       reply->completed(reply);
+               }
+               else
+               {
+                       VehicleProperty::AirConditioningType temp(acStatus[reply->zoneFilter]);
+                       reply->success = true;
+                       reply->value = &temp;
+                       reply->completed(reply);
+               }
+       }
 
        else
        {
@@ -256,7 +284,29 @@ void ExampleSourcePlugin::getRangePropertyAsync(AsyncRangePropertyReply *reply)
 
 AsyncPropertyReply *ExampleSourcePlugin::setProperty(AsyncSetPropertyRequest request )
 {
+       AsyncPropertyReply *reply = new AsyncPropertyReply(request);
+
+       if(reply->property == VehicleProperty::AirConditioning)
+       {
+               if(acStatus.find(reply->zoneFilter) == acStatus.end())
+               {
+                       reply->success = false;
+                       reply->error = AsyncPropertyReply::ZoneNotSupported;
+                       reply->completed(reply);
+               }
+               else
+               {
+                       acStatus[reply->zoneFilter] = reply->value->value<bool>();
+
+                       ///we need to update subscribers of this change:
+                       routingEngine->updateProperty(reply->value,uuid());
+
+                       ///Now reply to the set request:
+                       reply->success = true;
+                       reply->completed(reply);
 
+               }
+       }
 }
 
 void ExampleSourcePlugin::subscribeToPropertyChanges(VehicleProperty::Property property)
index 3db5623..e7dde41 100644 (file)
@@ -58,6 +58,7 @@ private:
 
        std::map<VehicleProperty::Property, PropertyInfo> propertyInfoMap;
        std::map<Zone::Type, Airbag::Status> airbagStatus;
+       std::map<Zone::Type, bool> acStatus;
        PropertyList mRequests;
        PropertyList mSupported;
        uint16_t velocity;