[tools] ambctl test script
[profile/ivi/automotive-message-broker.git] / lib / 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
24 /*! \addtogroup ivipocbase
25  *  @{
26  */
27
28 /*!
29  * \brief AmbPlugin private class implementation - base class for all plugin implementations.
30  *
31  * Contains common code used in all IviPoC II plugins for Automotive message broker(AMB).
32  * For the AMB library API please visit <a href="https://github.com/otcshare/automotive-message-broker">Automotive message broker web page</a>.
33  *
34  * \class AmbPluginImpl
35  */
36 class AmbPluginImpl
37 {
38
39 public:
40         /*!
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
44          */
45         AmbPluginImpl(AbstractRoutingEngine* re, const map<string, string>& config, AbstractSource &parent);
46         virtual ~AmbPluginImpl() { } /*LCOV_EXCL_LINE*/
47
48         //  aka AbstractSource:
49 public:
50
51         /*!
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.
55          */
56         virtual void getPropertyAsync(AsyncPropertyReply *reply);
57
58         /*!
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.
63          */
64         virtual void getRangePropertyAsync(AsyncRangePropertyReply *reply);
65
66         /*!
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.
71          */
72         virtual AsyncPropertyReply *setProperty(const AsyncSetPropertyRequest& request );
73
74         /*!
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.
78          */
79         virtual void subscribeToPropertyChanges(const VehicleProperty::Property& property);
80
81         /*!
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
84          */
85         virtual void unsubscribeToPropertyChanges(const VehicleProperty::Property& property);
86
87         /*!
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.
90          */
91         virtual PropertyList supported() const;
92
93         /*!
94          * \brief supportedOperations
95          * \return returns the supported operations.
96          */
97         virtual int supportedOperations() const;
98
99         /*!
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.
104          */
105         virtual PropertyInfo getPropertyInfo(const VehicleProperty::Property & property);
106
107         // aka AbstractSink:
108 public:
109
110         /*! uuid() is a unique identifier
111           * @return a guid-style unique identifier
112           */
113         virtual const std::string uuid() const = 0;
114
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.
119           */
120         virtual void propertyChanged(AbstractPropertyType* value);
121
122         /*! supportedChanged() is called when the supported properties changes
123          * \fn supportedChanged
124          * \param supportedProperties the new list of supported properties.
125          */
126         virtual void supportedChanged(const PropertyList& supportedProperties);
127
128         /*!
129          * Second phase of the plugin initialization.
130          * \fn init
131          */
132         virtual void init();
133
134 protected:
135
136         /*! Finds property type in #properties
137          * \param propertyName Name of the property to be found.
138          * \param zone Zone of the property to be found.
139          * \return AbstractPropertyType* if signal exits otherwise nullptr(in this case we do not know its datatype)
140          */
141         virtual AbstractPropertyType* findPropertyType(const VehicleProperty::Property& propertyName, const Zone::Type& zone = Zone::None);
142
143         /*! Registers property in AMB
144          * \param zone Zone of the property to be registered.
145          * \param typeFactory Function to be used to create instance of the AbstractPropertyType for registered property
146          * \return AbstractPropertyType* if signal exits otherwise nullptr(in this case we do not know its datatype)
147          */
148         std::shared_ptr<AbstractPropertyType> addPropertySupport(Zone::Type zone, std::function<AbstractPropertyType* (void)> typeFactory, std::string sourceUuid="");
149
150         template <class T>
151         std::shared_ptr<AbstractPropertyType> addPropertySupport(Zone::Type zone)
152         {
153                 auto typeFactory = [](){
154                         return new T;
155                 };
156                 return addPropertySupport(zone, typeFactory);
157         }
158
159         //
160         // data:
161         //
162
163         /*! AmbPlugin instance
164          * \property parent
165          */
166         AbstractSource& source;
167
168         /*!
169          * AbstractRoutingEngine instance
170          * \property routingEngine
171          */
172         AbstractRoutingEngine* routingEngine;
173
174         /*! Helper typedef
175          * \internal
176          */
177         typedef std::map< Zone::Type, std::shared_ptr<AbstractPropertyType> > ZonePropertyType;
178
179         /*!
180          * Supported property values map
181          * \property properties
182          */
183         std::map< VehicleProperty::Property, ZonePropertyType > properties;
184
185         /*!
186           * configuration
187           */
188         std::map< std::string, std::string> configuration;
189 };
190
191 #endif // _AMBPLUGINIMPL_H_
192
193 /** @} */