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"
35 class AsyncPropertyReply;
36 class AsyncRangePropertyReply;
39 typedef std::function<void (AsyncPropertyReply*)> GetPropertyCompletedSignal;
40 typedef std::function<void (AsyncRangePropertyReply*)> GetRangedPropertyCompletedSignal;
42 class AsyncPropertyRequest
45 AsyncPropertyRequest()
46 :property(VehicleProperty::NoValue),timeout(10000)
51 AsyncPropertyRequest(const AsyncPropertyRequest &request)
53 this->property = request.property;
54 this->completed = request.completed;
55 this->sourceUuid = request.sourceUuid;
56 this->timeout = request.timeout;
59 AsyncPropertyRequest & operator = (const AsyncPropertyRequest & other)
61 this->property = other.property;
62 this->completed = other.completed;
63 this->sourceUuid = other.sourceUuid;
64 this->timeout = other.timeout;
69 VehicleProperty::Property property;
70 std::string sourceUuid;
71 GetPropertyCompletedSignal completed;
75 class AsyncPropertyReply: public AsyncPropertyRequest
78 AsyncPropertyReply(const AsyncPropertyRequest &request)
79 :AsyncPropertyRequest(request), value(NULL), success(false), timeoutSource(nullptr)
81 auto timeoutfunc = [](gpointer userData) {
82 AsyncPropertyReply* thisReply = static_cast<AsyncPropertyReply*>(userData);
83 if(thisReply->success == false)
85 thisReply->error = Timeout;
86 thisReply->completed(thisReply);
93 timeoutSource = g_timeout_source_new(timeout);
94 g_source_set_callback(timeoutSource,(GSourceFunc) timeoutfunc, this, nullptr);
95 g_source_attach(timeoutSource, nullptr);
103 g_source_destroy(timeoutSource);
104 g_source_unref(timeoutSource);
116 * @brief value of the reply. This may be null if success = false. This is owned by the source.
118 AbstractPropertyType* value;
123 GSource* timeoutSource;
126 class AsyncSetPropertyRequest: public AsyncPropertyRequest
129 AsyncSetPropertyRequest()
135 AsyncSetPropertyRequest(const AsyncPropertyRequest &request)
136 :AsyncPropertyRequest(request), value(NULL)
141 AbstractPropertyType* value;
144 class AsyncRangePropertyRequest
147 AsyncRangePropertyRequest()
148 :timeBegin(0), timeEnd(0), sequenceBegin(-1), sequenceEnd(-1)
153 AsyncRangePropertyRequest(const AsyncRangePropertyRequest &request)
156 this->property = request.property;
157 this->completed = request.completed;
158 this->timeBegin = request.timeBegin;
159 this->timeEnd = request.timeEnd;
160 this->sequenceBegin = request.sequenceBegin;
161 this->sequenceEnd = request.sequenceEnd;
162 this->sourceUuid = request.sourceUuid;
165 VehicleProperty::Property property;
166 std::string sourceUuid;
167 GetRangedPropertyCompletedSignal completed;
170 int32_t sequenceBegin;
174 class AsyncRangePropertyReply: public AsyncRangePropertyRequest
177 AsyncRangePropertyReply(AsyncRangePropertyRequest request)
178 :AsyncRangePropertyRequest(request), success(false)
183 ~AsyncRangePropertyReply()
185 for(auto itr = values.begin(); itr != values.end(); itr++)
193 std::list<AbstractPropertyType*> values;
197 class AbstractRoutingEngine
200 virtual ~AbstractRoutingEngine();
202 virtual void setSupported(PropertyList supported, AbstractSource* source) = 0;
203 virtual void updateSupported(PropertyList added, PropertyList removed) = 0;
204 virtual void updateProperty(VehicleProperty::Property property, AbstractPropertyType* value, std::string uuid) = 0;
207 virtual void registerSink(AbstractSink* self) = 0;
208 virtual void unregisterSink(AbstractSink* self) = 0;
209 virtual AsyncPropertyReply * getPropertyAsync(AsyncPropertyRequest request) = 0;
210 virtual AsyncRangePropertyReply * getRangePropertyAsync(AsyncRangePropertyRequest request) = 0;
211 virtual AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request) = 0;
212 virtual void subscribeToProperty(VehicleProperty::Property, AbstractSink* self) = 0;
213 virtual void unsubscribeToProperty(VehicleProperty::Property, AbstractSink* self) = 0;
214 virtual PropertyList supported() = 0;
217 #endif // ABSTRACTROUTINGENGINE_H