automotive-message-broker  0.12
 All Classes Functions Variables Typedefs Enumerations Enumerator 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 
149 
154  bool success;
155 
160  TimedOutCallback timedout;
161 
167 
168 private:
169  void setTimeout();
170  GSource* timeoutSource;
171 };
172 
180 {
181 public:
183  :value(NULL)
184  {
185 
186  }
187 
189  :AsyncPropertyRequest(request), value(NULL)
190  {
191 
192  }
193 
194  virtual ~AsyncSetPropertyRequest()
195  {
196 
197  }
198 
203 };
204 
210 {
211 public:
213  :zone(Zone::None), timeBegin(0), timeEnd(0), sequenceBegin(-1), sequenceEnd(-1)
214  {
215 
216  }
217 
219  {
220  this->properties = request.properties;
221  this->completed = request.completed;
222  this->timeBegin = request.timeBegin;
223  this->timeEnd = request.timeEnd;
224  this->sequenceBegin = request.sequenceBegin;
225  this->sequenceEnd = request.sequenceEnd;
226  this->sourceUuid = request.sourceUuid;
227  this->zone = request.zone;
228  }
229 
230  virtual ~AsyncRangePropertyRequest() {}
231 
235  PropertyList properties;
236 
240  std::string sourceUuid;
241 
245  Zone::Type zone;
246 
251  GetRangedPropertyCompletedSignal completed;
252 
257  double timeBegin;
258 
263  double timeEnd;
264 
269  int32_t sequenceBegin;
270 
275  int32_t sequenceEnd;
276 
280  std::string pid;
281 };
282 
289 {
290 public:
292  :AsyncRangePropertyRequest(request), success(false)
293  {
294 
295  }
296 
298  {
299  for(auto itr = values.begin(); itr != values.end(); itr++)
300  {
301  delete (*itr);
302  }
303 
304  values.clear();
305  }
306 
311 
315  std::list<AbstractPropertyType*> values;
316 
320  bool success;
321 };
322 
324 {
325 public:
326  typedef std::function<void (AbstractPropertyType* value)> PropertyChangedType;
327 
328  AbstractRoutingEngine(std::map<std::string, std::string> configuration):mConfig(configuration) {}
329  virtual ~AbstractRoutingEngine();
330 
331  virtual void registerSource(AbstractSource* src) = 0;
332  virtual void updateSupported(PropertyList added, PropertyList removed, AbstractSource* source) = 0;
333 
334 
336  void updateProperty(VehicleProperty::Property property, AbstractPropertyType* value, std::string uuid)
337  {
338  DebugOut(DebugOut::Warning)<<"updateProperty(VehicleProperty::Property,AbstractPropertyType*,std::string) is deprecated. use new updateProperty(AbstractPropertyType*, const std::string &)"<<endl;
339  updateProperty(value,uuid);
340  }
341 
342  virtual void updateProperty(AbstractPropertyType* value, const std::string &uuid) = 0;
343  virtual PropertyList supported() = 0;
344 
346  virtual void registerSink(AbstractSink* self) = 0;
347  virtual void unregisterSink(AbstractSink* self) = 0;
348 
354  virtual std::list<std::string> sourcesForProperty(const VehicleProperty::Property & property) = 0;
355 
372 
402  virtual AsyncRangePropertyReply * getRangePropertyAsync(AsyncRangePropertyRequest request) = 0;
403 
412  virtual AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request) = 0;
413 
421  virtual uint subscribeToProperty(const VehicleProperty::Property & propertyName, PropertyChangedType callback, std::string pid="") = 0;
422 
427  virtual void unsubscribeToProperty(uint handle) = 0;
428 
446  virtual bool subscribeToProperty(const VehicleProperty::Property & propertyName, AbstractSink* self) = 0;
447 
454  virtual bool subscribeToProperty(const VehicleProperty::Property & propertyName, const std::string & sourceUuidFilter, AbstractSink *self) = 0;
455 
463  virtual bool subscribeToProperty(const VehicleProperty::Property & propertyName, const std::string & sourceUuidFilter, Zone::Type zoneFilter, AbstractSink *self) = 0;
464 
465  virtual bool unsubscribeToProperty(const VehicleProperty::Property &, AbstractSink* self) = 0;
466 
467  virtual PropertyInfo getPropertyInfo(const VehicleProperty::Property &, const std::string & sourceUuid) = 0;
468 
469 protected:
470  std::map<std::string, std::string> mConfig;
471 };
472 
473 #endif // ABSTRACTROUTINGENGINE_H
static const Property NoValue
Various property types:
Definition: vehicleproperty.h:353
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:263
Definition: abstractpropertytype.h:69
GetPropertyCompletedSignal completed
completed the callback when the request has been completed.
Definition: abstractroutingengine.h:99
Definition: abstractroutingengine.h:323
TimedOutCallback timedout
timed out callback is called when the reply times out. This is so sources can avoid using this reply ...
Definition: abstractroutingengine.h:160
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:209
bool success
success indicates if the request was successfull or not. True means success. False means fail and the...
Definition: abstractroutingengine.h:154
bool success
success this will be true if the request was successful. If not, this is false and error is set...
Definition: abstractroutingengine.h:320
double timeBegin
timeBegin set this to request values for the specified property beggining at this time...
Definition: abstractroutingengine.h:257
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:275
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:315
virtual void registerSink(AbstractSink *self)=0
sinks:
PropertyList properties
properties list of properties to request
Definition: abstractroutingengine.h:235
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:269
virtual AsyncPropertyReply * getPropertyAsync(AsyncPropertyRequest request)=0
Error error
error contains the error if the request was not successful.\
Definition: abstractroutingengine.h:166
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:179
Definition: propertyinfo.hpp:7
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:240
virtual void unsubscribeToProperty(uint handle)=0
unsubscribeToProperty
GetRangedPropertyCompletedSignal completed
completed callback that is called when the ranged request is complete. The reply from this request is...
Definition: abstractroutingengine.h:251
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:288
Zone::Type zone
zone if the sink wishes to request a specific zone, this should be set to the desired zone ...
Definition: abstractroutingengine.h:245
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 std::list< std::string > sourcesForProperty(const VehicleProperty::Property &property)=0
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:280
void updateProperty(VehicleProperty::Property property, AbstractPropertyType *value, std::string uuid)
Deprecated:
Definition: abstractroutingengine.h:336
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:310
AbstractPropertyType * value
value the new value to set the property to.
Definition: abstractroutingengine.h:202
uint timeout
use to specify a timeout in ms for the request. When a timeout occurs, the 'completed' callback will ...
Definition: abstractroutingengine.h:106
Definition: debugout.h:33
AbstractPropertyType * value
value of the reply. This may be null if success = false. This is owned by the source.
Definition: abstractroutingengine.h:148
Definition: abstractsource.h:41