automotive-message-broker  0.14.803
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
ambpluginimpl.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 #ifndef _AMBPLUGINIMPL_H_
20 #define _AMBPLUGINIMPL_H_
21 
22 #include "abstractsource.h"
23 
37 {
38 
39 public:
45  AmbPluginImpl(AbstractRoutingEngine* re, const map<string, string>& config, AbstractSource &parent);
46  virtual ~AmbPluginImpl() { } /*LCOV_EXCL_LINE*/
47 
48  // aka AbstractSource:
49 public:
50 
56  virtual void getPropertyAsync(AsyncPropertyReply *reply);
57 
65 
72  virtual AsyncPropertyReply *setProperty(const AsyncSetPropertyRequest& request );
73 
79  virtual void subscribeToPropertyChanges(const VehicleProperty::Property& property);
80 
85  virtual void unsubscribeToPropertyChanges(const VehicleProperty::Property& property);
86 
91  virtual PropertyList supported() const;
92 
97  virtual int supportedOperations() const;
98 
105  virtual PropertyInfo getPropertyInfo(const VehicleProperty::Property & property);
106 
107  // aka AbstractSink:
108 public:
109 
113  virtual const std::string uuid() const = 0;
114 
121 
126  virtual void supportedChanged(const PropertyList& supportedProperties);
127 
132  virtual void init();
133 
137  template <typename T>
138  void setValue(std::shared_ptr<AbstractPropertyType> property, T value)
139  {
140  if(property->value<T>() == value)
141  {
142  return;
143  }
144 
145  property->setValue(value);
146  routingEngine->updateProperty(property.get(), source.uuid());
147  }
148 
149 
150 protected:
151 
157  virtual AbstractPropertyType* findPropertyType(const VehicleProperty::Property& propertyName, const Zone::Type& zone = Zone::None);
158 
164  std::shared_ptr<AbstractPropertyType> addPropertySupport(Zone::Type zone, std::function<AbstractPropertyType* (void)> typeFactory, std::string sourceUuid="");
165 
166  template <class T>
167  std::shared_ptr<AbstractPropertyType> addPropertySupport(Zone::Type zone)
168  {
169  auto typeFactory = [](){
170  return new T;
171  };
172  return addPropertySupport(zone, typeFactory);
173  }
174 
175  //
176  // data:
177  //
178 
182  AbstractSource& source;
183 
189 
193  typedef std::map< Zone::Type, std::shared_ptr<AbstractPropertyType> > ZonePropertyType;
194 
199  std::map< VehicleProperty::Property, ZonePropertyType > properties;
200 
204  std::map< std::string, std::string> configuration;
205 };
206 
207 #endif // _AMBPLUGINIMPL_H_
208