Merge branch 'master' of https://github.com/otcshare/automotive-message-broker
[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 AsyncPropertyRequest
42 {
43 public:
44         AsyncPropertyRequest()
45                 :property(VehicleProperty::NoValue)
46         {
47
48         }
49
50         AsyncPropertyRequest(const AsyncPropertyRequest &request)
51         {
52                 this->property = request.property;
53                 this->completed = request.completed;
54         }
55
56         AsyncPropertyRequest & operator = (const AsyncPropertyRequest & other)
57         {
58                 this->property = other.property;
59                 this->completed = other.completed;
60
61                 return *this;
62         }
63
64         VehicleProperty::Property property;
65         GetPropertyCompletedSignal completed;
66 };
67
68 class AsyncPropertyReply: public AsyncPropertyRequest
69 {
70 public:
71         AsyncPropertyReply(const AsyncPropertyRequest &request)
72                 :AsyncPropertyRequest(request), value(NULL), success(false)
73         {
74
75         }
76
77         AbstractPropertyType* value;
78         bool success;
79 };
80
81 class AsyncSetPropertyRequest: public AsyncPropertyRequest
82 {
83 public:
84         AsyncSetPropertyRequest()
85                 :value(NULL)
86         {
87
88         }
89
90         AsyncSetPropertyRequest(const AsyncPropertyRequest &request)
91                 :AsyncPropertyRequest(request), value(NULL)
92         {
93
94         }
95
96         AbstractPropertyType* value;
97 };
98
99 class AsyncRangePropertyRequest
100 {
101 public:
102         AsyncRangePropertyRequest()
103                 :timeBegin(0), timeEnd(0), sequenceBegin(-1), sequenceEnd(-1)
104         {
105
106         }
107
108         AsyncRangePropertyRequest(const AsyncRangePropertyRequest &request)
109
110         {
111                 this->property = request.property;
112                 this->completed = request.completed;
113                 this->timeBegin = request.timeBegin;
114                 this->timeEnd = request.timeEnd;
115                 this->sequenceBegin = request.sequenceBegin;
116                 this->sequenceEnd = request.sequenceEnd;
117         }
118
119         VehicleProperty::Property property;
120         GetRangedPropertyCompletedSignal completed;
121         double timeBegin;
122         double timeEnd;
123         int32_t sequenceBegin;
124         int32_t sequenceEnd;
125 };
126
127 class AsyncRangePropertyReply: public AsyncRangePropertyRequest
128 {
129 public:
130         AsyncRangePropertyReply(AsyncRangePropertyRequest request)
131                 :AsyncRangePropertyRequest(request), success(false)
132         {
133
134         }
135
136         ~AsyncRangePropertyReply()
137         {
138                 for(auto itr = values.begin(); itr != values.end(); itr++)
139                 {
140                         delete (*itr);
141                 }
142
143                 values.clear();
144         }
145
146         std::list<AbstractPropertyType*> values;
147         bool success;
148 };
149
150 class AbstractRoutingEngine
151 {
152 public:
153         virtual void setSupported(PropertyList supported, AbstractSource* source) = 0;
154         virtual void updateSupported(PropertyList added, PropertyList removed) = 0;
155         virtual void updateProperty(VehicleProperty::Property property, AbstractPropertyType* value, std::string uuid) = 0;
156
157         /// sinks:
158         virtual void registerSink(AbstractSink* self) = 0;
159         virtual void  unregisterSink(AbstractSink* self) = 0;
160         virtual AsyncPropertyReply * getPropertyAsync(AsyncPropertyRequest request) = 0;
161         virtual AsyncRangePropertyReply * getRangePropertyAsync(AsyncRangePropertyRequest request) = 0;
162         virtual AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request) = 0;
163         virtual void subscribeToProperty(VehicleProperty::Property, AbstractSink* self) = 0;
164         virtual void unsubscribeToProperty(VehicleProperty::Property, AbstractSink* self) = 0;
165         virtual PropertyList supported() = 0;
166
167 };
168
169 #endif // ABSTRACTROUTINGENGINE_H