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