Add LCOV remarkers to increase line coverage rate
[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                 //LCOV_EXCL_START
48                 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
49                 return MAPS_ERROR_OUT_OF_MEMORY;
50                 //LCOV_EXCL_STOP
51         }
52
53         return MAPS_ERROR_NONE;
54 }
55
56 EXPORT_API int maps_place_link_object_destroy(maps_place_link_object_h place)
57 {
58         if (!maps_condition_check_maps_feature())
59                 return MAPS_ERROR_NOT_SUPPORTED;
60         if (!place)
61                 return MAPS_ERROR_INVALID_PARAMETER;
62
63         maps_place_link_object_s *lo = (maps_place_link_object_s *) place;
64
65         if (lo->id)
66                 g_free(lo->id);
67         if (lo->name)
68                 g_free(lo->name);
69         if (lo->type)
70                 g_free(lo->type);
71         if (lo->string)
72                 g_free(lo->string);
73
74         g_slice_free(maps_place_link_object_s, place);
75         return MAPS_ERROR_NONE;
76 }
77
78 EXPORT_API int maps_place_link_object_clone(const maps_place_link_object_h origin,
79                                                                 maps_place_link_object_h *cloned)
80 {
81         if (!maps_condition_check_maps_feature())
82                 return MAPS_ERROR_NOT_SUPPORTED;
83         if (!cloned || !origin)
84                 return MAPS_ERROR_INVALID_PARAMETER;
85
86         int error = MAPS_ERROR_NONE;
87         do {
88                 error = maps_place_link_object_create(cloned);
89                 if (!(*cloned) || (error != MAPS_ERROR_NONE))
90                         break;
91
92                 maps_place_link_object_s *lo =
93                         (maps_place_link_object_s *) origin;
94
95                 if (lo->id) {
96                         error = maps_place_link_object_set_id(*cloned, lo->id);
97                         if (error != MAPS_ERROR_NONE)
98                                 break;
99                 }
100
101                 if (lo->name) {
102                         error = maps_place_link_object_set_name(*cloned, lo->name);
103                         if (error != MAPS_ERROR_NONE)
104                                 break;
105                 }
106
107                 if (lo->type) {
108                         error = maps_place_link_object_set_type(*cloned, lo->type);
109                         if (error != MAPS_ERROR_NONE)
110                                 break;
111                 }
112
113                 if (lo->string) {
114                         error = maps_place_link_object_set_string(*cloned, lo->string);
115                         if (error != MAPS_ERROR_NONE)
116                                 break;
117                 }
118
119                 return MAPS_ERROR_NONE;
120         } while (false);
121
122         //LCOV_EXCL_START
123         maps_place_link_object_destroy(*cloned);
124         *cloned = NULL;
125         return error;
126         //LCOV_EXCL_STOP
127 }
128
129 /*----------------------------------------------------------------------------*/
130
131 EXPORT_API int maps_place_link_object_get_string(const maps_place_link_object_h place,
132                                                  char **string)
133 {
134         if (!maps_condition_check_maps_feature())
135                 return MAPS_ERROR_NOT_SUPPORTED;
136         if (!place || !string)
137                 return MAPS_ERROR_INVALID_PARAMETER;
138         if (!((maps_place_link_object_s *) place)->string)
139                 return MAPS_ERROR_NOT_FOUND;
140         return maps_get_string(((maps_place_link_object_s *) place)->string,
141                 _MAPS_PLACE_LINK_OBJECT_STRING_MAX_LENGTH, string);
142 }
143
144 EXPORT_API int maps_place_link_object_get_type(const maps_place_link_object_h place,
145                                                char **type)
146 {
147         if (!maps_condition_check_maps_feature())
148                 return MAPS_ERROR_NOT_SUPPORTED;
149         if (!place || !type)
150                 return MAPS_ERROR_INVALID_PARAMETER;
151         if (!((maps_place_link_object_s *) place)->type)
152                 return MAPS_ERROR_NOT_FOUND;
153         return maps_get_string(((maps_place_link_object_s *) place)->type,
154                 _MAPS_PLACE_LINK_OBJECT_TYPE_MAX_LENGTH, type);
155 }
156
157 EXPORT_API int maps_place_link_object_get_id(const maps_place_link_object_h place,
158                                              char **id)
159 {
160         if (!maps_condition_check_maps_feature())
161                 return MAPS_ERROR_NOT_SUPPORTED;
162         if (!place || !id)
163                 return MAPS_ERROR_INVALID_PARAMETER;
164         if (!((maps_place_link_object_s *) place)->id)
165                 return MAPS_ERROR_NOT_FOUND;
166         return maps_get_string(((maps_place_link_object_s *) place)->id,
167                 _MAPS_PLACE_LINK_OBJECT_ID_MAX_LENGTH, id);
168 }
169
170 EXPORT_API int maps_place_link_object_get_name(const maps_place_link_object_h place,
171                                              char **name)
172 {
173         if (!maps_condition_check_maps_feature())
174                 return MAPS_ERROR_NOT_SUPPORTED;
175         if (!place || !name)
176                 return MAPS_ERROR_INVALID_PARAMETER;
177         if (!((maps_place_link_object_s *) place)->name)
178                 return MAPS_ERROR_NOT_FOUND;
179         return maps_get_string(((maps_place_link_object_s *) place)->name,
180                 _MAPS_PLACE_LINK_OBJECT_NAME_MAX_LENGTH, name);
181 }
182
183 /*----------------------------------------------------------------------------*/
184
185 EXPORT_API int maps_place_link_object_set_id(maps_place_link_object_h place,
186                                              const char *id)
187 {
188         if (!maps_condition_check_maps_feature())
189                 return MAPS_ERROR_NOT_SUPPORTED;
190         if (!place || !id)
191                 return MAPS_ERROR_INVALID_PARAMETER;
192         return maps_set_string(id, _MAPS_PLACE_LINK_OBJECT_ID_MAX_LENGTH,
193                 &((maps_place_link_object_s *) place)->id);
194 }
195
196 EXPORT_API int maps_place_link_object_set_string(maps_place_link_object_h place,
197                                                  const char *string)
198 {
199         if (!maps_condition_check_maps_feature())
200                 return MAPS_ERROR_NOT_SUPPORTED;
201         if (!place || !string)
202                 return MAPS_ERROR_INVALID_PARAMETER;
203         return maps_set_string(string,
204                 _MAPS_PLACE_LINK_OBJECT_STRING_MAX_LENGTH,
205                 &((maps_place_link_object_s *) place)->string);
206 }
207
208 EXPORT_API int maps_place_link_object_set_type(maps_place_link_object_h place,
209                                                const char *type)
210 {
211         if (!maps_condition_check_maps_feature())
212                 return MAPS_ERROR_NOT_SUPPORTED;
213         if (!place || !type)
214                 return MAPS_ERROR_INVALID_PARAMETER;
215         return maps_set_string(type, _MAPS_PLACE_LINK_OBJECT_TYPE_MAX_LENGTH,
216                 &((maps_place_link_object_s *) place)->type);
217 }
218
219 EXPORT_API int maps_place_link_object_set_name(maps_place_link_object_h place,
220                                                const char *name)
221 {
222         if (!maps_condition_check_maps_feature())
223                 return MAPS_ERROR_NOT_SUPPORTED;
224         if (!place || !name)
225                 return MAPS_ERROR_INVALID_PARAMETER;
226         return maps_set_string(name, _MAPS_PLACE_LINK_OBJECT_NAME_MAX_LENGTH,
227                 &((maps_place_link_object_s *) place)->name);
228 }