2 Copyright (C) 2012 Intel Corporation
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.
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.
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
19 #ifndef _AMBPLUGINIMPL_H_
20 #define _AMBPLUGINIMPL_H_
22 #include "abstractsource.h"
24 /*! \addtogroup libamb
29 * \brief AmbPlugin private class implementation - base class for all plugin implementations.
31 * Contains common code used in plugins for Automotive message broker(AMB).
32 * For the AMB library API please visit \ref libamb.
34 * \class AmbPluginImpl
41 * \param re AbstractRoutingEngine
42 * \param config Map of the configuration string values loaded on startup from AMB configuration file
43 * \param parent AmbPlugin instance
45 AmbPluginImpl(AbstractRoutingEngine* re, const map<string, string>& config, AbstractSource &parent);
46 virtual ~AmbPluginImpl() { } /*LCOV_EXCL_LINE*/
48 // aka AbstractSource:
52 * \brief getPropertyAsync is called when a sink requests the value for given property.
53 * This is only called if the source supports the Get operation.
54 * \param reply the reply variable.
56 virtual void getPropertyAsync(AsyncPropertyReply *reply);
59 * \brief getRangePropertyAsync is called when a sink requests a series of values for a given
60 * property within a specified time or sequencial range. This will only be called if the source
61 * support the Ranged Operation.
62 * \param reply is the reply variable.
64 virtual void getRangePropertyAsync(AsyncRangePropertyReply *reply);
67 * \brief setProperty is called when a sink requests to set a value for a given property.
68 * This is only called if the source supports the Set Operation.
69 * \param request the requested property to set.
70 * \return returns a pointer to the new value for the property.
72 virtual AsyncPropertyReply *setProperty(const AsyncSetPropertyRequest& request );
75 * \brief subscribeToPropertyChanges is called when a sink requests a subscription. Source plugins
76 * can keep track of subscriptions and may wish to sleep if there are no subscriptions.
77 * \param property the property that is being subscribed.
79 virtual void subscribeToPropertyChanges(const VehicleProperty::Property& property);
82 * \brief unsubscribeToPropertyChanges is called when a sink requests to unsubscribe from a given property's changes.
83 * \param property the property to unsubscribe to
85 virtual void unsubscribeToPropertyChanges(const VehicleProperty::Property& property);
88 * \brief supported is called by the routingEngine to understand what properties this source supports.
89 * \return returns a list of supported properties. If the the supported properties changed, the source should call AbstractRoutingEngine::setSupported.
91 virtual PropertyList supported() const;
94 * \brief supportedOperations
95 * \return returns the supported operations.
97 virtual int supportedOperations() const;
100 * \brief getPropertyInfo used to return specific information about a property.
101 * The source should override this otherwise a PropertyInfo::invalid() will be returned for the property
102 * \param property the property to get info for.
103 * \return a PropertyInfo object.
105 virtual PropertyInfo getPropertyInfo(const VehicleProperty::Property & property);
110 /*! uuid() is a unique identifier
111 * @return a guid-style unique identifier
113 virtual const std::string uuid() const = 0;
115 /*! propertyChanged is called when a subscribed to property changes.
116 * @param value value of the property that changed. this is a temporary pointer that will be destroyed.
117 * Do not destroy it. If you need to store the value use value.anyValue(), value.value<T>() or
118 * value->copy() to copy.
120 virtual void propertyChanged(AbstractPropertyType* value);
122 /*! supportedChanged() is called when the supported properties changes
123 * \fn supportedChanged
124 * \param supportedProperties the new list of supported properties.
126 virtual void supportedChanged(const PropertyList& supportedProperties);
129 * Second phase of the plugin initialization.
135 * \brief setValue of a property
137 template <typename T>
138 void setValue(std::shared_ptr<AbstractPropertyType> property, T value)
140 if(property->value<T>() == value)
145 property->setValue(value);
146 routingEngine->updateProperty(property.get(), source.uuid());
152 /*! Finds property type in #properties
153 * \param propertyName Name of the property to be found.
154 * \param zone Zone of the property to be found.
155 * \return AbstractPropertyType* if signal exits otherwise nullptr(in this case we do not know its datatype)
157 virtual AbstractPropertyType* findPropertyType(const VehicleProperty::Property& propertyName, const Zone::Type& zone = Zone::None);
159 /*! Registers property in AMB
160 * \param zone Zone of the property to be registered.
161 * \param typeFactory Function to be used to create instance of the AbstractPropertyType for registered property
162 * \return AbstractPropertyType* if signal exits otherwise nullptr(in this case we do not know its datatype)
164 std::shared_ptr<AbstractPropertyType> addPropertySupport(Zone::Type zone, std::function<AbstractPropertyType* (void)> typeFactory, std::string sourceUuid="");
167 std::shared_ptr<AbstractPropertyType> addPropertySupport(Zone::Type zone)
169 auto typeFactory = [](){
172 return addPropertySupport(zone, typeFactory);
179 /*! AmbPlugin instance
182 AbstractSource& source;
185 * AbstractRoutingEngine instance
186 * \property routingEngine
188 AbstractRoutingEngine* routingEngine;
193 typedef std::map< Zone::Type, std::shared_ptr<AbstractPropertyType> > ZonePropertyType;
196 * Supported property values map
197 * \property properties
199 std::map< VehicleProperty::Property, ZonePropertyType > properties;
204 std::map< std::string, std::string> configuration;
207 #endif // _AMBPLUGINIMPL_H_