#include "examplesink.h"
#include "abstractroutingengine.h"
#include "debugout.h"
+#include "listplusplus.h"
+
+#include <glib.h>
+
extern "C" AbstractSinkManager * create(AbstractRoutingEngine* routingengine, map<string, string> config)
{
{
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);
- AsyncPropertyRequest velocityRequest;
- velocityRequest.property = VehicleProperty::VehicleSpeed;
- velocityRequest.completed = [](AsyncPropertyReply* reply) { 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()<<"VIN Async request completed: "<<reply->value->toString()<<endl; delete reply; };
-
- routingEngine->getPropertyAsync(vinRequest);
-
- AsyncPropertyRequest wmiRequest;
- wmiRequest.property = VehicleProperty::WMI;
- wmiRequest.completed = [](AsyncPropertyReply* reply) { DebugOut()<<"WMI Async request completed: "<<reply->value->toString()<<endl; delete reply; };
-
- routingEngine->getPropertyAsync(wmiRequest);
-
- AsyncPropertyRequest batteryVoltageRequest;
- batteryVoltageRequest.property = VehicleProperty::BatteryVoltage;
- batteryVoltageRequest.completed = [](AsyncPropertyReply* reply) { DebugOut()<<"BatteryVoltage Async request completed: "<<reply->value->toString()<<endl; delete reply; };
-
- routingEngine->getPropertyAsync(batteryVoltageRequest);
-
+ 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;
+
+ if(contains(supportedProperties, VehicleProperty::VehicleSpeed))
+ {
+ 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;
+ };
+
+ routingEngine->getPropertyAsync(velocityRequest);
+ }
+
+ 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;
+ };
+
+ 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);
+ }
+ 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;
+ };
+
+ 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(doorsPerRowRequest);
+ }
+
+ if(contains(supportedProperties,VehicleProperty::AirbagStatus))
+ {
+ 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);
+ }
+
+ if(contains(supportedProperties, VehicleProperty::ExteriorBrightness))
+ {
+ 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);
+ }
+
+ auto getRangedCb = [](gpointer data)
+ {
+ AbstractRoutingEngine* routingEngine = (AbstractRoutingEngine*)data;
+
+ AsyncRangePropertyRequest vehicleSpeedFromLastWeek;
+
+ vehicleSpeedFromLastWeek.timeBegin = amb::currentTime() - 10;
+ vehicleSpeedFromLastWeek.timeEnd = amb::currentTime();
+
+ 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)<<"Value from past: ("<<val->name<<"): "<<val->toString()<<" time: "<<val->timestamp<<endl;
+ }
+
+ delete reply;
+ };
+
+ routingEngine->getRangePropertyAsync(vehicleSpeedFromLastWeek);
+
+ return 0;
+ };
+
+ 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";
}