/* Copyright (C) 2012 Intel Corporation This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "examplesink.h" #include "abstractroutingengine.h" #include "debugout.h" #include "listplusplus.h" #include extern "C" void create(AbstractRoutingEngine* routingEngine, map config) { new ExampleSink(routingEngine, config); } ExampleSink::ExampleSink(AbstractRoutingEngine* engine, map config): AbstractSink(engine, 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); supportedChanged(engine->supported()); } PropertyList ExampleSink::subscriptions() { } void ExampleSink::supportedChanged(const PropertyList & supportedProperties) { DebugOut()<<"Support changed!"<success) DebugOut(DebugOut::Error)<<"Velocity Async request failed ("<error<<")"<value->toString()<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 ("<error<<")"<value->toString()<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 ("<error<<")"<value->toString()<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 ("<error<<")"<value->toString()<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 ("<error<<")"<value->toString()<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 ("<error<<")"<value->toString()<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 ("<error<<")"<value->toString()<getPropertyAsync(exteriorBrightness); } auto getRangedCb = [](gpointer data) { AbstractRoutingEngine* routingEngine = (AbstractRoutingEngine*)data; AsyncRangePropertyRequest vehicleSpeedFromLastWeek; vehicleSpeedFromLastWeek.timeBegin = amb::Timestamp::instance()->epochTime() - 10; vehicleSpeedFromLastWeek.timeEnd = amb::Timestamp::instance()->epochTime(); PropertyList requestList; requestList.push_back(VehicleProperty::VehicleSpeed); requestList.push_back(VehicleProperty::EngineSpeed); vehicleSpeedFromLastWeek.properties = requestList; vehicleSpeedFromLastWeek.completed = [](AsyncRangePropertyReply* reply) { std::list 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 << " sequence: " << val->sequence << endl; } delete reply; }; routingEngine->getRangePropertyAsync(vehicleSpeedFromLastWeek); return 0; }; g_timeout_add(10000, getRangedCb, routingEngine); } void ExampleSink::propertyChanged(AbstractPropertyType *value) { VehicleProperty::Property property = value->name; DebugOut()<toString()<