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"
27 extern "C" AbstractSinkManager * create(AbstractRoutingEngine* routingengine, map<string, string> config)
29 return new ExampleSinkManager(routingengine, config);
32 ExampleSink::ExampleSink(AbstractRoutingEngine* engine, map<string, string> config): AbstractSink(engine, config)
34 routingEngine->subscribeToProperty(VehicleProperty::EngineSpeed, this);
35 routingEngine->subscribeToProperty(VehicleProperty::VehicleSpeed, this);
37 supportedChanged(routingEngine->supported());
42 PropertyList ExampleSink::subscriptions()
47 void ExampleSink::supportedChanged(PropertyList supportedProperties)
49 printf("Support changed!\n");
50 routingEngine->subscribeToProperty(VehicleProperty::EngineSpeed, this);
51 routingEngine->subscribeToProperty(VehicleProperty::VehicleSpeed, this);
53 AsyncPropertyRequest velocityRequest;
54 velocityRequest.property = VehicleProperty::VehicleSpeed;
55 velocityRequest.completed = [](AsyncPropertyReply* reply)
57 DebugOut()<<"Velocity Async request completed: "<<reply->value->toString()<<endl; delete reply;
60 routingEngine->getPropertyAsync(velocityRequest);
62 AsyncPropertyRequest vinRequest;
63 vinRequest.property = VehicleProperty::VIN;
64 vinRequest.completed = [](AsyncPropertyReply* reply) { DebugOut(1)<<"VIN Async request completed: "<<reply->value->toString()<<endl; delete reply; };
66 routingEngine->getPropertyAsync(vinRequest);
68 AsyncPropertyRequest wmiRequest;
69 wmiRequest.property = VehicleProperty::WMI;
70 wmiRequest.completed = [](AsyncPropertyReply* reply) { DebugOut(1)<<"WMI Async request completed: "<<reply->value->toString()<<endl; delete reply; };
72 routingEngine->getPropertyAsync(wmiRequest);
74 AsyncPropertyRequest batteryVoltageRequest;
75 batteryVoltageRequest.property = VehicleProperty::BatteryVoltage;
76 batteryVoltageRequest.completed = [](AsyncPropertyReply* reply) { DebugOut(1)<<"BatteryVoltage Async request completed: "<<reply->value->toString()<<endl; delete reply; };
78 routingEngine->getPropertyAsync(batteryVoltageRequest);
80 auto getRangedCb = [](gpointer data)
82 AbstractRoutingEngine* routingEngine = (AbstractRoutingEngine*)data;
84 AsyncRangePropertyRequest vehicleSpeedFromLastWeek;
86 vehicleSpeedFromLastWeek.timeBegin = amb::currentTime() - 10;
87 vehicleSpeedFromLastWeek.timeEnd = amb::currentTime();
88 vehicleSpeedFromLastWeek.property = VehicleProperty::VehicleSpeed;
89 vehicleSpeedFromLastWeek.completed = [](AsyncRangePropertyReply* reply)
91 std::list<AbstractPropertyType*> values = reply->values;
92 for(auto itr = values.begin(); itr != values.end(); itr++)
95 DebugOut(1)<<"Velocity value from past: "<<val->toString()<<" time: "<<val->timestamp<<endl;
99 routingEngine->getRangePropertyAsync(vehicleSpeedFromLastWeek);
104 g_timeout_add(10000, getRangedCb, routingEngine);
107 void ExampleSink::propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, std::string uuid)
109 DebugOut()<<property<<" value: "<<value->toString()<<endl;
112 std::string ExampleSink::uuid()
114 return "f7e4fab2-eb73-4842-9fb0-e1c550eb2d81";