fixed to work with latest amb 0.11.810
[profile/ivi/ico-vic-amb-plugin.git] / src / ambinterface.h
1 /**
2  * Copyright (C) 2012  TOYOTA MOTOR 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 #ifndef AMBINTERFACE_H
20 #define AMBINTERFACE_H
21
22 #include <pthread.h>
23
24 #include <map>
25 #include <string>
26 #include <vector>
27
28 #include <abstractpropertytype.h>
29 #include <abstractsource.h>
30 #if LATER1024
31 #include <propertyinfo.hpp>
32 #endif
33 #include "ambconfig.h"
34
35 /**
36  * Vehicle information of AMB.
37  */
38 struct AMBVehicleInfo {
39     std::string name;
40     AbstractPropertyType *value;
41     Zone::Type zone;
42     bool isCustom;
43
44     bool operator==(const AMBVehicleInfo &vi) {
45         return (this->name == vi.name);
46     }
47 };
48
49 class AMBConfig;
50 class VICCommunicator;
51
52 /**
53  * Interface of AMB-Core and Plugin.
54  */
55 class AMBIF : public AbstractSource {
56 public:
57     /**
58      * Constructor.
59      * 
60      * @param engine Instance of AMB-Core.
61      * @param config Information in a configuration file of AMB.
62      */
63     AMBIF(AbstractRoutingEngine *engine,
64           std::map<std::string, std::string> config);
65     /**
66      * Destructor.
67      */
68     ~AMBIF();
69
70     /**
71      * AMBIF class receives a request for acquisition of information from AMB-Core.
72      * Vehicle Information stored in the hold, plugin will return the data.
73      * 
74      * @param reply Variable for storing the vehiclle information to be returnd to AMB-Core.
75      */
76     void
77     getPropertyAsync(AsyncPropertyReply *reply);
78     /**
79      * AMBIF class receives a request for a change in the vehicle information from AMB-Core.
80      * Changes to vehicle information received from its own information.
81      *
82      * @param request Vehicle information that has been requested change.
83      * @return Vehicle information after the change.
84      */
85     AsyncPropertyReply *
86     setProperty(AsyncSetPropertyRequest request);
87     /**
88      * AMBIF class receives a request for acquisition of vehicle information list from AMB-Core.
89      *
90      * @return Vehicle information list held by the plugin.
91      */
92     PropertyList
93     supported();
94     /**
95      * AMBIF class receives from AMB-Core a request for obtaining the operation list.
96      * AMBIF class supports the operations(Get/Set)
97      *
98      * @return Operation
99      */
100     int
101     supportedOperations();
102
103     /**
104      * AMBIF class will issue a UUID.
105      *
106      * @return UUID
107      */
108 #if LATER1024
109     const string
110 #else
111     string
112 #endif
113     uuid();
114     /**
115      * AMBIF class is received the vehicle information that other plugin updated.
116      *
117      * @param property the name of Vehicle information of AMB.
118      * @param value the value of Vehicle information of AMB.
119      * @param uuid UUID of the source plugin.
120      */
121     void
122     propertyChanged(VehicleProperty::Property property,
123                     AbstractPropertyType *value, std::string uuid);
124     /**
125      * AMBIF class reads the configuration file AMB.
126      *
127      * @param config Information in a configuration file of AMB.
128      */
129     void
130     setConfiguratin(std::map<std::string, std::string> config);
131
132     /**
133      * Initialization.
134      *
135      * @param comm Instance of VICCommunicator.
136      * @param conf Instance of Config.
137      * @return Success : true Failure : false
138      */
139     bool
140     initialize(VICCommunicator *comm, AMBConfig *conf);
141     /**
142      * AMBIF class is required to get the vehicle information to AMB-Core.
143      *
144      * @param propertyname The name of vehicle information of AMB.
145      * @return The value of vehicle information of AMB.
146      */
147     AMBVehicleInfo *
148     getPropertyRequest(std::string propertyname);
149     /**
150      * AMBIF class ask AMB-Core to change the vehicle information.
151      * This request is used for vehicle information that is managed by other plugin.
152      *
153      * @param vehicleinfo Vehicle information of AMB.(name and value)
154      */
155     void
156     setPropertyRequest(AMBVehicleInfo *vehicleinfo);
157     /**
158      * AMBIF class notify a change in the vehicle information to the AMB-Core.
159      * This instruction is subject to only the vehicle information that is managed by the plugin.
160      *
161      * @param vehicleinfo Vehicle information of AMB.(name and value)
162      */
163     void
164     updateProperty(AMBVehicleInfo *vehicleinfo);
165     /**
166      * AMBIF class locks the vehicle information changes.
167      */
168     void
169     lock();
170     /**
171      * AMBIF class releases the lock status of the vehicle information changes.
172      */
173     void
174     unLock();
175     /**
176      * This function is an interface with other objects in the Plugin.
177      * This interface issues a request to change the information.
178      * 
179      * @param vehicleinfo Vehicle information of AMB.
180      */
181     void
182     requestUpdate(AMBVehicleInfo *vehicleinfo);
183
184     /**
185      * Unused virtual function.
186      */
187     void
188     getRangePropertyAsync(AsyncRangePropertyReply *reply)
189     {
190     }
191     /**
192      * Unused virtual function.
193      */
194     void
195     subscribeToPropertyChanges(VehicleProperty::Property property)
196     {
197     }
198     /**
199      * Unused virtual function.
200      */
201     void
202     unsubscribeToPropertyChanges(VehicleProperty::Property property)
203     {
204     }
205     /**
206      * Unused virtual function.
207      */
208     void
209     supportedChanged(const PropertyList &)
210     {
211     }
212
213 #if LATER1024
214     PropertyInfo getPropertyInfo(VehicleProperty::Property property);
215 #endif
216 private:
217     bool
218     registVehicleInfo(std::string propertyName, DataType type,
219                       std::string value);
220     AMBVehicleInfo *
221     find(std::string propertyName);
222
223     PropertyList propertylist;
224     vector<AMBVehicleInfo> vehicleinfoArray;
225 #if LATER1024
226     std::map<VehicleProperty::Property, PropertyInfo> propertyInfoMap;
227 #endif
228     VICCommunicator *communicator;
229     pthread_mutex_t mutex;
230 };
231 #endif // #ifndef AMBINTERFACE_H