8105ad1037f01d826e155a9d2417b0e207a68c4b
[platform/core/api/maps-service.git] / src / api / maps_place_link_object.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_place_link_object_plugin.h"
19 #include "maps_util.h"
20 #include "maps_condition.h"
21
22 typedef struct _maps_place_link_object_s
23 {
24         char *id;
25         char *name;
26         char *type;
27         char *string;
28 } maps_place_link_object_s;
29
30 const gsize _MAPS_PLACE_LINK_OBJECT_ID_MAX_LENGTH = MAPS_BASE_ID_MAX_LEN;
31 const gsize _MAPS_PLACE_LINK_OBJECT_NAME_MAX_LENGTH = MAPS_BASE_NAME_MAX_LEN;
32 const gsize _MAPS_PLACE_LINK_OBJECT_TYPE_MAX_LENGTH = MAPS_BASE_NAME_MAX_LEN;
33 const gsize _MAPS_PLACE_LINK_OBJECT_STRING_MAX_LENGTH = MAPS_BASE_URL_MAX_LEN;
34
35 /*----------------------------------------------------------------------------*/
36
37 EXPORT_API int maps_place_link_object_create(maps_place_link_object_h *place)
38 {
39         if (!maps_condition_check_maps_feature())
40                 return MAPS_ERROR_NOT_SUPPORTED;
41         if (!place)
42                 return MAPS_ERROR_INVALID_PARAMETER;
43         *place = (maps_place_link_object_h)
44                 g_slice_new0(maps_place_link_object_s);
45
46         if (*place == NULL) {
47                 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
48                 return MAPS_ERROR_OUT_OF_MEMORY;
49         }
50
51         return MAPS_ERROR_NONE;
52 }
53
54 EXPORT_API int maps_place_link_object_destroy(maps_place_link_object_h place)
55 {
56         if (!maps_condition_check_maps_feature())
57                 return MAPS_ERROR_NOT_SUPPORTED;
58         if (!place)
59                 return MAPS_ERROR_INVALID_PARAMETER;
60
61         maps_place_link_object_s *lo = (maps_place_link_object_s *) place;
62
63         if (lo->id)
64                 g_free(lo->id);
65         if (lo->name)
66                 g_free(lo->name);
67         if (lo->type)
68                 g_free(lo->type);
69         if (lo->string)
70                 g_free(lo->string);
71
72         g_slice_free(maps_place_link_object_s, place);
73         return MAPS_ERROR_NONE;
74 }
75
76 EXPORT_API int maps_place_link_object_clone(const maps_place_link_object_h origin,
77                                                                 maps_place_link_object_h *cloned)
78 {
79         if (!maps_condition_check_maps_feature())
80                 return MAPS_ERROR_NOT_SUPPORTED;
81         if (!cloned || !origin)
82                 return MAPS_ERROR_INVALID_PARAMETER;
83
84         int error = MAPS_ERROR_NONE;
85         do {
86                 error = maps_place_link_object_create(cloned);
87                 if (!(*cloned) || (error != MAPS_ERROR_NONE))
88                         break;
89
90                 maps_place_link_object_s *lo =
91                         (maps_place_link_object_s *) origin;
92
93                 if (lo->id) {
94                         error = maps_place_link_object_set_id(*cloned, lo->id);
95                         if (error != MAPS_ERROR_NONE)
96                                 break;
97                 }
98
99                 if (lo->name) {
100                         error = maps_place_link_object_set_name(*cloned, lo->name);
101                         if (error != MAPS_ERROR_NONE)
102                                 break;
103                 }
104
105                 if (lo->type) {
106                         error = maps_place_link_object_set_type(*cloned, lo->type);
107                         if (error != MAPS_ERROR_NONE)
108                                 break;
109                 }
110
111                 if (lo->string) {
112                         error = maps_place_link_object_set_string(*cloned, lo->string);
113                         if (error != MAPS_ERROR_NONE)
114                                 break;
115                 }
116
117                 return MAPS_ERROR_NONE;
118         } while (false);
119
120         maps_place_link_object_destroy(*cloned);
121         *cloned = NULL;
122         return error;
123 }
124
125 /*----------------------------------------------------------------------------*/
126
127 EXPORT_API int maps_place_link_object_get_string(const maps_place_link_object_h place,
128                                                  char **string)
129 {
130         if (!maps_condition_check_maps_feature())
131                 return MAPS_ERROR_NOT_SUPPORTED;
132         if (!place || !string)
133                 return MAPS_ERROR_INVALID_PARAMETER;
134         if (!((maps_place_link_object_s *) place)->string)
135                 return MAPS_ERROR_NOT_FOUND;
136         return maps_get_string(((maps_place_link_object_s *) place)->string,
137                 _MAPS_PLACE_LINK_OBJECT_STRING_MAX_LENGTH, string);
138 }
139
140 EXPORT_API int maps_place_link_object_get_type(const maps_place_link_object_h place,
141                                                char **type)
142 {
143         if (!maps_condition_check_maps_feature())
144                 return MAPS_ERROR_NOT_SUPPORTED;
145         if (!place || !type)
146                 return MAPS_ERROR_INVALID_PARAMETER;
147         if (!((maps_place_link_object_s *) place)->type)
148                 return MAPS_ERROR_NOT_FOUND;
149         return maps_get_string(((maps_place_link_object_s *) place)->type,
150                 _MAPS_PLACE_LINK_OBJECT_TYPE_MAX_LENGTH, type);
151 }
152
153 EXPORT_API int maps_place_link_object_get_id(const maps_place_link_object_h place,
154                                              char **id)
155 {
156         if (!maps_condition_check_maps_feature())
157                 return MAPS_ERROR_NOT_SUPPORTED;
158         if (!place || !id)
159                 return MAPS_ERROR_INVALID_PARAMETER;
160         if (!((maps_place_link_object_s *) place)->id)
161                 return MAPS_ERROR_NOT_FOUND;
162         return maps_get_string(((maps_place_link_object_s *) place)->id,
163                 _MAPS_PLACE_LINK_OBJECT_ID_MAX_LENGTH, id);
164 }
165
166 EXPORT_API int maps_place_link_object_get_name(const maps_place_link_object_h place,
167                                              char **name)
168 {
169         if (!maps_condition_check_maps_feature())
170                 return MAPS_ERROR_NOT_SUPPORTED;
171         if (!place || !name)
172                 return MAPS_ERROR_INVALID_PARAMETER;
173         if (!((maps_place_link_object_s *) place)->name)
174                 return MAPS_ERROR_NOT_FOUND;
175         return maps_get_string(((maps_place_link_object_s *) place)->name,
176                 _MAPS_PLACE_LINK_OBJECT_NAME_MAX_LENGTH, name);
177 }
178
179 /*----------------------------------------------------------------------------*/
180
181 EXPORT_API int maps_place_link_object_set_id(maps_place_link_object_h place,
182                                              const char *id)
183 {
184         if (!maps_condition_check_maps_feature())
185                 return MAPS_ERROR_NOT_SUPPORTED;
186         if (!place || !id)
187                 return MAPS_ERROR_INVALID_PARAMETER;
188         return maps_set_string(id, _MAPS_PLACE_LINK_OBJECT_ID_MAX_LENGTH,
189                 &((maps_place_link_object_s *) place)->id);
190 }
191
192 EXPORT_API int maps_place_link_object_set_string(maps_place_link_object_h place,
193                                                  const char *string)
194 {
195         if (!maps_condition_check_maps_feature())
196                 return MAPS_ERROR_NOT_SUPPORTED;
197         if (!place || !string)
198                 return MAPS_ERROR_INVALID_PARAMETER;
199         return maps_set_string(string,
200                 _MAPS_PLACE_LINK_OBJECT_STRING_MAX_LENGTH,
201                 &((maps_place_link_object_s *) place)->string);
202 }
203
204 EXPORT_API int maps_place_link_object_set_type(maps_place_link_object_h place,
205                                                const char *type)
206 {
207         if (!maps_condition_check_maps_feature())
208                 return MAPS_ERROR_NOT_SUPPORTED;
209         if (!place || !type)
210                 return MAPS_ERROR_INVALID_PARAMETER;
211         return maps_set_string(type, _MAPS_PLACE_LINK_OBJECT_TYPE_MAX_LENGTH,
212                 &((maps_place_link_object_s *) place)->type);
213 }
214
215 EXPORT_API int maps_place_link_object_set_name(maps_place_link_object_h place,
216                                                const char *name)
217 {
218         if (!maps_condition_check_maps_feature())
219                 return MAPS_ERROR_NOT_SUPPORTED;
220         if (!place || !name)
221                 return MAPS_ERROR_INVALID_PARAMETER;
222         return maps_set_string(name, _MAPS_PLACE_LINK_OBJECT_NAME_MAX_LENGTH,
223                 &((maps_place_link_object_s *) place)->name);
224 }