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" AbstractSinkManager * create(AbstractRoutingEngine* routingengine, map<string, string> config)
30 return new ExampleSinkManager(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(PropertyList supportedProperties)
52 DebugOut()<<"Support changed!"<<endl;
54 if(ListPlusPlus<VehicleProperty::Property>(&supportedProperties).contains(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(ListPlusPlus<VehicleProperty::Property>(&supportedProperties).contains(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(ListPlusPlus<VehicleProperty::Property>(&supportedProperties).contains(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(ListPlusPlus<VehicleProperty::Property>(&supportedProperties).contains(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(ListPlusPlus<VehicleProperty::Property>(&supportedProperties).contains(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(ListPlusPlus<VehicleProperty::Property>(&supportedProperties).contains(VehicleProperty::AirbagStatus))
133 AsyncPropertyRequest airbagStatus;
134 airbagStatus.property = VehicleProperty::AirbagStatus;
135 airbagStatus.completed = [](AsyncPropertyReply* reply)
138 DebugOut(DebugOut::Error)<<"Airbag Async request failed ("<<reply->error<<")"<<endl;
140 DebugOut(1)<<"Airbag Status: "<<reply->value->toString()<<endl;
144 routingEngine->getPropertyAsync(airbagStatus);
147 if(ListPlusPlus<VehicleProperty::Property>(&supportedProperties).contains(VehicleProperty::ExteriorBrightness))
149 AsyncPropertyRequest exteriorBrightness;
150 exteriorBrightness.property = VehicleProperty::ExteriorBrightness;
151 exteriorBrightness.completed = [](AsyncPropertyReply* reply)
154 DebugOut(DebugOut::Error)<<"Exterior Brightness Async request failed ("<<reply->error<<")"<<endl;
156 DebugOut(1)<<"Exterior Brightness: "<<reply->value->toString()<<endl;
160 routingEngine->getPropertyAsync(exteriorBrightness);
163 auto getRangedCb = [](gpointer data)
165 AbstractRoutingEngine* routingEngine = (AbstractRoutingEngine*)data;
167 AsyncRangePropertyRequest vehicleSpeedFromLastWeek;
169 vehicleSpeedFromLastWeek.timeBegin = amb::currentTime() - 10;
170 vehicleSpeedFromLastWeek.timeEnd = amb::currentTime();
172 PropertyList requestList;
173 requestList.push_back(VehicleProperty::VehicleSpeed);
174 requestList.push_back(VehicleProperty::EngineSpeed);
176 vehicleSpeedFromLastWeek.properties = requestList;
177 vehicleSpeedFromLastWeek.completed = [](AsyncRangePropertyReply* reply)
179 std::list<AbstractPropertyType*> values = reply->values;
180 for(auto itr = values.begin(); itr != values.end(); itr++)
183 DebugOut(1)<<"Value from past: ("<<val->name<<"): "<<val->toString()<<" time: "<<val->timestamp<<endl;
189 routingEngine->getRangePropertyAsync(vehicleSpeedFromLastWeek);
194 g_timeout_add(10000, getRangedCb, routingEngine);
197 void ExampleSink::propertyChanged(AbstractPropertyType* value, const string &uuid)
199 VehicleProperty::Property property = value->name;
200 DebugOut()<<property<<" value: "<<value->toString()<<endl;
203 const string ExampleSink::uuid()
205 return "f7e4fab2-eb73-4842-9fb0-e1c550eb2d81";