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
22 #include <abstractsource.h>
23 #include "ambpluginimpl.h"
28 * \brief Contains common code used in plugins for Automotive message broker(AMB).
32 * AmbPlugin class contains common code used in plugins for Automotive message broker(AMB).
33 * For the AMB library API please visit \ref libamb</a>.
37 * Example of the minimal code to write a new plugin using AmbPlugin:
40 * #include "ambpluginimpl.h"
42 * class MyPlugin: public AmbPluginImpl {
45 * MyPlugin(AbstractRoutingEngine* re, const std::map<std::string, std::string>& config, AbstractSource& parent);
48 * const std::string uuid() const { return "plugin_uuid"; }
51 * // library exported function for plugin loader
52 * extern "C" void create(AbstractRoutingEngine* routingengine, std::map<std::string, std::string> config)
54 * new AmbPlugin<MyPlugin>(routingengine, config);
62 class AmbPlugin : public AbstractSource {
68 static_assert(std::is_base_of<AmbPluginImpl, T>::value, "AmbPluginImpl has to be a base of T");
72 * \param re AbstractRoutingEngine
73 * \param config Map of the configuration string values loaded on startup from AMB configuration file
75 AmbPlugin(AbstractRoutingEngine* re, const std::map<std::string, std::string>& config);
76 virtual ~AmbPlugin() {}
78 // from AbstractSource:
82 * \brief getPropertyAsync is called when a sink requests the value for given property.
83 * This is only called if the source supports the Get operation.
84 * \param reply the reply variable. @see AsyncPropertyReply
86 virtual void getPropertyAsync(AsyncPropertyReply *reply);
89 * \brief getRangePropertyAsync is called when a sink requests a series of values for a given
90 * property within a specified time or sequencial range. This will only be called if the source
91 * support the Ranged Operation.
92 * \param reply is the reply variable. @see AsyncRangePropertyReply
94 virtual void getRangePropertyAsync(AsyncRangePropertyReply *reply);
97 * \brief setProperty is called when a sink requests to set a value for a given property.
98 * This is only called if the source supports the Set Operation.
99 * \param request the requested property to set.
100 * \return returns a pointer to the new value for the property.
102 virtual AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request);
105 * \brief subscribeToPropertyChanges is called when a sink requests a subscription. Source plugins
106 * can keep track of subscriptions and may wish to sleep if there are no subscriptions.
107 * \param property the property that is being subscribed.
109 virtual void subscribeToPropertyChanges(VehicleProperty::Property property);
112 * \brief unsubscribeToPropertyChanges is called when a sink requests to unsubscribe from a given property's changes.
113 * \param property the property to unsubscribe to
115 virtual void unsubscribeToPropertyChanges(VehicleProperty::Property property);
118 * \brief supported is called by the routingEngine to understand what properties this source supports
119 * \return returns a list of supported properties. If the the supported properties changed, the source should call AbstractRoutingEngine::setSupported.
121 virtual PropertyList supported();
124 * \brief supportedOperations
125 * \return returns the supported operations.
127 virtual int supportedOperations();
130 * \brief getPropertyInfo used to return specific information about a property.
131 * The source should override this otherwise a PropertyInfo::invalid() will be returned for the property.
132 * \param property the property to get info for.
133 * \return a PropertyInfo object.
135 virtual PropertyInfo getPropertyInfo(const VehicleProperty::Property & property);
140 /*! uuid() is a unique identifier
141 * \return A guid-style unique identifier
143 virtual const string uuid();
145 /*! propertyChanged is called when a subscribed to property changes.
146 * \param value value of the property that changed. this is a temporary pointer that will be destroyed.
147 * Do not destroy it. If you need to store the value use value.anyValue(), value.value<T>() or
148 * value->copy() to copy.
150 virtual void propertyChanged(AbstractPropertyType* value);
152 /*! supportedChanged() is called when the supported properties changes
153 * \param supportedProperties the new list of supported properties.
155 virtual void supportedChanged(const PropertyList & supportedProperties);
158 // AmbPlugin's own methods
162 * Second phase of the plugin initialization.
170 * \brief AmbPlugin class private implementation
172 std::unique_ptr<T> d;
175 //----------------------------------------------------------------------------
176 // Function implementations
177 //----------------------------------------------------------------------------
179 //----------------------------------------------------------------------------
181 //----------------------------------------------------------------------------
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))
192 void AmbPlugin<T>::getPropertyAsync(AsyncPropertyReply *reply)
195 d->getPropertyAsync(reply);
199 void AmbPlugin<T>::getRangePropertyAsync(AsyncRangePropertyReply *reply)
202 d->getRangePropertyAsync(reply);
206 AsyncPropertyReply* AmbPlugin<T>::setProperty(AsyncSetPropertyRequest request)
209 return d->setProperty(request);
214 void AmbPlugin<T>::subscribeToPropertyChanges(VehicleProperty::Property property)
217 d->subscribeToPropertyChanges(property);
221 void AmbPlugin<T>::unsubscribeToPropertyChanges(VehicleProperty::Property property)
224 return d->unsubscribeToPropertyChanges(property);
228 PropertyList AmbPlugin<T>::supported()
230 return d ? d->supported() : PropertyList();
234 int AmbPlugin<T>::supportedOperations()
236 return d ? d->supportedOperations() : 0;
240 PropertyInfo AmbPlugin<T>::getPropertyInfo(const VehicleProperty::Property &property)
242 return d ? d->getPropertyInfo(property) : PropertyInfo::invalid();
246 const string AmbPlugin<T>::uuid()
248 return d ? d->uuid() : "";
252 void AmbPlugin<T>::propertyChanged(AbstractPropertyType* value)
255 d->propertyChanged(value);
259 void AmbPlugin<T>::supportedChanged(const PropertyList &supportedProperties)
262 d->supportedChanged(supportedProperties);
266 void AmbPlugin<T>::init()
272 #endif // _AMBPLUGIN_H_