automotive-message-broker  0.13
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
ambplugin.h
Go to the documentation of this file.
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 #ifndef _AMBPLUGIN_H_
20 #define _AMBPLUGIN_H_
21 
22 #include <abstractsource.h>
23 #include "ambpluginimpl.h"
24 #include <string>
25 
61 template<class T>
62 class AmbPlugin : public AbstractSource {
63 
68  static_assert(std::is_base_of<AmbPluginImpl, T>::value, "AmbPluginImpl has to be a base of T");
69 
70 public:
75  AmbPlugin(AbstractRoutingEngine* re, const std::map<std::string, std::string>& config);
76  virtual ~AmbPlugin() {}
77 
78  // from AbstractSource:
79 public:
80 
86  virtual void getPropertyAsync(AsyncPropertyReply *reply);
87 
95 
103 
109  virtual void subscribeToPropertyChanges(VehicleProperty::Property property);
110 
115  virtual void unsubscribeToPropertyChanges(VehicleProperty::Property property);
116 
121  virtual PropertyList supported();
122 
127  virtual int supportedOperations();
128 
135  virtual PropertyInfo getPropertyInfo(const VehicleProperty::Property & property);
136 
137  // from AbstractSink
138 public:
139 
143  virtual const string uuid();
144 
150  virtual void propertyChanged(AbstractPropertyType* value);
151 
155  virtual void supportedChanged(const PropertyList & supportedProperties);
156 
157 
158  // AmbPlugin's own methods
159 public:
160 
165  void init();
166 
167 private:
168 
172  std::unique_ptr<T> d;
173 };
174 
175 //----------------------------------------------------------------------------
176 // Function implementations
177 //----------------------------------------------------------------------------
178 
179 //----------------------------------------------------------------------------
180 // AmbPlugin
181 //----------------------------------------------------------------------------
182 
183 template<typename T>
184 AmbPlugin<T>::AmbPlugin(AbstractRoutingEngine* re, const std::map<std::string, std::string>& config) :
185  AbstractSource(re, config),
186  d(new T(re, config, *this))
187 {
188 
189 }
190 
191 template<typename T>
193 {
194  if(d)
195  d->getPropertyAsync(reply);
196 }
197 
198 template<typename T>
200 {
201  if(d)
202  d->getRangePropertyAsync(reply);
203 }
204 
205 template<typename T>
207 {
208  if(d)
209  return d->setProperty(request);
210  return nullptr;
211 }
212 
213 template<typename T>
214 void AmbPlugin<T>::subscribeToPropertyChanges(VehicleProperty::Property property)
215 {
216  if(d)
217  d->subscribeToPropertyChanges(property);
218 }
219 
220 template<typename T>
221 void AmbPlugin<T>::unsubscribeToPropertyChanges(VehicleProperty::Property property)
222 {
223  if(d)
224  return d->unsubscribeToPropertyChanges(property);
225 }
226 
227 template<typename T>
228 PropertyList AmbPlugin<T>::supported()
229 {
230  return d ? d->supported() : PropertyList();
231 }
232 
233 template<typename T>
235 {
236  return d ? d->supportedOperations() : 0;
237 }
238 
239 template<typename T>
240 PropertyInfo AmbPlugin<T>::getPropertyInfo(const VehicleProperty::Property &property)
241 {
242  return d ? d->getPropertyInfo(property) : PropertyInfo::invalid();
243 }
244 
245 template<typename T>
246 const string AmbPlugin<T>::uuid()
247 {
248  return d ? d->uuid() : "";
249 }
250 
251 template<typename T>
253 {
254  if(d)
255  d->propertyChanged(value);
256 }
257 
258 template<typename T>
259 void AmbPlugin<T>::supportedChanged(const PropertyList &supportedProperties)
260 {
261  if(d)
262  d->supportedChanged(supportedProperties);
263 }
264 
265 template<typename T>
266 void AmbPlugin<T>::init()
267 {
268  if(d)
269  d->init();
270 }
271 
272 #endif // _AMBPLUGIN_H_
273 
virtual void unsubscribeToPropertyChanges(VehicleProperty::Property property)=0
unsubscribeToPropertyChanges is called when a sink requests to unsubscribe from a given property's ch...
virtual const string uuid()=0
Pure virtual methods:
Definition: abstractpropertytype.h:70
Definition: abstractroutingengine.h:366
virtual PropertyList supported()=0
supported
virtual void subscribeToPropertyChanges(VehicleProperty::Property property)=0
subscribeToPropertyChanges is called when a sink requests a subscription. Source plugins can keep tra...
virtual void getPropertyAsync(AsyncPropertyReply *reply)=0
pure virtual methods:
Definition: ambplugin.h:62
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
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
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
virtual PropertyInfo getPropertyInfo(const VehicleProperty::Property &property)=0
getPropertyInfo used to return specific information about a property
virtual AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request)=0
setProperty is called when a sink requests to set a value for a given property. This is only called i...
virtual void getRangePropertyAsync(AsyncRangePropertyReply *reply)=0
getRangePropertyAsync is called when a sink requests a series of values for a given property within a...
virtual void propertyChanged(AbstractPropertyType *value)
propertyChanged is called when a subscribed to property changes.
Definition: abstractsink.h:60
static PropertyInfo invalid()
Definition: propertyinfo.hpp:59
virtual int supportedOperations()=0
supportedOperations
virtual void supportedChanged(const PropertyList &supportedProperties)=0
Definition: abstractsource.h:41