refactored how timestamp and sequence are stored: moved to AbstractProperty
[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                 :begin(0), end(0)
104         {
105
106         }
107
108         AsyncRangePropertyRequest(const AsyncRangePropertyRequest &request)
109
110         {
111                 this->property = request.property;
112                 this->completed = request.completed;
113                 this->begin = request.begin;
114                 this->end = request.end;
115         }
116
117         VehicleProperty::Property property;
118         GetRangedPropertyCompletedSignal completed;
119         double begin;
120         double end;
121 };
122
123 class AsyncRangePropertyReply: public AsyncRangePropertyRequest
124 {
125 public:
126         AsyncRangePropertyReply(AsyncRangePropertyRequest request)
127                 :AsyncRangePropertyRequest(request), success(false)
128         {
129
130         }
131
132         ~AsyncRangePropertyReply()
133         {
134                 for(auto itr = values.begin(); itr != values.end(); itr++)
135                 {
136                         delete (*itr);
137                 }
138
139                 values.clear();
140         }
141
142         std::list<AbstractPropertyType*> values;
143         bool success;
144 };
145
146 class AbstractRoutingEngine
147 {
148 public:
149         virtual void setSupported(PropertyList supported, AbstractSource* source) = 0;
150         virtual void updateSupported(PropertyList added, PropertyList removed) = 0;
151         virtual void updateProperty(VehicleProperty::Property property, AbstractPropertyType* value, std::string uuid) = 0;
152
153         /// sinks:
154         virtual void registerSink(AbstractSink* self) = 0;
155         virtual void  unregisterSink(AbstractSink* self) = 0;
156         virtual AsyncPropertyReply * getPropertyAsync(AsyncPropertyRequest request) = 0;
157         virtual AsyncRangePropertyReply * getRangePropertyAsync(AsyncRangePropertyRequest request) = 0;
158         virtual AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request) = 0;
159         virtual void subscribeToProperty(VehicleProperty::Property, AbstractSink* self) = 0;
160         virtual void unsubscribeToProperty(VehicleProperty::Property, AbstractSink* self) = 0;
161         virtual PropertyList supported() = 0;
162
163 };
164
165 #endif // ABSTRACTROUTINGENGINE_H