aff3a19c9b0a19fd4a79e570313b2ffe6d1fc992
[framework/location/maps-service.git] / src / plugin / module.h
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __MAPS_SERVICE_PLUGIN_MODULE_H__
18 #define __MAPS_SERVICE_PLUGIN_MODULE_H__
19
20 #include "maps_plugin.h"
21 #include "discovery.h"
22 #include <glib.h>
23 #include <gmodule.h>
24
25 /* ------------------------------------------------------------------------- */
26 /*
27 *  Plugin dedicated functions
28 */
29 typedef int (*maps_plugin_init_f) (maps_plugin_h *plugin);
30 typedef int (*maps_plugin_shutdown_f) (maps_plugin_h plugin);
31 typedef int (*maps_plugin_get_info_f) (maps_plugin_info_h *info);
32
33 /* Maps Provider access key, preference and capabilities */
34 typedef int (*maps_plugin_set_provider_key_f) (const char *provider_key);
35 typedef int (*maps_plugin_get_provider_key_f) (char **provider_key);
36 typedef int (*maps_plugin_set_preference_f) (maps_preference_h preference);
37 typedef int (*maps_plugin_get_preference_f) (maps_preference_h *preference);
38 typedef int (*maps_plugin_is_service_supported_f) (maps_service_e service,
39                                                    bool *supported);
40 typedef int (*maps_plugin_is_data_supported_f) (maps_service_data_e data,
41                                                 bool *supported);
42
43 /* Geocode */
44 typedef int (*maps_plugin_geocode_f) (const char *address,
45                                       const maps_preference_h preference,
46                                       maps_service_geocode_cb callback,
47                                       void *user_data, int *request_id);
48 typedef int (*maps_plugin_geocode_inside_area_f) (const char *address,
49                                                   const maps_area_h bounds,
50                                                   const maps_preference_h
51                                                   preference,
52                                                   maps_service_geocode_cb
53                                                   callback,
54                                                   void *user_data,
55                                                   int *request_id);
56 typedef int (*maps_plugin_geocode_by_structured_address_f) (const maps_address_h
57                                                             address,
58                                                             const
59                                                             maps_preference_h
60                                                             preference,
61                                                         maps_service_geocode_cb
62                                                         callback,
63                                                         void *user_data,
64                                                         int *request_id);
65 typedef int (*maps_plugin_reverse_geocode_f) (double latitude, double longitude,
66                                               const maps_preference_h
67                                               preference,
68                                               maps_service_reverse_geocode_cb
69                                               callback,
70                                               void *user_data, int *request_id);
71
72 /* Place */
73 typedef int (*maps_plugin_search_place_f) (const maps_coordinates_h position,
74                                            int distance,
75                                            const maps_place_filter_h filter,
76                                            maps_preference_h preference,
77                                            maps_service_search_place_cb
78                                            callback,
79                                            void *user_data, int *request_id);
80 typedef int (*maps_plugin_search_place_by_area_f) (const maps_area_h boundary,
81                                                    const maps_place_filter_h
82                                                    filter,
83                                                    maps_preference_h preference,
84                                                    maps_service_search_place_cb
85                                                    callback,
86                                                    void *user_data,
87                                                    int *request_id);
88 typedef int (*maps_plugin_search_place_by_address_f) (const char *address,
89                                                       const maps_area_h
90                                                       boundary,
91                                                       const maps_place_filter_h
92                                                       filter,
93                                                       maps_preference_h
94                                                       preference,
95                                                 maps_service_search_place_cb
96                                                 callback,
97                                                 void *user_data,
98                                                 int *request_id);
99
100 /* Route */
101 typedef int (*maps_plugin_search_route_f) (const maps_coordinates_h origin,
102                                            const maps_coordinates_h destination,
103                                            maps_preference_h preference,
104                                            maps_service_search_route_cb
105                                            callback,
106                                            void *user_data, int *request_id);
107 typedef int (*maps_plugin_search_route_waypoints_f) (const maps_coordinates_h *
108                                                      waypoint_list,
109                                                      int waypoint_num,
110                                                      maps_preference_h
111                                                      preference,
112                                                 maps_service_search_route_cb
113                                                 callback,
114                                                 void *user_data,
115                                                 int *request_id);
116
117 /* Cancel Request */
118 typedef int (*maps_plugin_cancel_request_f) (int request_id);
119
120
121 namespace plugin {
122
123         /* Plugin interface */
124         typedef struct _interface_s {
125
126                 /* Plugin dedicated functions */
127                 maps_plugin_init_f maps_plugin_init;
128                 maps_plugin_shutdown_f maps_plugin_shutdown;
129                 maps_plugin_get_info_f maps_plugin_get_info;
130
131                 /* Maps Provider access key, preference and capabilities */
132                 maps_plugin_set_provider_key_f maps_plugin_set_provider_key;
133                 maps_plugin_get_provider_key_f maps_plugin_get_provider_key;
134                 maps_plugin_set_preference_f maps_plugin_set_preference;
135                 maps_plugin_get_preference_f maps_plugin_get_preference;
136                 maps_plugin_is_service_supported_f
137                         maps_plugin_is_service_supported;
138                 maps_plugin_is_data_supported_f maps_plugin_is_data_supported;
139
140                 /* Geocode */
141                 maps_plugin_geocode_f maps_plugin_geocode;
142                 maps_plugin_geocode_inside_area_f
143                         maps_plugin_geocode_inside_area;
144                  maps_plugin_geocode_by_structured_address_f
145                         maps_plugin_geocode_by_structured_address;
146                 maps_plugin_reverse_geocode_f maps_plugin_reverse_geocode;
147
148                 /* Place */
149                 maps_plugin_search_place_f maps_plugin_search_place;
150                 maps_plugin_search_place_by_area_f
151                         maps_plugin_search_place_by_area;
152                 maps_plugin_search_place_by_address_f
153                         maps_plugin_search_place_by_address;
154
155                 /* Route */
156                 maps_plugin_search_route_f maps_plugin_search_route;
157                 maps_plugin_search_route_waypoints_f
158                         maps_plugin_search_route_waypoints;
159
160                 /* Cancel Request */
161                 maps_plugin_cancel_request_f maps_plugin_cancel_request;
162
163         } interface_s;
164
165         /* Plugin structure */
166         typedef struct _plugin_s {
167                 interface_s interface;  /* Plugin interface function pointers */
168                 gpointer module;        /* Plugin module pointer, GMod */
169                 GAsyncQueue *request_queue;     /* Queue of asynchronous requests */
170                 GThread *thread;        /* Request queue thread: there is
171                                            happening delivery of request from
172                                            app to plugin */
173
174                 /* Flag: is the plugin in use */
175                 volatile bool is_working;       /* It is discouraged to use this
176                                                    approach; */
177                 /* probably, it must be exchanged with event dispite of
178                 *  performance trade-off */
179
180                 /*maps_string_hashtable_h capabilities; // The table of plugin
181                 * capabilities */
182
183                 GMutex pending_request_mutex;   /* Mutex for synchronizing the
184                                                    map of pending requests */
185                 GHashTable *pending_request_maps;       /* Map of pending
186                                                            requests */
187         } plugin_s;
188
189         /* TODO: Refactor to encapsulate everithing in a single calss
190         *  plugin::module */
191         typedef struct _GMod {
192                 gchar *name;
193                 gchar *path;
194                 GModule *module;
195         } GMod;
196
197         /* RAII Class implementing the mutex helper on the base of GLib mutex */
198         /* which automatically locks mutex during its creation and unlocks while
199         *  exiting the scope */
200         class scope_mutex {
201                 GMutex *mutex;
202         public:
203                  scope_mutex(GMutex *m);
204                 ~scope_mutex();
205         };
206
207         class binary_extractor {
208         public:
209                 binary_extractor();
210                 virtual ~binary_extractor()
211                 {
212                 }
213         public:
214                  provider_info get_plugin_info(const string &file_name) const;
215                 maps_plugin_h init(const provider_info &info);
216                 void shutdown(maps_plugin_h plugin_h);
217         private:
218                  GMod *gmod_new(const string &module_file,
219                                 gboolean is_resident) const;
220                 void gmod_free(GMod *gmod) const;
221                 gpointer gmod_find_sym(GMod *gmod,
222                                        const gchar *func_name) const;
223                 void trace_dbg(const plugin_s *plugin) const;
224         };
225 };
226
227 #endif                          /* __MAPS_SERVICE_PLUGIN_MODULE_H__ */