automotive-message-broker  0.13
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Modules 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
static const Property NoValue
Various property types:
Definition: vehicleproperty.h:431
double timeEnd
timeEnd Set this to request values for the specified property beggining at this time. Time is seconds\ since the unix epoc. Set this to '0' if you do not want values within a time range.
Definition: abstractroutingengine.h:306
Definition: abstractpropertytype.h:70
GetPropertyCompletedSignal completed
completed the callback when the request has been completed.
Definition: abstractroutingengine.h:99
Definition: abstractroutingengine.h:366
TimedOutCallback timedout
timed out callback is called when the reply times out. This is so sources can avoid using this reply ...
Definition: abstractroutingengine.h:200
std::string pid
pid requesting process id
Definition: abstractroutingengine.h:111
The AsyncRangePropertyRequest class is used by sinks to request values within a time or sequence rang...
Definition: abstractroutingengine.h:249
bool success
success indicates if the request was successfull or not. True means success. False means fail and the...
Definition: abstractroutingengine.h:194
bool success
success this will be true if the request was successful. If not, this is false and error is set...
Definition: abstractroutingengine.h:363
double timeBegin
timeBegin Set this to request values for the specified property beggining at this time...
Definition: abstractroutingengine.h:299
Zone::Type zoneFilter
zoneFilter the requesting sink should use this if he wants to filter on a specific zone ...
Definition: abstractroutingengine.h:94
int32_t sequenceEnd
sequenceEnd set this to request values with a sequence <= to the sequenceEnd value. Set to -1 if you don't want values within a sequence ranges.
Definition: abstractroutingengine.h:318
Error
The Error enum.
Definition: abstractroutingengine.h:137
std::list< AbstractPropertyType * > values
values if the request was successful, this will contain a list of values meeting the criteria of the ...
Definition: abstractroutingengine.h:358
static const int Warning
Warning use when non-essential functionality is bocked, or when workarounds exist.
Definition: debugout.h:69
virtual void registerSink(AbstractSink *self)=0
sinks:
static std::string errorToStr(Error err)
errorToStr returns string representing the Error
Definition: abstractroutingengine.h:148
PropertyList properties
properties list of properties to request
Definition: abstractroutingengine.h:275
The AsyncPropertyReply class is used by sources to reply to Get and Set operations. The source should set success to true if the call is successful or 'false' if the request was not successful and set 'error' to the appropriate error.
Definition: abstractroutingengine.h:123
int32_t sequenceBegin
sequenceBegin set this to request values with a sequence >= to the sequenceBegin value. Set to -1 if you don't want values within a sequence ranges.
Definition: abstractroutingengine.h:312
virtual AsyncPropertyReply * getPropertyAsync(AsyncPropertyRequest request)=0
Error error
error contains the error if the request was not successful.\
Definition: abstractroutingengine.h:206
The AsyncSetPropertyRequest class is used by sinks to set a property to the 'value'. The source will reply with a AsyncPropertyReply containing the new value or an error.
Definition: abstractroutingengine.h:219
Definition: propertyinfo.hpp:6
std::string sourceUuid
sourceUuid if the sink wishes to request a specific source, this should be set to the uuid of the sou...
Definition: abstractroutingengine.h:280
virtual void unsubscribeToProperty(uint handle)=0
unsubscribeToProperty
GetRangedPropertyCompletedSignal completed
completed callback 'completed' is called when the ranged request is complete. The reply from this req...
Definition: abstractroutingengine.h:292
The AsyncPropertyRequest class is used by sinks to request property values.
Definition: abstractroutingengine.h:50
VehicleProperty::Property property
property property to request.
Definition: abstractroutingengine.h:84
The AsyncRangePropertyReply class is used by a source to reply to an AsyncRangePropertyRequest. The source should set success to 'true' and populate the 'values' member if the request was successful. If the request is not successful, 'success' should be set to 'false' and the 'error' member should be set.
Definition: abstractroutingengine.h:331
Zone::Type zone
zone if the sink wishes to request a specific zone, this should be set to the desired zone ...
Definition: abstractroutingengine.h:285
static Error strToError(std::string err)
strToError returns Error representing the string
Definition: abstractroutingengine.h:168
std::string sourceUuidFilter
sourceUuidFilter the requesting sink should use this to filter on a specific source or leave blank to...
Definition: abstractroutingengine.h:89
Definition: abstractsink.h:40
virtual uint subscribeToProperty(const VehicleProperty::Property &propertyName, PropertyChangedType callback, std::string pid="")=0
subscribeToProperty subscribes to propertyName. Value changes will be passed to callback.
std::string pid
pid requesting process id
Definition: abstractroutingengine.h:323
void updateProperty(VehicleProperty::Property property, AbstractPropertyType *value, std::string uuid)
Deprecated:
Definition: abstractroutingengine.h:379
AsyncPropertyReply::Error error
error this is set if there was an error in the request. "success" will also be set to false...
Definition: abstractroutingengine.h:353
AbstractPropertyType * value
value the new value to set the property to.
Definition: abstractroutingengine.h:242
uint timeout
use to specify a timeout in ms for the request. When a timeout occurs, the 'completed' callback will ...
Definition: abstractroutingengine.h:106
virtual void getRangePropertyAsync(AsyncRangePropertyRequest request)=0
getRangePropertyAsync is used for getting a range of properties that are within the specified time or...
The DebugOut class represents a class used for outputing debug information The specified debug level ...
Definition: debugout.h:57
virtual std::vector< std::string > sourcesForProperty(const VehicleProperty::Property &property)=0
AbstractPropertyType * value
value of the reply. This may be null if success = false. This is owned by the source.
Definition: abstractroutingengine.h:188
Definition: abstractsource.h:41