fixed websocketsource. possibly removed mem leak
[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*)> CompletedSignal;
35
36 class AsyncPropertyRequest
37 {
38 public:
39         AsyncPropertyRequest()
40                 :property(VehicleProperty::NoValue)
41         {
42
43         }
44
45         AsyncPropertyRequest(const AsyncPropertyRequest &request)
46         {
47                 this->property = request.property;
48                 this->completed = request.completed;
49         }
50
51         AsyncPropertyRequest & operator = (const AsyncPropertyRequest & other)
52         {
53                 this->property = other.property;
54                 this->completed = other.completed;
55
56                 return *this;
57         }
58
59         VehicleProperty::Property property;
60         CompletedSignal completed;
61 };
62
63 class AsyncPropertyReply: public AsyncPropertyRequest
64 {
65 public:
66         AsyncPropertyReply(const AsyncPropertyRequest &request)
67                 :AsyncPropertyRequest(request), value(NULL)
68         {
69
70         }
71
72         AbstractPropertyType* value;
73 };
74
75 class AsyncRangePropertyRequest: public AsyncPropertyRequest
76 {
77 public:
78         AsyncRangePropertyRequest()
79                 :begin(0), end(0)
80         {
81
82         }
83
84         AsyncRangePropertyRequest(const AsyncPropertyRequest &request)
85                 :AsyncPropertyRequest(request), begin(0), end(0)
86         {
87                 this->property = request.property;
88                 this->completed = request.completed;
89         }
90
91         AsyncRangePropertyRequest(const AsyncRangePropertyRequest &request)
92                 :AsyncPropertyRequest(request)
93         {
94                 this->property = request.property;
95                 this->completed = request.completed;
96                 this->begin = request.begin;
97                 this->end = request.end;
98         }
99
100         time_t begin;
101         time_t end;
102 };
103
104 class AsyncRangePropertyReply: public AsyncRangePropertyRequest
105 {
106 public:
107         AsyncRangePropertyReply(AsyncRangePropertyRequest request)
108                 :AsyncRangePropertyRequest(request)
109         {
110
111         }
112
113         std::list<AbstractPropertyType*> values;
114 };
115
116 class AbstractRoutingEngine
117 {
118 public:
119         virtual void setSupported(PropertyList supported, AbstractSource* source) = 0;
120         virtual void updateSupported(PropertyList added, PropertyList removed) = 0;
121         virtual void updateProperty(VehicleProperty::Property property, AbstractPropertyType* value) = 0;
122
123         /// sinks:
124         virtual void registerSink(AbstractSink* self) = 0;
125         virtual void  unregisterSink(AbstractSink* self) = 0;
126         virtual AsyncPropertyReply *getPropertyAsync(AsyncPropertyRequest request) = 0;
127         virtual AsyncRangePropertyReply * getRangePropertyAsync(AsyncRangePropertyRequest request) = 0;
128         virtual void setProperty(VehicleProperty::Property, AbstractPropertyType*) = 0;
129         virtual void subscribeToProperty(VehicleProperty::Property, AbstractSink* self) = 0;
130         virtual void unsubscribeToProperty(VehicleProperty::Property, AbstractSink* self) = 0;
131         virtual PropertyList supported() = 0;
132 };
133
134 #endif // ABSTRACTROUTINGENGINE_H