fixed todo 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         AbstractPropertyType* value;
44         time_t timestamp;
45 };
46
47 class AsyncPropertyRequest
48 {
49 public:
50         AsyncPropertyRequest()
51                 :property(VehicleProperty::NoValue)
52         {
53
54         }
55
56         AsyncPropertyRequest(const AsyncPropertyRequest &request)
57         {
58                 this->property = request.property;
59                 this->completed = request.completed;
60         }
61
62         AsyncPropertyRequest & operator = (const AsyncPropertyRequest & other)
63         {
64                 this->property = other.property;
65                 this->completed = other.completed;
66
67                 return *this;
68         }
69
70         VehicleProperty::Property property;
71         GetPropertyCompletedSignal completed;
72 };
73
74 class AsyncPropertyReply: public AsyncPropertyRequest
75 {
76 public:
77         AsyncPropertyReply(const AsyncPropertyRequest &request)
78                 :AsyncPropertyRequest(request), value(NULL), success(false)
79         {
80
81         }
82
83         AbstractPropertyType* value;
84         bool success;
85 };
86
87 class AsyncSetPropertyRequest: public AsyncPropertyRequest
88 {
89 public:
90         AsyncSetPropertyRequest()
91                 :value(NULL)
92         {
93
94         }
95
96         AsyncSetPropertyRequest(const AsyncPropertyRequest &request)
97                 :AsyncPropertyRequest(request), value(NULL)
98         {
99
100         }
101
102         AbstractPropertyType* value;
103 };
104
105 class AsyncRangePropertyRequest
106 {
107 public:
108         AsyncRangePropertyRequest()
109                 :begin(0), end(0)
110         {
111
112         }
113
114         AsyncRangePropertyRequest(const AsyncRangePropertyRequest &request)
115
116         {
117                 this->property = request.property;
118                 this->completed = request.completed;
119                 this->begin = request.begin;
120                 this->end = request.end;
121         }
122
123         VehicleProperty::Property property;
124         GetRangedPropertyCompletedSignal completed;
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), success(false)
134         {
135
136         }
137
138         std::list<PropertyValueTime*> values;
139         bool success;
140 };
141
142 class AbstractRoutingEngine
143 {
144 public:
145         virtual void setSupported(PropertyList supported, AbstractSource* source) = 0;
146         virtual void updateSupported(PropertyList added, PropertyList removed) = 0;
147         virtual void updateProperty(VehicleProperty::Property property, AbstractPropertyType* value) = 0;
148
149         /// sinks:
150         virtual void registerSink(AbstractSink* self) = 0;
151         virtual void  unregisterSink(AbstractSink* self) = 0;
152         virtual AsyncPropertyReply * getPropertyAsync(AsyncPropertyRequest request) = 0;
153         virtual AsyncRangePropertyReply * getRangePropertyAsync(AsyncRangePropertyRequest request) = 0;
154         virtual AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request) = 0;
155         virtual void subscribeToProperty(VehicleProperty::Property, AbstractSink* self) = 0;
156         virtual void unsubscribeToProperty(VehicleProperty::Property, AbstractSink* self) = 0;
157         virtual PropertyList supported() = 0;
158 };
159
160 #endif // ABSTRACTROUTINGENGINE_H