added cuda support for opencv plugin
[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 #include "listplusplus.h"
24
25 #include <glib.h>
26
27
28 extern "C" AbstractSinkManager * create(AbstractRoutingEngine* routingengine, map<string, string> config)
29 {
30         return new ExampleSinkManager(routingengine, config);
31 }
32
33 ExampleSink::ExampleSink(AbstractRoutingEngine* engine, map<string, string> config): AbstractSink(engine, config)
34 {
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);
40
41         supportedChanged(engine->supported());
42 }
43
44
45 PropertyList ExampleSink::subscriptions()
46 {
47
48 }
49
50 void ExampleSink::supportedChanged(PropertyList supportedProperties)
51 {
52         DebugOut()<<"Support changed!"<<endl;
53
54         if(ListPlusPlus<VehicleProperty::Property>(&supportedProperties).contains(VehicleProperty::VehicleSpeed))
55         {
56                 AsyncPropertyRequest velocityRequest;
57                 velocityRequest.property = VehicleProperty::VehicleSpeed;
58                 velocityRequest.completed = [](AsyncPropertyReply* reply)
59                 {
60                         if(!reply->success)
61                                 DebugOut(DebugOut::Error)<<"Velocity Async request failed ("<<reply->error<<")"<<endl;
62                         else
63                                 DebugOut(0)<<"Velocity Async request completed: "<<reply->value->toString()<<endl;
64                         delete reply;
65                 };
66
67                 routingEngine->getPropertyAsync(velocityRequest);
68         }
69
70         if(ListPlusPlus<VehicleProperty::Property>(&supportedProperties).contains(VehicleProperty::VIN))
71         {
72                 AsyncPropertyRequest vinRequest;
73                 vinRequest.property = VehicleProperty::VIN;
74                 vinRequest.completed = [](AsyncPropertyReply* reply)
75                 {
76                         if(!reply->success)
77                                 DebugOut(DebugOut::Error)<<"VIN Async request failed ("<<reply->error<<")"<<endl;
78                         else
79                                 DebugOut(0)<<"VIN Async request completed: "<<reply->value->toString()<<endl;
80                         delete reply;
81                 };
82
83                 routingEngine->getPropertyAsync(vinRequest);
84         }
85         if(ListPlusPlus<VehicleProperty::Property>(&supportedProperties).contains(VehicleProperty::WMI))
86         {
87                 AsyncPropertyRequest wmiRequest;
88                 wmiRequest.property = VehicleProperty::WMI;
89                 wmiRequest.completed = [](AsyncPropertyReply* reply)
90                 {
91                         if(!reply->success)
92                                 DebugOut(DebugOut::Error)<<"WMI Async request failed ("<<reply->error<<")"<<endl;
93                         else
94                                 DebugOut(1)<<"WMI Async request completed: "<<reply->value->toString()<<endl;
95                         delete reply;
96                 };
97
98                 routingEngine->getPropertyAsync(wmiRequest);
99         }
100         if(ListPlusPlus<VehicleProperty::Property>(&supportedProperties).contains(VehicleProperty::BatteryVoltage))
101         {
102                 AsyncPropertyRequest batteryVoltageRequest;
103                 batteryVoltageRequest.property = VehicleProperty::BatteryVoltage;
104                 batteryVoltageRequest.completed = [](AsyncPropertyReply* reply)
105                 {
106                         if(!reply->success)
107                                 DebugOut(DebugOut::Error)<<"BatteryVoltage Async request failed ("<<reply->error<<")"<<endl;
108                         else
109                                 DebugOut(1)<<"BatteryVoltage Async request completed: "<<reply->value->toString()<<endl;
110                         delete reply;
111                 };
112
113                 routingEngine->getPropertyAsync(batteryVoltageRequest);
114         }
115         if(ListPlusPlus<VehicleProperty::Property>(&supportedProperties).contains(VehicleProperty::DoorsPerRow))
116         {
117                 AsyncPropertyRequest doorsPerRowRequest;
118                 doorsPerRowRequest.property = VehicleProperty::DoorsPerRow;
119                 doorsPerRowRequest.completed = [](AsyncPropertyReply* reply)
120                 {
121                         if(!reply->success)
122                                 DebugOut(DebugOut::Error)<<"Doors per row Async request failed ("<<reply->error<<")"<<endl;
123                         else
124                                 DebugOut(1)<<"Doors per row: "<<reply->value->toString()<<endl;
125                         delete reply;
126                 };
127
128                 routingEngine->getPropertyAsync(doorsPerRowRequest);
129         }
130
131         if(ListPlusPlus<VehicleProperty::Property>(&supportedProperties).contains(VehicleProperty::AirbagStatus))
132         {
133                 AsyncPropertyRequest airbagStatus;
134                 airbagStatus.property = VehicleProperty::AirbagStatus;
135                 airbagStatus.completed = [](AsyncPropertyReply* reply)
136                 {
137                         if(!reply->success)
138                                 DebugOut(DebugOut::Error)<<"Airbag Async request failed ("<<reply->error<<")"<<endl;
139                         else
140                                 DebugOut(1)<<"Airbag Status: "<<reply->value->toString()<<endl;
141                         delete reply;
142                 };
143
144                 routingEngine->getPropertyAsync(airbagStatus);
145         }
146
147         if(ListPlusPlus<VehicleProperty::Property>(&supportedProperties).contains(VehicleProperty::ExteriorBrightness))
148         {
149                 AsyncPropertyRequest exteriorBrightness;
150                 exteriorBrightness.property = VehicleProperty::ExteriorBrightness;
151                 exteriorBrightness.completed = [](AsyncPropertyReply* reply)
152                 {
153                         if(!reply->success)
154                                 DebugOut(DebugOut::Error)<<"Exterior Brightness Async request failed ("<<reply->error<<")"<<endl;
155                         else
156                                 DebugOut(1)<<"Exterior Brightness: "<<reply->value->toString()<<endl;
157                         delete reply;
158                 };
159
160                 routingEngine->getPropertyAsync(exteriorBrightness);
161         }
162
163         auto getRangedCb = [](gpointer data)
164         {
165                 AbstractRoutingEngine* routingEngine = (AbstractRoutingEngine*)data;
166
167                 AsyncRangePropertyRequest vehicleSpeedFromLastWeek;
168
169                 vehicleSpeedFromLastWeek.timeBegin = amb::currentTime() - 10;
170                 vehicleSpeedFromLastWeek.timeEnd = amb::currentTime();
171
172                 PropertyList requestList;
173                 requestList.push_back(VehicleProperty::VehicleSpeed);
174                 requestList.push_back(VehicleProperty::EngineSpeed);
175
176                 vehicleSpeedFromLastWeek.properties = requestList;
177                 vehicleSpeedFromLastWeek.completed = [](AsyncRangePropertyReply* reply)
178                 {
179                         std::list<AbstractPropertyType*> values = reply->values;
180                         for(auto itr = values.begin(); itr != values.end(); itr++)
181                         {
182                                 auto val = *itr;
183                                 DebugOut(1)<<"Value from past: ("<<val->name<<"): "<<val->toString()<<" time: "<<val->timestamp<<endl;
184                         }
185
186                         delete reply;
187                 };
188
189                 routingEngine->getRangePropertyAsync(vehicleSpeedFromLastWeek);
190
191                 return 0;
192         };
193
194         g_timeout_add(10000, getRangedCb, routingEngine);
195 }
196
197 void ExampleSink::propertyChanged(AbstractPropertyType* value, const string &uuid)
198 {
199         VehicleProperty::Property property = value->name;
200         DebugOut()<<property<<" value: "<<value->toString()<<endl;
201 }
202
203 const string ExampleSink::uuid()
204 {
205         return "f7e4fab2-eb73-4842-9fb0-e1c550eb2d81";
206 }