automotive-message-broker  0.13.1
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
abstractroutingengine.h
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 #ifndef ABSTRACTROUTINGENGINE_H
21 #define ABSTRACTROUTINGENGINE_H
22 
23 #include <sys/types.h>
24 #include <stdlib.h>
25 #include <boost/any.hpp>
26 #include <functional>
27 #include <string>
28 #include <time.h>
29 
30 #include "vehicleproperty.h"
31 #include "abstractpropertytype.h"
32 #include "propertyinfo.hpp"
33 
34 class AbstractSink;
35 class AbstractSource;
36 class AsyncPropertyReply;
39 
40 
41 typedef std::function<void (AsyncPropertyReply*)> GetPropertyCompletedSignal;
42 typedef std::function<void (AsyncRangePropertyReply*)> GetRangedPropertyCompletedSignal;
43 typedef std::function<void (AsyncPropertyReply*)> TimedOutCallback;
44 
51 {
52 public:
55  {
56 
57  }
58 
60  {
61  this->property = request.property;
62  this->completed = request.completed;
63  this->sourceUuidFilter = request.sourceUuidFilter;
64  this->zoneFilter = request.zoneFilter;
65  this->timeout = request.timeout;
66  }
67 
68  AsyncPropertyRequest & operator = (const AsyncPropertyRequest & other)
69  {
70  this->property = other.property;
71  this->completed = other.completed;
72  this->sourceUuidFilter = other.sourceUuidFilter;
73  this->zoneFilter = other.zoneFilter;
74  this->timeout = other.timeout;
75 
76  return *this;
77  }
78 
79  virtual ~AsyncPropertyRequest() { }
80 
84  VehicleProperty::Property property;
85 
89  std::string sourceUuidFilter;
90 
94  Zone::Type zoneFilter;
95 
99  GetPropertyCompletedSignal completed;
100 
106  uint timeout;
107 
111  std::string pid;
112 };
113 
124 {
125 public:
127 
129 
131 
132  virtual ~AsyncPropertyReply();
133 
137  enum Error {
138  NoError = 0,
139  Timeout,
140  InvalidOperation,
141  PermissionDenied,
142  ZoneNotSupported
143  };
144 
148  static std::string errorToStr(Error err)
149  {
150  if(err == NoError)
151  return "NoError";
152  else if(err == Timeout)
153  return "Timeout";
154  else if(err == InvalidOperation)
155  return "InvalidOperation";
156  else if(err == PermissionDenied)
157  return "PermissionDenied";
158  else if(err == ZoneNotSupported)
159  return "ZoneNotSupported";
160 
161  DebugOut(DebugOut::Warning) << "Could not translate error: " << err << endl;
162  return "";
163  }
164 
168  static Error strToError(std::string err)
169  {
170  if(err == "NoError")
171  return NoError;
172  else if(err == "Timeout")
173  return Timeout;
174  else if(err == "InvalidOperation")
175  return InvalidOperation;
176  else if(err == "PermissionDenied")
177  return PermissionDenied;
178  else if(err == "ZoneNotSupported")
179  return ZoneNotSupported;
180 
181  DebugOut(DebugOut::Warning) << "Could not translate error string: " << err << endl;
182  return NoError;
183  }
184 
189 
194  bool success;
195 
200  TimedOutCallback timedout;
201 
207 
208 private:
209  void setTimeout();
210  GSource* timeoutSource;
211 };
212 
220 {
221 public:
223  :value(NULL)
224  {
225 
226  }
227 
229  :AsyncPropertyRequest(request), value(NULL)
230  {
231 
232  }
233 
234  virtual ~AsyncSetPropertyRequest()
235  {
236 
237  }
238 
243 };
244 
250 {
251 public:
253  :zone(Zone::None), timeBegin(0), timeEnd(0), sequenceBegin(-1), sequenceEnd(-1)
254  {
255 
256  }
257 
259  {
260  this->properties = request.properties;
261  this->completed = request.completed;
262  this->timeBegin = request.timeBegin;
263  this->timeEnd = request.timeEnd;
264  this->sequenceBegin = request.sequenceBegin;
265  this->sequenceEnd = request.sequenceEnd;
266  this->sourceUuid = request.sourceUuid;
267  this->zone = request.zone;
268  }
269 
270  virtual ~AsyncRangePropertyRequest() {}
271 
275  PropertyList properties;
276 
280  std::string sourceUuid;
281 
285  Zone::Type zone;
286 
292  GetRangedPropertyCompletedSignal completed;
293 
299  double timeBegin;
300 
306  double timeEnd;
307 
312  int32_t sequenceBegin;
313 
318  int32_t sequenceEnd;
319 
323  std::string pid;
324 };
325 
332 {
333 public:
335  :AsyncRangePropertyRequest(request), success(false)
336  {
337 
338  }
339 
341  {
342  for(auto itr = values.begin(); itr != values.end(); itr++)
343  {
344  delete (*itr);
345  }
346 
347  values.clear();
348  }
349 
354 
358  std::list<AbstractPropertyType*> values;
359 
363  bool success;
364 };
365 
367 {
368 public:
369  typedef std::function<void (AbstractPropertyType* value)> PropertyChangedType;
370 
371  AbstractRoutingEngine(std::map<std::string, std::string> configuration):mConfig(configuration) {}
372  virtual ~AbstractRoutingEngine();
373 
374  virtual void registerSource(AbstractSource* src) = 0;
375  virtual void updateSupported(PropertyList added, PropertyList removed, AbstractSource* source) = 0;
376 
377 
379  void updateProperty(VehicleProperty::Property property, AbstractPropertyType* value, std::string uuid)
380  {
381  DebugOut(DebugOut::Warning)<<"updateProperty(VehicleProperty::Property,AbstractPropertyType*,std::string) is deprecated. use new updateProperty(AbstractPropertyType*, const std::string &)"<<endl;
382  updateProperty(value,uuid);
383  }
384 
385  virtual void updateProperty(AbstractPropertyType* value, const std::string &uuid) = 0;
386  virtual PropertyList supported() = 0;
387 
389  virtual void registerSink(AbstractSink* self) = 0;
390  virtual void unregisterSink(AbstractSink* self) = 0;
391 
397  virtual std::vector<std::string> sourcesForProperty(const VehicleProperty::Property & property) = 0;
398 
416 
446  virtual void getRangePropertyAsync(AsyncRangePropertyRequest request) = 0;
447 
456  virtual AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request) = 0;
457 
465  virtual uint subscribeToProperty(const VehicleProperty::Property & propertyName, PropertyChangedType callback, std::string pid="") = 0;
466 
471  virtual void unsubscribeToProperty(uint handle) = 0;
472 
491  virtual bool subscribeToProperty(const VehicleProperty::Property & propertyName, AbstractSink* self) = 0;
492 
499  virtual bool subscribeToProperty(const VehicleProperty::Property & propertyName, const std::string & sourceUuidFilter, AbstractSink *self) = 0;
500 
508  virtual bool subscribeToProperty(const VehicleProperty::Property & propertyName, const std::string & sourceUuidFilter, Zone::Type zoneFilter, AbstractSink *self) = 0;
509 
510  virtual bool unsubscribeToProperty(const VehicleProperty::Property &, AbstractSink* self) = 0;
511 
512  virtual PropertyInfo getPropertyInfo(const VehicleProperty::Property &, const std::string & sourceUuid) = 0;
513 
514 protected:
515  std::map<std::string, std::string> mConfig;
516 };
517 
518 #endif // ABSTRACTROUTINGENGINE_H