ec690fc1246e784da35a93fe66ea493ac0da65e6
[platform/core/api/maps-service.git] / src / api / maps_plugin_info.cpp
1 /* Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #include <glib.h>
17 #include "maps_error.h"
18 #include "maps_plugin_info.h"
19 #include "maps_util.h"
20 #include "maps_condition.h"
21
22 typedef struct _maps_plugin_info_s
23 {
24         char *provider_name;
25 } maps_plugin_info_s;
26
27 const gsize _MAPS_PLUGIN_INFO_NAME_MAX_LENGTH = MAPS_BASE_NAME_MAX_LEN;
28
29 /*----------------------------------------------------------------------------*/
30
31 EXPORT_API int maps_plugin_info_create(maps_plugin_info_h *info)
32 {
33         if (!maps_condition_check_maps_feature())
34                 return MAPS_ERROR_NOT_SUPPORTED;
35         if (!info)
36                 return MAPS_ERROR_INVALID_PARAMETER;
37         *info = g_slice_new0(maps_plugin_info_s);
38
39         if (*info == NULL) {
40                 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
41                 return MAPS_ERROR_OUT_OF_MEMORY;
42         }
43
44         return MAPS_ERROR_NONE;
45 }
46
47 EXPORT_API int maps_plugin_info_destroy(maps_plugin_info_h info)
48 {
49         if (!maps_condition_check_maps_feature())
50                 return MAPS_ERROR_NOT_SUPPORTED;
51         if (!info)
52                 return MAPS_ERROR_INVALID_PARAMETER;
53         int error = MAPS_ERROR_NONE;
54
55         maps_plugin_info_s *c = (maps_plugin_info_s *) info;
56
57         if (c->provider_name)
58                 g_free(c->provider_name);
59
60         g_slice_free(maps_plugin_info_s, info);
61         return error;
62 }
63
64 EXPORT_API int maps_plugin_info_clone(const maps_plugin_info_h origin,
65                                       maps_plugin_info_h *cloned)
66 {
67         if (!maps_condition_check_maps_feature())
68                 return MAPS_ERROR_NOT_SUPPORTED;
69         if (!cloned || !origin)
70                 return MAPS_ERROR_INVALID_PARAMETER;
71
72         int error = MAPS_ERROR_NONE;
73
74         do {
75                 error = maps_plugin_info_create(cloned);
76                 if (error != MAPS_ERROR_NONE)
77                         break;
78
79                 maps_plugin_info_s *c = (maps_plugin_info_s *) origin;
80
81                 if (c->provider_name) {
82                         error = maps_plugin_info_set_provider_name(*cloned, c->provider_name);
83                         if (error != MAPS_ERROR_NONE)
84                                 break;
85                 }
86
87                 return MAPS_ERROR_NONE;
88         } while (false);
89
90         maps_plugin_info_destroy(*cloned);
91         *cloned = NULL;
92         return error;
93 }
94
95 /*----------------------------------------------------------------------------*/
96
97 EXPORT_API int maps_plugin_info_get_provider_name(const maps_plugin_info_h info,
98                                                   char **provider_name)
99 {
100         if (!maps_condition_check_maps_feature())
101                 return MAPS_ERROR_NOT_SUPPORTED;
102         if (!info || !provider_name)
103                 return MAPS_ERROR_INVALID_PARAMETER;
104         return maps_get_string(((maps_plugin_info_s *) info)->provider_name,
105                 _MAPS_PLUGIN_INFO_NAME_MAX_LENGTH, provider_name);
106 }
107
108 /*----------------------------------------------------------------------------*/
109
110 EXPORT_API int maps_plugin_info_set_provider_name(maps_plugin_info_h info,
111                                                   const char *provider_name)
112 {
113         if (!maps_condition_check_maps_feature())
114                 return MAPS_ERROR_NOT_SUPPORTED;
115         if (!info || !provider_name)
116                 return MAPS_ERROR_INVALID_PARAMETER;
117         return maps_set_string(provider_name, _MAPS_PLUGIN_INFO_NAME_MAX_LENGTH,
118                 &((maps_plugin_info_s *) info)->provider_name);
119 }