fixed merge
[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
26 #include <boost/any.hpp>
27 #include <functional>
28 #include <time.h>
29 #include "vehicleproperty.h"
30 #include "abstractpropertytype.h"
31
32 class AbstractSink;
33 class AbstractSource;
34 class AsyncPropertyReply;
35 class AsyncRangePropertyReply;
36
37
38 typedef std::function<void (AsyncPropertyReply*)> GetPropertyCompletedSignal;
39 typedef std::function<void (AsyncRangePropertyReply*)> GetRangedPropertyCompletedSignal;
40
41 class PropertyValueTime {
42 public:
43         ~PropertyValueTime()
44         {
45                 delete value;
46         }
47
48         AbstractPropertyType* value;
49         double timestamp;
50 };
51
52 class AsyncPropertyRequest
53 {
54 public:
55         AsyncPropertyRequest()
56                 :property(VehicleProperty::NoValue)
57         {
58
59         }
60
61         AsyncPropertyRequest(const AsyncPropertyRequest &request)
62         {
63                 this->property = request.property;
64                 this->completed = request.completed;
65         }
66
67         AsyncPropertyRequest & operator = (const AsyncPropertyRequest & other)
68         {
69                 this->property = other.property;
70                 this->completed = other.completed;
71
72                 return *this;
73         }
74
75         VehicleProperty::Property property;
76         GetPropertyCompletedSignal completed;
77 };
78
79 class AsyncPropertyReply: public AsyncPropertyRequest
80 {
81 public:
82         AsyncPropertyReply(const AsyncPropertyRequest &request)
83                 :AsyncPropertyRequest(request), value(NULL), success(false)
84         {
85
86         }
87
88         AbstractPropertyType* value;
89         bool success;
90 };
91
92 class AsyncSetPropertyRequest: public AsyncPropertyRequest
93 {
94 public:
95         AsyncSetPropertyRequest()
96                 :value(NULL)
97         {
98
99         }
100
101         AsyncSetPropertyRequest(const AsyncPropertyRequest &request)
102                 :AsyncPropertyRequest(request), value(NULL)
103         {
104
105         }
106
107         AbstractPropertyType* value;
108 };
109
110 class AsyncRangePropertyRequest
111 {
112 public:
113         AsyncRangePropertyRequest()
114                 :begin(0), end(0)
115         {
116
117         }
118
119         AsyncRangePropertyRequest(const AsyncRangePropertyRequest &request)
120
121         {
122                 this->property = request.property;
123                 this->completed = request.completed;
124                 this->begin = request.begin;
125                 this->end = request.end;
126         }
127
128         VehicleProperty::Property property;
129         GetRangedPropertyCompletedSignal completed;
130         double begin;
131         double end;
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<PropertyValueTime*> values;
154         bool success;
155 };
156
157 class AbstractRoutingEngine
158 {
159 public:
160         virtual void setSupported(PropertyList supported, AbstractSource* source) = 0;
161         virtual void updateSupported(PropertyList added, PropertyList removed) = 0;
162         virtual void updateProperty(VehicleProperty::Property property, AbstractPropertyType* value, std::string uuid, double timestamp, uint32_t sequence) = 0;
163
164         /// sinks:
165         virtual void registerSink(AbstractSink* self) = 0;
166         virtual void  unregisterSink(AbstractSink* self) = 0;
167         virtual AsyncPropertyReply * getPropertyAsync(AsyncPropertyRequest request) = 0;
168         virtual AsyncRangePropertyReply * getRangePropertyAsync(AsyncRangePropertyRequest request) = 0;
169         virtual AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request) = 0;
170         virtual void subscribeToProperty(VehicleProperty::Property, AbstractSink* self) = 0;
171         virtual void unsubscribeToProperty(VehicleProperty::Property, AbstractSink* self) = 0;
172         virtual PropertyList supported() = 0;
173
174 };
175
176 #endif // ABSTRACTROUTINGENGINE_H