#include "examplesink.h"
#include "abstractroutingengine.h"
#include "debugout.h"
+#include "listplusplus.h"
#include <glib.h>
{
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());
}
}
-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);
+ 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 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 vinRequest;
- vinRequest.property = VehicleProperty::VIN;
- vinRequest.completed = [](AsyncPropertyReply* reply) { DebugOut(1)<<"VIN Async request completed: "<<reply->value->toString()<<endl; delete reply; };
+ routingEngine->getPropertyAsync(velocityRequest);
+ }
- routingEngine->getPropertyAsync(vinRequest);
+ 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 wmiRequest;
- wmiRequest.property = VehicleProperty::WMI;
- wmiRequest.completed = [](AsyncPropertyReply* reply) { DebugOut(1)<<"WMI 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(wmiRequest);
+ 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 batteryVoltageRequest;
- batteryVoltageRequest.property = VehicleProperty::BatteryVoltage;
- batteryVoltageRequest.completed = [](AsyncPropertyReply* reply) { DebugOut(1)<<"BatteryVoltage Async request completed: "<<reply->value->toString()<<endl; delete reply; };
+ routingEngine->getPropertyAsync(batteryVoltageRequest);
+ }
+ if(contains(supportedProperties, VehicleProperty::DoorsPerRow))
+ {
+ 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(batteryVoltageRequest);
+ routingEngine->getPropertyAsync(doorsPerRowRequest);
+ }
- AsyncPropertyRequest doorsPerRowRequest;
- doorsPerRowRequest.property = VehicleProperty::DoorsPerRow;
- doorsPerRowRequest.completed = [](AsyncPropertyReply* reply)
+ if(contains(supportedProperties,VehicleProperty::AirbagStatus))
{
- DebugOut(1)<<"Doors per row: "<<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(doorsPerRowRequest);
+ routingEngine->getPropertyAsync(airbagStatus);
+ }
- AsyncPropertyRequest airbagStatus;
- airbagStatus.property = VehicleProperty::AirbagStatus;
- airbagStatus.completed = [](AsyncPropertyReply* reply)
+ if(contains(supportedProperties, VehicleProperty::ExteriorBrightness))
{
- DebugOut(1)<<"Airbag Status: "<<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(airbagStatus);
+ routingEngine->getPropertyAsync(exteriorBrightness);
+ }
auto getRangedCb = [](gpointer data)
{
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;
};
routingEngine->getRangePropertyAsync(vehicleSpeedFromLastWeek);
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";
}