database plugin works
[profile/ivi/automotive-message-broker.git] / plugins / examplesink.cpp
1 /*
2     Copyright (C) 2012  Intel Corporation
3
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.
8
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.
13
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
17 */
18
19
20 #include "examplesink.h"
21 #include "abstractroutingengine.h"
22 #include "debugout.h"
23
24 #include <boost/date_time/posix_time/posix_time.hpp>
25
26
27 extern "C" AbstractSinkManager * create(AbstractRoutingEngine* routingengine, map<string, string> config)
28 {
29         return new ExampleSinkManager(routingengine, config);
30 }
31
32 ExampleSink::ExampleSink(AbstractRoutingEngine* engine, map<string, string> config): AbstractSink(engine, config)
33 {
34         routingEngine->subscribeToProperty(VehicleProperty::EngineSpeed, this);
35         routingEngine->subscribeToProperty(VehicleProperty::VehicleSpeed, this);
36
37         AsyncPropertyRequest velocityRequest;
38         velocityRequest.property = VehicleProperty::VehicleSpeed;
39         velocityRequest.completed = [](AsyncPropertyReply* reply) { DebugOut()<<"Velocity Async request completed: "<<reply->value->toString()<<endl; delete reply; };
40
41         routingEngine->getPropertyAsync(velocityRequest);
42
43         AsyncPropertyRequest vinRequest;
44         vinRequest.property = VehicleProperty::VIN;
45         vinRequest.completed = [](AsyncPropertyReply* reply) { DebugOut()<<"VIN Async request completed: "<<reply->value->toString()<<endl; delete reply; };
46
47         routingEngine->getPropertyAsync(vinRequest);
48
49         AsyncPropertyRequest wmiRequest;
50         wmiRequest.property = VehicleProperty::WMI;
51         wmiRequest.completed = [](AsyncPropertyReply* reply) { DebugOut()<<"WMI Async request completed: "<<reply->value->toString()<<endl; delete reply; };
52
53         routingEngine->getPropertyAsync(wmiRequest);
54
55         AsyncPropertyRequest batteryVoltageRequest;
56         batteryVoltageRequest.property = VehicleProperty::BatteryVoltage;
57         batteryVoltageRequest.completed = [](AsyncPropertyReply* reply) { DebugOut()<<"BatteryVoltage Async request completed: "<<reply->value->toString()<<endl; delete reply; };
58
59         routingEngine->getPropertyAsync(batteryVoltageRequest);
60
61         AsyncRangePropertyRequest vehicleSpeedFromLastWeek;
62
63         vehicleSpeedFromLastWeek.timeBegin = 1354233906.54099;
64         vehicleSpeedFromLastWeek.timeEnd = 1354234153.03318;
65         vehicleSpeedFromLastWeek.property = VehicleProperty::VehicleSpeed;
66         vehicleSpeedFromLastWeek.completed = [](AsyncRangePropertyReply* reply)
67         {
68                 std::list<AbstractPropertyType*> values = reply->values;
69                 for(auto itr = values.begin(); itr != values.end(); itr++)
70                 {
71                         DebugOut(0)<<"Velocity value from last week: "<<(*itr)->toString()<<" time: "<<(*itr)->timestamp<<endl;
72                 }
73         };
74
75         routingEngine->getRangePropertyAsync(vehicleSpeedFromLastWeek);
76
77 }
78
79
80 PropertyList ExampleSink::subscriptions()
81 {
82
83 }
84
85 void ExampleSink::supportedChanged(PropertyList supportedProperties)
86 {
87         printf("Support changed!\n");
88         routingEngine->subscribeToProperty(VehicleProperty::EngineSpeed, this);
89         routingEngine->subscribeToProperty(VehicleProperty::VehicleSpeed, this);
90 }
91
92 void ExampleSink::propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, std::string uuid)
93 {
94         DebugOut()<<property<<" value: "<<value->toString()<<endl;
95 }
96
97 std::string ExampleSink::uuid()
98 {
99         return "f7e4fab2-eb73-4842-9fb0-e1c550eb2d81";
100 }