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"
24 #include <boost/date_time/posix_time/posix_time.hpp>
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 AsyncPropertyRequest velocityRequest;
38 velocityRequest.property = VehicleProperty::VehicleSpeed;
39 velocityRequest.completed = [](AsyncPropertyReply* reply) { DebugOut()<<"Velocity Async request completed: "<<reply->value->toString()<<endl; delete reply; };
41 routingEngine->getPropertyAsync(velocityRequest);
43 AsyncPropertyRequest vinRequest;
44 vinRequest.property = VehicleProperty::VIN;
45 vinRequest.completed = [](AsyncPropertyReply* reply) { DebugOut()<<"VIN Async request completed: "<<reply->value->toString()<<endl; delete reply; };
47 routingEngine->getPropertyAsync(vinRequest);
49 AsyncPropertyRequest wmiRequest;
50 wmiRequest.property = VehicleProperty::WMI;
51 wmiRequest.completed = [](AsyncPropertyReply* reply) { DebugOut()<<"WMI Async request completed: "<<reply->value->toString()<<endl; delete reply; };
53 routingEngine->getPropertyAsync(wmiRequest);
55 AsyncPropertyRequest batteryVoltageRequest;
56 batteryVoltageRequest.property = VehicleProperty::BatteryVoltage;
57 batteryVoltageRequest.completed = [](AsyncPropertyReply* reply) { DebugOut()<<"BatteryVoltage Async request completed: "<<reply->value->toString()<<endl; delete reply; };
59 routingEngine->getPropertyAsync(batteryVoltageRequest);
61 AsyncRangePropertyRequest vehicleSpeedFromLastWeek;
63 vehicleSpeedFromLastWeek.timeBegin = 1354233906.54099;
64 vehicleSpeedFromLastWeek.timeEnd = 1354234153.03318;
65 vehicleSpeedFromLastWeek.property = VehicleProperty::VehicleSpeed;
66 vehicleSpeedFromLastWeek.completed = [](AsyncRangePropertyReply* reply)
68 std::list<AbstractPropertyType*> values = reply->values;
69 for(auto itr = values.begin(); itr != values.end(); itr++)
71 DebugOut(0)<<"Velocity value from last week: "<<(*itr)->toString()<<" time: "<<(*itr)->timestamp<<endl;
75 routingEngine->getRangePropertyAsync(vehicleSpeedFromLastWeek);
80 PropertyList ExampleSink::subscriptions()
85 void ExampleSink::supportedChanged(PropertyList supportedProperties)
87 printf("Support changed!\n");
88 routingEngine->subscribeToProperty(VehicleProperty::EngineSpeed, this);
89 routingEngine->subscribeToProperty(VehicleProperty::VehicleSpeed, this);
92 void ExampleSink::propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, std::string uuid)
94 DebugOut()<<property<<" value: "<<value->toString()<<endl;
97 std::string ExampleSink::uuid()
99 return "f7e4fab2-eb73-4842-9fb0-e1c550eb2d81";