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