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
20 #ifndef ABSTRACTROUTINGENGINE_H
21 #define ABSTRACTROUTINGENGINE_H
23 #include <sys/types.h>
25 #include <boost/any.hpp>
30 #include "vehicleproperty.h"
31 #include "abstractpropertytype.h"
32 #include "propertyinfo.hpp"
36 class AsyncPropertyReply;
37 class AsyncRangePropertyReply;
40 typedef std::function<void (AsyncPropertyReply*)> GetPropertyCompletedSignal;
41 typedef std::function<void (AsyncRangePropertyReply*)> GetRangedPropertyCompletedSignal;
43 class AsyncPropertyRequest
46 AsyncPropertyRequest()
47 :property(VehicleProperty::NoValue),timeout(10000)
52 AsyncPropertyRequest(const AsyncPropertyRequest &request)
54 this->property = request.property;
55 this->completed = request.completed;
56 this->sourceUuidFilter = request.sourceUuidFilter;
57 this->zoneFilter = request.zoneFilter;
58 this->timeout = request.timeout;
61 AsyncPropertyRequest & operator = (const AsyncPropertyRequest & other)
63 this->property = other.property;
64 this->completed = other.completed;
65 this->sourceUuidFilter = other.sourceUuidFilter;
66 this->zoneFilter = other.zoneFilter;
67 this->timeout = other.timeout;
72 virtual ~AsyncPropertyRequest() { }
74 VehicleProperty::Property property;
75 std::string sourceUuidFilter;
76 Zone::Type zoneFilter;
77 GetPropertyCompletedSignal completed;
81 class AsyncPropertyReply: public AsyncPropertyRequest
84 AsyncPropertyReply(const AsyncPropertyRequest &request);
86 virtual ~AsyncPropertyReply()
90 g_source_destroy(timeoutSource);
91 g_source_unref(timeoutSource);
104 * @brief value of the reply. This may be null if success = false. This is owned by the source.
106 AbstractPropertyType* value;
111 GSource* timeoutSource;
114 class AsyncSetPropertyRequest: public AsyncPropertyRequest
117 AsyncSetPropertyRequest()
123 AsyncSetPropertyRequest(const AsyncPropertyRequest &request)
124 :AsyncPropertyRequest(request), value(NULL)
129 virtual ~AsyncSetPropertyRequest() { }
131 AbstractPropertyType* value;
134 class AsyncRangePropertyRequest
137 AsyncRangePropertyRequest()
138 :timeBegin(0), timeEnd(0), sequenceBegin(-1), sequenceEnd(-1)
143 AsyncRangePropertyRequest(const AsyncRangePropertyRequest &request)
146 this->properties = request.properties;
147 this->completed = request.completed;
148 this->timeBegin = request.timeBegin;
149 this->timeEnd = request.timeEnd;
150 this->sequenceBegin = request.sequenceBegin;
151 this->sequenceEnd = request.sequenceEnd;
152 this->sourceUuid = request.sourceUuid;
155 virtual ~AsyncRangePropertyRequest() {}
157 PropertyList properties;
158 std::string sourceUuid;
159 GetRangedPropertyCompletedSignal completed;
162 int32_t sequenceBegin;
166 class AsyncRangePropertyReply: public AsyncRangePropertyRequest
169 AsyncRangePropertyReply(AsyncRangePropertyRequest request)
170 :AsyncRangePropertyRequest(request), success(false)
175 ~AsyncRangePropertyReply()
177 for(auto itr = values.begin(); itr != values.end(); itr++)
185 std::list<AbstractPropertyType*> values;
189 class AbstractRoutingEngine
192 virtual ~AbstractRoutingEngine();
194 virtual void setSupported(PropertyList supported, AbstractSource* source) = 0;
195 virtual void updateSupported(PropertyList added, PropertyList removed) = 0;
196 virtual void updateProperty(VehicleProperty::Property property, AbstractPropertyType* value, std::string uuid) = 0;
197 virtual PropertyList supported() = 0;
200 virtual void registerSink(AbstractSink* self) = 0;
201 virtual void unregisterSink(AbstractSink* self) = 0;
204 * @brief sourcesForProperty
206 * @return list of source uuid's that support the "property"
208 virtual std::list<std::string> sourcesForProperty(VehicleProperty::Property property) = 0;
211 * @brief getPropertyAsync requests a property value from a source. This call has a timeout and will always return.
212 * @see AsyncPropertyRequest
213 * @see AsyncPropertyReply.
214 * @param request requested property.
215 * @return AsyncPropertyReply. The returned AsyncPropertyReply is owned by the caller of getPropertyAsync.
216 * @example AsyncPropertyRequest request;
217 * request.property = VehicleProperty::VehicleSpeed
218 * request.completed = [](AsyncPropertyReply* reply) { delete reply; };
219 * routingEngine->getPropertyAsync(request);
221 virtual AsyncPropertyReply * getPropertyAsync(AsyncPropertyRequest request) = 0;
222 virtual AsyncRangePropertyReply * getRangePropertyAsync(AsyncRangePropertyRequest request) = 0;
223 virtual AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request) = 0;
224 virtual void subscribeToProperty(VehicleProperty::Property, AbstractSink* self) = 0;
225 virtual void subscribeToProperty(VehicleProperty::Property, std::string sourceUuidFilter, AbstractSink *self) = 0;
226 virtual void subscribeToProperty(VehicleProperty::Property, std::string sourceUuidFilter, Zone::Type zoneFilter, AbstractSink *self) = 0;
227 virtual void unsubscribeToProperty(VehicleProperty::Property, AbstractSink* self) = 0;
229 virtual PropertyInfo getPropertyInfo(VehicleProperty::Property, std::string sourceUuid) = 0;
230 virtual std::list<std::string> getSourcesForProperty(VehicleProperty::Property) = 0;
233 #endif // ABSTRACTROUTINGENGINE_H