added xwalk. added set
[profile/ivi/automotive-message-broker.git] / plugins / examplesink.cpp
index ce68dbe..bad3c42 100644 (file)
@@ -20,6 +20,7 @@
 #include "examplesink.h"
 #include "abstractroutingengine.h"
 #include "debugout.h"
+#include "listplusplus.h"
 
 #include <glib.h>
 
@@ -33,9 +34,11 @@ ExampleSink::ExampleSink(AbstractRoutingEngine* engine, map<string, string> conf
 {
        routingEngine->subscribeToProperty(VehicleProperty::EngineSpeed, this);
        routingEngine->subscribeToProperty(VehicleProperty::VehicleSpeed, this);
+       routingEngine->subscribeToProperty(VehicleProperty::Latitude, this);
+       routingEngine->subscribeToProperty(VehicleProperty::Longitude, this);
+       routingEngine->subscribeToProperty(VehicleProperty::ExteriorBrightness, this);
 
-       supportedChanged(routingEngine->supported());
-
+       supportedChanged(engine->supported());
 }
 
 
@@ -44,70 +47,121 @@ PropertyList ExampleSink::subscriptions()
 
 }
 
-void ExampleSink::supportedChanged(PropertyList supportedProperties)
+void ExampleSink::supportedChanged(const PropertyList & supportedProperties)
 {
-       printf("Support changed!\n");
-       routingEngine->subscribeToProperty(VehicleProperty::EngineSpeed, this);
-       routingEngine->subscribeToProperty(VehicleProperty::VehicleSpeed, this);
-       routingEngine->subscribeToProperty(VehicleProperty::Latitude, this);
-       routingEngine->subscribeToProperty(VehicleProperty::Longitude, this);
+       DebugOut()<<"Support changed!"<<endl;
 
-       AsyncPropertyRequest velocityRequest;
-       velocityRequest.property = VehicleProperty::VehicleSpeed;
-       velocityRequest.completed = [](AsyncPropertyReply* reply)
+       if(contains(supportedProperties, VehicleProperty::VehicleSpeed))
        {
-               DebugOut()<<"Velocity Async request completed: "<<reply->value->toString()<<endl; delete reply;
-       };
-
-       routingEngine->getPropertyAsync(velocityRequest);
-
-       AsyncPropertyRequest vinRequest;
-       vinRequest.property = VehicleProperty::VIN;
-       vinRequest.completed = [](AsyncPropertyReply* reply) { DebugOut(1)<<"VIN Async request completed: "<<reply->value->toString()<<endl; delete reply; };
-
-       routingEngine->getPropertyAsync(vinRequest);
+               AsyncPropertyRequest velocityRequest;
+               velocityRequest.property = VehicleProperty::VehicleSpeed;
+               velocityRequest.completed = [](AsyncPropertyReply* reply)
+               {
+                       if(!reply->success)
+                               DebugOut(DebugOut::Error)<<"Velocity Async request failed ("<<reply->error<<")"<<endl;
+                       else
+                               DebugOut(0)<<"Velocity Async request completed: "<<reply->value->toString()<<endl;
+                       delete reply;
+               };
 
-       AsyncPropertyRequest wmiRequest;
-       wmiRequest.property = VehicleProperty::WMI;
-       wmiRequest.completed = [](AsyncPropertyReply* reply) { DebugOut(1)<<"WMI Async request completed: "<<reply->value->toString()<<endl; delete reply; };
+               routingEngine->getPropertyAsync(velocityRequest);
+       }
 
-       routingEngine->getPropertyAsync(wmiRequest);
+       if(contains(supportedProperties, VehicleProperty::VIN))
+       {
+               AsyncPropertyRequest vinRequest;
+               vinRequest.property = VehicleProperty::VIN;
+               vinRequest.completed = [](AsyncPropertyReply* reply)
+               {
+                       if(!reply->success)
+                               DebugOut(DebugOut::Error)<<"VIN Async request failed ("<<reply->error<<")"<<endl;
+                       else
+                               DebugOut(0)<<"VIN Async request completed: "<<reply->value->toString()<<endl;
+                       delete reply;
+               };
 
-       AsyncPropertyRequest batteryVoltageRequest;
-       batteryVoltageRequest.property = VehicleProperty::BatteryVoltage;
-       batteryVoltageRequest.completed = [](AsyncPropertyReply* reply) { DebugOut(1)<<"BatteryVoltage Async request completed: "<<reply->value->toString()<<endl; delete reply; };
+               routingEngine->getPropertyAsync(vinRequest);
+       }
+       if(contains(supportedProperties, VehicleProperty::WMI))
+       {
+               AsyncPropertyRequest wmiRequest;
+               wmiRequest.property = VehicleProperty::WMI;
+               wmiRequest.completed = [](AsyncPropertyReply* reply)
+               {
+                       if(!reply->success)
+                               DebugOut(DebugOut::Error)<<"WMI Async request failed ("<<reply->error<<")"<<endl;
+                       else
+                               DebugOut(1)<<"WMI Async request completed: "<<reply->value->toString()<<endl;
+                       delete reply;
+               };
 
-       routingEngine->getPropertyAsync(batteryVoltageRequest);
+               routingEngine->getPropertyAsync(wmiRequest);
+       }
+       if(contains(supportedProperties, VehicleProperty::BatteryVoltage))
+       {
+               AsyncPropertyRequest batteryVoltageRequest;
+               batteryVoltageRequest.property = VehicleProperty::BatteryVoltage;
+               batteryVoltageRequest.completed = [](AsyncPropertyReply* reply)
+               {
+                       if(!reply->success)
+                               DebugOut(DebugOut::Error)<<"BatteryVoltage Async request failed ("<<reply->error<<")"<<endl;
+                       else
+                               DebugOut(1)<<"BatteryVoltage Async request completed: "<<reply->value->toString()<<endl;
+                       delete reply;
+               };
 
-       AsyncPropertyRequest doorsPerRowRequest;
-       doorsPerRowRequest.property = VehicleProperty::DoorsPerRow;
-       doorsPerRowRequest.completed = [](AsyncPropertyReply* reply)
+               routingEngine->getPropertyAsync(batteryVoltageRequest);
+       }
+       if(contains(supportedProperties, VehicleProperty::DoorsPerRow))
        {
-               DebugOut(1)<<"Doors per row: "<<reply->value->toString()<<endl;
-               delete reply;
-       };
+               AsyncPropertyRequest doorsPerRowRequest;
+               doorsPerRowRequest.property = VehicleProperty::DoorsPerRow;
+               doorsPerRowRequest.completed = [](AsyncPropertyReply* reply)
+               {
+                       if(!reply->success)
+                               DebugOut(DebugOut::Error)<<"Doors per row Async request failed ("<<reply->error<<")"<<endl;
+                       else
+                               DebugOut(1)<<"Doors per row: "<<reply->value->toString()<<endl;
+                       delete reply;
+               };
 
