Add LCOV remarkers to increase line coverage rate
[platform/core/api/maps-service.git] / src / api / maps_place_attribute.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_attribute_plugin.h"
19 #include "maps_util.h"
20 #include "maps_condition.h"
21
22 typedef struct _maps_place_attribute_s
23 {
24         char *id;
25         char *label;
26         char *text;
27 } maps_place_attribute_s;
28
29 const gsize _MAPS_PLACE_ATTRIBUTE_ID_MAX_LENGTH = MAPS_BASE_ID_MAX_LEN;
30 const gsize _MAPS_PLACE_ATTRIBUTE_LABEL_MAX_LENGTH = MAPS_BASE_NAME_MAX_LEN;
31 const gsize _MAPS_PLACE_ATTRIBUTE_TEXT_MAX_LENGTH = MAPS_BASE_DESC_MAX_LEN;
32
33 /*----------------------------------------------------------------------------*/
34
35 EXPORT_API int maps_place_attribute_create(maps_place_attribute_h *place)
36 {
37         if (!maps_condition_check_maps_feature())
38                 return MAPS_ERROR_NOT_SUPPORTED;
39         if (!place)
40                 return MAPS_ERROR_INVALID_PARAMETER;
41         *place = (maps_place_attribute_h) g_slice_new0(maps_place_attribute_s);
42
43         if (*place == NULL) {
44                 //LCOV_EXCL_START
45                 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
46                 return MAPS_ERROR_OUT_OF_MEMORY;
47                 //LCOV_EXCL_STOP
48         }
49
50         return MAPS_ERROR_NONE;
51 }
52
53 EXPORT_API int maps_place_attribute_destroy(maps_place_attribute_h place)
54 {
55         if (!maps_condition_check_maps_feature())
56                 return MAPS_ERROR_NOT_SUPPORTED;
57         if (!place)
58                 return MAPS_ERROR_INVALID_PARAMETER;
59
60         maps_place_attribute_s *a = (maps_place_attribute_s *) place;
61
62         if (a->id)
63                 g_free(a->id);
64         if (a->label)
65                 g_free(a->label);
66         if (a->text)
67                 g_free(a->text);
68
69         g_slice_free(maps_place_attribute_s, place);
70         return MAPS_ERROR_NONE;
71 }
72
73 EXPORT_API int maps_place_attribute_clone(const maps_place_attribute_h origin,
74                                                                 maps_place_attribute_h *cloned)
75 {
76         if (!maps_condition_check_maps_feature())
77                 return MAPS_ERROR_NOT_SUPPORTED;
78         if (!cloned || !origin)
79                 return MAPS_ERROR_INVALID_PARAMETER;
80
81         int error = MAPS_ERROR_NONE;
82         do {
83                 error = maps_place_attribute_create(cloned);
84                 if (!(*cloned) || (error != MAPS_ERROR_NONE))
85                         break;
86
87                 maps_place_attribute_s *a = (maps_place_attribute_s *) origin;
88
89                 if (a->id) {
90                         error = maps_place_attribute_set_id(*cloned, a->id);
91                         if (error != MAPS_ERROR_NONE)
92                                 break;
93                 }
94
95                 if (a->label) {
96                         error = maps_place_attribute_set_label(*cloned,
97                                 a->label);
98                         if (error != MAPS_ERROR_NONE)
99                                 break;
100                 }
101
102                 if (a->text) {
103                         error = maps_place_attribute_set_text(*cloned, a->text);
104                         if (error != MAPS_ERROR_NONE)
105                                 break;
106                 }
107
108                 return MAPS_ERROR_NONE;
109         } while (false);
110
111         //LCOV_EXCL_START
112         maps_place_attribute_destroy(*cloned);
113         *cloned = NULL;
114         return error;
115         //LCOV_EXCL_STOP
116 }
117
118 /*----------------------------------------------------------------------------*/
119
120 EXPORT_API int maps_place_attribute_get_id(const maps_place_attribute_h place, char **id)
121 {
122         if (!maps_condition_check_maps_feature())
123                 return MAPS_ERROR_NOT_SUPPORTED;
124         if (!place || !id)
125                 return MAPS_ERROR_INVALID_PARAMETER;
126         if (!((maps_place_attribute_s *) place)->id)
127                 return MAPS_ERROR_NOT_FOUND;
128         return maps_get_string(((maps_place_attribute_s *) place)->id,
129                 _MAPS_PLACE_ATTRIBUTE_ID_MAX_LENGTH, id);
130 }
131
132 EXPORT_API int maps_place_attribute_get_text(const maps_place_attribute_h place, char **text)
133 {
134         if (!maps_condition_check_maps_feature())
135                 return MAPS_ERROR_NOT_SUPPORTED;
136         if (!place || !text)
137                 return MAPS_ERROR_INVALID_PARAMETER;
138         if (!((maps_place_attribute_s *) place)->text)
139                 return MAPS_ERROR_NOT_FOUND;
140         return maps_get_string(((maps_place_attribute_s *) place)->text,
141                 _MAPS_PLACE_ATTRIBUTE_TEXT_MAX_LENGTH, text);
142 }
143
144 EXPORT_API int maps_place_attribute_get_label(const maps_place_attribute_h place, char **label)
145 {
146         if (!maps_condition_check_maps_feature())
147                 return MAPS_ERROR_NOT_SUPPORTED;
148         if (!place || !label)
149                 return MAPS_ERROR_INVALID_PARAMETER;
150         if (!((maps_place_attribute_s *) place)->label)
151                 return MAPS_ERROR_NOT_FOUND;
152         return maps_get_string(((maps_place_attribute_s *) place)->label,
153                 _MAPS_PLACE_ATTRIBUTE_LABEL_MAX_LENGTH, label);
154 }
155
156 /*----------------------------------------------------------------------------*/
157
158 EXPORT_API int maps_place_attribute_set_id(maps_place_attribute_h place, const 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         return maps_set_string(id, _MAPS_PLACE_ATTRIBUTE_ID_MAX_LENGTH,
165                 &((maps_place_attribute_s *) place)->id);
166 }
167
168 EXPORT_API int maps_place_attribute_set_label(maps_place_attribute_h place, const char *label)
169 {
170         if (!maps_condition_check_maps_feature())
171                 return MAPS_ERROR_NOT_SUPPORTED;
172         if (!place || !label)
173                 return MAPS_ERROR_INVALID_PARAMETER;
174         return maps_set_string(label, _MAPS_PLACE_ATTRIBUTE_LABEL_MAX_LENGTH,
175                 &((maps_place_attribute_s *) place)->label);
176 }
177
178 EXPORT_API int maps_place_attribute_set_text(maps_place_attribute_h place, const char *text)
179 {
180         if (!maps_condition_check_maps_feature())
181                 return MAPS_ERROR_NOT_SUPPORTED;
182         if (!place || !text)
183                 return MAPS_ERROR_INVALID_PARAMETER;
184         return maps_set_string(text, _MAPS_PLACE_ATTRIBUTE_TEXT_MAX_LENGTH,
185                 &((maps_place_attribute_s *) place)->text);
186 }