2 Copyright (C) 2012 Intel Corporation
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "examplesink.h"
21 #include "abstractroutingengine.h"
23 #include "listplusplus.h"
28 extern "C" void create(AbstractRoutingEngine* routingEngine, map<string, string> config)
30 new ExampleSink(routingEngine, config);
33 ExampleSink::ExampleSink(AbstractRoutingEngine* engine, map<string, string> config): AbstractSink(engine, config)
35 routingEngine->subscribeToProperty(VehicleProperty::EngineSpeed, this);
36 routingEngine->subscribeToProperty(VehicleProperty::VehicleSpeed, this);
37 routingEngine->subscribeToProperty(VehicleProperty::Latitude, this);
38 routingEngine->subscribeToProperty(VehicleProperty::Longitude, this);
39 routingEngine->subscribeToProperty(VehicleProperty::ExteriorBrightness, this);
41 supportedChanged(engine->supported());
45 PropertyList ExampleSink::subscriptions()
50 void ExampleSink::supportedChanged(const PropertyList & supportedProperties)
52 DebugOut()<<"Support changed!"<<endl;
54 if(contains(supportedProperties, VehicleProperty::VehicleSpeed))
56 AsyncPropertyRequest velocityRequest;
57 velocityRequest.property = VehicleProperty::VehicleSpeed;
58 velocityRequest.completed = [](AsyncPropertyReply* reply)
61 DebugOut(DebugOut::Error)<<"Velocity Async request failed ("<<reply->error<<")"<<endl;
63 DebugOut(0)<<"Velocity Async request completed: "<<reply->value->toString()<<endl;
67 routingEngine->getPropertyAsync(velocityRequest);
70 if(contains(supportedProperties, VehicleProperty::VIN))
72 AsyncPropertyRequest vinRequest;
73 vinRequest.property = VehicleProperty::VIN;
74 vinRequest.completed = [](AsyncPropertyReply* reply)
77 DebugOut(DebugOut::Error)<<"VIN Async request failed ("<<reply->error<<")"<<endl;
79 DebugOut(0)<<"VIN Async request completed: "<<reply->value->toString()<<endl;
83 routingEngine->getPropertyAsync(vinRequest);
85 if(contains(supportedProperties, VehicleProperty::WMI))
87 AsyncPropertyRequest wmiRequest;
88 wmiRequest.property = VehicleProperty::WMI;
89 wmiRequest.completed = [](AsyncPropertyReply* reply)
92 DebugOut(DebugOut::Error)<<"WMI Async request failed ("<<reply->error<<")"<<endl;
94 DebugOut(1)<<"WMI Async request completed: "<<reply->value->toString()<<endl;
98 routingEngine->getPropertyAsync(wmiRequest);
100 if(contains(supportedProperties, VehicleProperty::BatteryVoltage))
102 AsyncPropertyRequest batteryVoltageRequest;
103 batteryVoltageRequest.property = VehicleProperty::BatteryVoltage;
104 batteryVoltageRequest.completed = [](AsyncPropertyReply* reply)
107 DebugOut(DebugOut::Error)<<"BatteryVoltage Async request failed ("<<reply->error<<")"<<endl;
109 DebugOut(1)<<"BatteryVoltage Async request completed: "<<reply->value->toString()<<endl;
113 routingEngine->getPropertyAsync(batteryVoltageRequest);
115 if(contains(supportedProperties, VehicleProperty::DoorsPerRow))
117 AsyncPropertyRequest doorsPerRowRequest;
118 doorsPerRowRequest.property = VehicleProperty::DoorsPerRow;
119 doorsPerRowRequest.completed = [](AsyncPropertyReply* reply)
122 DebugOut(DebugOut::Error)<<"Doors per row Async request failed ("<<reply->error<<")"<<endl;
124 DebugOut(1)<<"Doors per row: "<<reply->value->toString()<<endl;
128 routingEngine->getPropertyAsync(doorsPerRowRequest);
131 if(contains(supportedProperties,VehicleProperty::AirbagStatus))
133 AsyncPropertyRequest airbagStatus;
134 airbagStatus.property = VehicleProperty::AirbagStatus;
135 airbagStatus.zoneFilter = Zone::FrontRight | Zone::FrontSide;
136 airbagStatus.completed = [](AsyncPropertyReply* reply)
140 DebugOut(DebugOut::Error)<<"Airbag Async request failed ("<<reply->error<<")"<<endl;
143 DebugOut(1)<<"Airbag Status: "<<reply->value->toString()<<endl;
147 routingEngine->getPropertyAsync(airbagStatus);
150 if(contains(supportedProperties, VehicleProperty::ExteriorBrightness))
152 AsyncPropertyRequest exteriorBrightness;
153 exteriorBrightness.property = VehicleProperty::ExteriorBrightness;
154 exteriorBrightness.completed = [](AsyncPropertyReply* reply)
157 DebugOut(DebugOut::Error)<<"Exterior Brightness Async request failed ("<<reply->error<<")"<<endl;
159 DebugOut(1)<<"Exterior Brightness: "<<reply->value->toString()<<endl;
163 routingEngine->getPropertyAsync(exteriorBrightness);
166 auto getRangedCb = [](gpointer data)
168 AbstractRoutingEngine* routingEngine = (AbstractRoutingEngine*)data;
170 AsyncRangePropertyRequest vehicleSpeedFromLastWeek;
172 vehicleSpeedFromLastWeek.timeBegin = amb::currentTime() - 10;
173 vehicleSpeedFromLastWeek.timeEnd = amb::currentTime();
175 PropertyList requestList;
176 requestList.push_back(VehicleProperty::VehicleSpeed);
177 requestList.push_back(VehicleProperty::EngineSpeed);
179 vehicleSpeedFromLastWeek.properties = requestList;
180 vehicleSpeedFromLastWeek.completed = [](AsyncRangePropertyReply* reply)
182 std::list<AbstractPropertyType*> values = reply->values;
183 for(auto itr = values.begin(); itr != values.end(); itr++)
186 DebugOut(1)<<"Value from past: ("<<val->name<<"): "<<val->toString()<<" time: "<<val->timestamp<<endl;
192 routingEngine->getRangePropertyAsync(vehicleSpeedFromLastWeek);
197 g_timeout_add(10000, getRangedCb, routingEngine);
200 void ExampleSink::propertyChanged(AbstractPropertyType *value)
202 VehicleProperty::Property property = value->name;
203 DebugOut()<<property<<" value: "<<value->toString()<<endl;
206 const string ExampleSink::uuid()
208 return "f7e4fab2-eb73-4842-9fb0-e1c550eb2d81";