refactored setProperty: made it async with callback
[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 <boost/any.hpp>
24 #include <functional>
25 #include <time.h>
26 #include "vehicleproperty.h"
27 #include "abstractpropertytype.h"
28
29 class AbstractSink;
30 class AbstractSource;
31 class AsyncPropertyReply;
32
33
34 typedef std::function<void (AsyncPropertyReply*)> GetPropertyCompletedSignal;
35
36 class PropertyValueTime {
37 public:
38         AbstractPropertyType* value;
39         time_t timestamp;
40 };
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         }
56
57         AsyncPropertyRequest & operator = (const AsyncPropertyRequest & other)
58         {
59                 this->property = other.property;
60                 this->completed = other.completed;
61
62                 return *this;
63         }
64
65         VehicleProperty::Property property;
66         GetPropertyCompletedSignal completed;
67 };
68
69 class AsyncPropertyReply: public AsyncPropertyRequest
70 {
71 public:
72         AsyncPropertyReply(const AsyncPropertyRequest &request)
73                 :AsyncPropertyRequest(request), value(NULL), success(false)
74         {
75
76         }
77
78         AbstractPropertyType* value;
79         bool success;
80 };
81
82 class AsyncSetPropertyRequest: public AsyncPropertyRequest
83 {
84 public:
85         AsyncSetPropertyRequest()
86                 :value(NULL)
87         {
88
89         }
90
91         AsyncSetPropertyRequest(const AsyncPropertyRequest &request)
92                 :AsyncPropertyRequest(request), value(NULL)
93         {
94
95         }
96
97         AbstractPropertyType* value;
98 };
99
100 class AsyncRangePropertyRequest: public AsyncPropertyRequest
101 {
102 public:
103         AsyncRangePropertyRequest()
104                 :begin(0), end(0)
105         {
106
107         }
108
109         AsyncRangePropertyRequest(const AsyncPropertyRequest &request)
110                 :AsyncPropertyRequest(request), begin(0), end(0)
111         {
112                 this->property = request.property;
113                 this->completed = request.completed;
114         }
115
116         AsyncRangePropertyRequest(const AsyncRangePropertyRequest &request)
117                 :AsyncPropertyRequest(request)
118         {
119                 this->property = request.property;
120                 this->completed = request.completed;
121                 this->begin = request.begin;
122                 this->end = request.end;
123         }
124
125         time_t begin;
126         time_t end;
127 };
128
129 class AsyncRangePropertyReply: public AsyncRangePropertyRequest
130 {
131 public:
132         AsyncRangePropertyReply(AsyncRangePropertyRequest request)
133                 :AsyncRangePropertyRequest(request)
134         {
135
136         }
137
138         std::list<PropertyValueTime*> values;
139 };
140
141 class AbstractRoutingEngine
142 {
143 public:
144         virtual void setSupported(PropertyList supported, AbstractSource* source) = 0;
145         virtual void updateSupported(PropertyList added, PropertyList removed) = 0;
146         virtual void updateProperty(VehicleProperty::Property property, AbstractPropertyType* value) = 0;
147
148         /// sinks:
149         virtual void registerSink(AbstractSink* self) = 0;
150         virtual void  unregisterSink(AbstractSink* self) = 0;
151         virtual AsyncPropertyReply * getPropertyAsync(AsyncPropertyRequest request) = 0;
152         virtual AsyncRangePropertyReply * getRangePropertyAsync(AsyncRangePropertyRequest request) = 0;
153         virtual AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request) = 0;
154         virtual void subscribeToProperty(VehicleProperty::Property, AbstractSink* self) = 0;
155         virtual void unsubscribeToProperty(VehicleProperty::Property, AbstractSink* self) = 0;
156         virtual PropertyList supported() = 0;
157 };
158
159 #endif // ABSTRACTROUTINGENGINE_H