fixed some previous merge bugs that may have broken building a few plugins. also...
[profile/ivi/automotive-message-broker.git] / lib / abstractroutingengine.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
20 #ifndef ABSTRACTROUTINGENGINE_H
21 #define ABSTRACTROUTINGENGINE_H
22
23 #include <sys/types.h>
24 #include <stdlib.h>
25 #include <boost/any.hpp>
26 #include <functional>
27 #include <string>
28 #include <time.h>
29
30 #include "vehicleproperty.h"
31 #include "abstractpropertytype.h"
32
33 class AbstractSink;
34 class AbstractSource;
35 class AsyncPropertyReply;
36 class AsyncRangePropertyReply;
37
38
39 typedef std::function<void (AsyncPropertyReply*)> GetPropertyCompletedSignal;
40 typedef std::function<void (AsyncRangePropertyReply*)> GetRangedPropertyCompletedSignal;
41
42 class AsyncPropertyRequest
43 {
44 public:
45         AsyncPropertyRequest()
46                 :property(VehicleProperty::NoValue)
47         {
48
49         }
50
51         AsyncPropertyRequest(const AsyncPropertyRequest &request)
52         {
53                 this->property = request.property;
54                 this->completed = request.completed;
55                 this->sourceUuid = request.sourceUuid;
56         }
57
58         AsyncPropertyRequest & operator = (const AsyncPropertyRequest & other)
59         {
60                 this->property = other.property;
61                 this->completed = other.completed;
62                 this->sourceUuid = other.sourceUuid;
63
64                 return *this;
65         }
66
67         VehicleProperty::Property property;
68         std::string sourceUuid;
69         GetPropertyCompletedSignal completed;
70 };
71
72 class AsyncPropertyReply: public AsyncPropertyRequest
73 {
74 public:
75         AsyncPropertyReply(const AsyncPropertyRequest &request)
76                 :AsyncPropertyRequest(request), value(NULL), success(false)
77         {
78
79         }
80
81
82         AbstractPropertyType* value;
83         bool success;
84 };
85
86 class AsyncSetPropertyRequest: public AsyncPropertyRequest
87 {
88 public:
89         AsyncSetPropertyRequest()
90                 :value(NULL)
91         {
92
93         }
94
95         AsyncSetPropertyRequest(const AsyncPropertyRequest &request)
96                 :AsyncPropertyRequest(request), value(NULL)
97         {
98
99         }
100
101         AbstractPropertyType* value;
102 };
103
104 class AsyncRangePropertyRequest
105 {
106 public:
107         AsyncRangePropertyRequest()
108                 :timeBegin(0), timeEnd(0), sequenceBegin(-1), sequenceEnd(-1)
109         {
110
111         }
112
113         AsyncRangePropertyRequest(const AsyncRangePropertyRequest &request)
114
115         {
116                 this->property = request.property;
117                 this->completed = request.completed;
118                 this->timeBegin = request.timeBegin;
119                 this->timeEnd = request.timeEnd;
120                 this->sequenceBegin = request.sequenceBegin;
121                 this->sequenceEnd = request.sequenceEnd;
122                 this->sourceUuid = request.sourceUuid;
123         }
124
125         VehicleProperty::Property property;
126         std::string sourceUuid;
127         GetRangedPropertyCompletedSignal completed;
128         double timeBegin;
129         double timeEnd;
130         int32_t sequenceBegin;
131         int32_t sequenceEnd;
132 };
133
134 class AsyncRangePropertyReply: public AsyncRangePropertyRequest
135 {
136 public:
137         AsyncRangePropertyReply(AsyncRangePropertyRequest request)
138                 :AsyncRangePropertyRequest(request), success(false)
139         {
140
141         }
142
143         ~AsyncRangePropertyReply()
144         {
145                 for(auto itr = values.begin(); itr != values.end(); itr++)
146                 {
147                         delete (*itr);
148                 }
149
150                 values.clear();
151         }
152
153         std::list<AbstractPropertyType*> values;
154         bool success;
155 };
156
157 class AbstractRoutingEngine
158 {
159 public:
160         virtual ~AbstractRoutingEngine();
161
162         virtual void setSupported(PropertyList supported, AbstractSource* source) = 0;
163         virtual void updateSupported(PropertyList added, PropertyList removed) = 0;
164         virtual void updateProperty(VehicleProperty::Property property, AbstractPropertyType* value, std::string uuid) = 0;
165
166         /// sinks:
167         virtual void registerSink(AbstractSink* self) = 0;
168         virtual void  unregisterSink(AbstractSink* self) = 0;
169         virtual AsyncPropertyReply * getPropertyAsync(AsyncPropertyRequest request) = 0;
170         virtual AsyncRangePropertyReply * getRangePropertyAsync(AsyncRangePropertyRequest request) = 0;
171         virtual AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request) = 0;
172         virtual void subscribeToProperty(VehicleProperty::Property, AbstractSink* self) = 0;
173         virtual void unsubscribeToProperty(VehicleProperty::Property, AbstractSink* self) = 0;
174         virtual PropertyList supported() = 0;
175 };
176
177 #endif // ABSTRACTROUTINGENGINE_H