automotive-message-broker  0.13.1
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups 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>
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>
267 {
268  if(d)
269  d->init();
270 }
271 
272 #endif // _AMBPLUGIN_H_
273