-       routingEngine->getPropertyAsync(doorsPerRowRequest);
+               routingEngine->getPropertyAsync(doorsPerRowRequest);
+       }
 
-       AsyncPropertyRequest airbagStatus;
-       airbagStatus.property = VehicleProperty::AirbagStatus;
-       airbagStatus.completed = [](AsyncPropertyReply* reply)
+       if(contains(supportedProperties,VehicleProperty::AirbagStatus))
        {
-               DebugOut(1)<<"Airbag Status: "<<reply->value->toString()<<endl;
-               delete reply;
-       };
+               AsyncPropertyRequest airbagStatus;
+               airbagStatus.property = VehicleProperty::AirbagStatus;
+               airbagStatus.zoneFilter = Zone::FrontRight | Zone::FrontSide;
+               airbagStatus.completed = [](AsyncPropertyReply* reply)
+               {
+                       if(!reply->success)
+                       {
+                               DebugOut(DebugOut::Error)<<"Airbag Async request failed ("<<reply->error<<")"<<endl;
+                       }
+                       else
+                               DebugOut(1)<<"Airbag Status: "<<reply->value->toString()<<endl;
+                       delete reply;
+               };
 
-       routingEngine->getPropertyAsync(airbagStatus);
+               routingEngine->getPropertyAsync(airbagStatus);
+       }
 
-       AsyncPropertyRequest exteriorBrightness;
-       exteriorBrightness.property = VehicleProperty::ExteriorBrightness;
-       exteriorBrightness.completed = [](AsyncPropertyReply* reply)
+       if(contains(supportedProperties, VehicleProperty::ExteriorBrightness))
        {
-               DebugOut(1)<<"Exterior Brightness: "<<reply->value->toString()<<endl;
-               delete reply;
-       };
+               AsyncPropertyRequest exteriorBrightness;
+               exteriorBrightness.property = VehicleProperty::ExteriorBrightness;
+               exteriorBrightness.completed = [](AsyncPropertyReply* reply)
+               {
+                       if(!reply->success)
+                               DebugOut(DebugOut::Error)<<"Exterior Brightness Async request failed ("<<reply->error<<")"<<endl;
+                       else
+                               DebugOut(1)<<"Exterior Brightness: "<<reply->value->toString()<<endl;
+                       delete reply;
+               };
 
-       routingEngine->getPropertyAsync(exteriorBrightness);
+               routingEngine->getPropertyAsync(exteriorBrightness);
+       }
 
        auto getRangedCb = [](gpointer data)
        {
@@ -117,14 +171,19 @@ void ExampleSink::supportedChanged(PropertyList supportedProperties)
 
                vehicleSpeedFromLastWeek.timeBegin = amb::currentTime() - 10;
                vehicleSpeedFromLastWeek.timeEnd = amb::currentTime();
-               vehicleSpeedFromLastWeek.property = VehicleProperty::VehicleSpeed;
+
+               PropertyList requestList;
+               requestList.push_back(VehicleProperty::VehicleSpeed);
+               requestList.push_back(VehicleProperty::EngineSpeed);
+
+               vehicleSpeedFromLastWeek.properties = requestList;
                vehicleSpeedFromLastWeek.completed = [](AsyncRangePropertyReply* reply)
                {
                        std::list<AbstractPropertyType*> values = reply->values;
                        for(auto itr = values.begin(); itr != values.end(); itr++)
                        {
                                auto val = *itr;
-                               DebugOut(1)<<"Velocity value from past: "<<val->toString()<<" time: "<<val->timestamp<<endl;
+                               DebugOut(1)<<"Value from past: ("<<val->name<<"): "<<val->toString()<<" time: "<<val->timestamp<<endl;
                        }
 
                        delete reply;
@@ -138,12 +197,13 @@ void ExampleSink::supportedChanged(PropertyList supportedProperties)
        g_timeout_add(10000, getRangedCb, routingEngine);
 }
 
-void ExampleSink::propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, std::string uuid)
+void ExampleSink::propertyChanged(AbstractPropertyType *value)
 {
+       VehicleProperty::Property property = value->name;
        DebugOut()<<property<<" value: "<<value->toString()<<endl;
 }
 
-std::string ExampleSink::uuid()
+const string ExampleSink::uuid()
 {
        return "f7e4fab2-eb73-4842-9fb0-e1c550eb2d81";
 }