Add LCOV remarkers to increase line coverage rate
[platform/core/api/maps-service.git] / src / api / maps_place_editorial.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_editorial_plugin.h"
19 #include "maps_place_media_plugin.h"
20 #include "maps_util.h"
21 #include "maps_condition.h"
22
23 typedef struct _maps_place_editorial_s
24 {
25         char *description;
26         char *language;
27         maps_place_media_h media;
28 } maps_place_editorial_s;
29
30 const gsize _MAPS_PLACE_EDITORIAL_DESCRIPTION_MAX_LENGTH = MAPS_BASE_DESC_MAX_LEN;
31 const gsize _MAPS_PLACE_EDITORIAL_LANGUAGE_MAX_LENGTH = MAPS_BASE_TYPE_MAX_LEN;
32
33 /*----------------------------------------------------------------------------*/
34
35 EXPORT_API int maps_place_editorial_create(maps_place_editorial_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
42         *place = (maps_place_editorial_h) g_slice_new0(maps_place_editorial_s);
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_editorial_destroy(maps_place_editorial_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_editorial_s *e = (maps_place_editorial_s *) place;
61
62         if (e->description)
63                 g_free(e->description);
64         if (e->language)
65                 g_free(e->language);
66
67         if (e->media)
68                 maps_place_media_destroy(e->media);
69
70         g_slice_free(maps_place_editorial_s, place);
71         return MAPS_ERROR_NONE;
72 }
73
74 EXPORT_API int maps_place_editorial_clone(const maps_place_editorial_h origin,
75                                                                 maps_place_editorial_h *cloned)
76 {
77         if (!maps_condition_check_maps_feature())
78                 return MAPS_ERROR_NOT_SUPPORTED;
79         if (!cloned || !origin)
80                 return MAPS_ERROR_INVALID_PARAMETER;
81
82         int error = MAPS_ERROR_NONE;
83         do {
84                 error = maps_place_editorial_create(cloned);
85                 if (!(*cloned) || (error != MAPS_ERROR_NONE))
86                         break;
87
88                 maps_place_editorial_s *e = (maps_place_editorial_s *) origin;
89
90                 if (e->description) {
91                         error = maps_place_editorial_set_description(*cloned, e->description);
92                         if (error != MAPS_ERROR_NONE)
93                                 break;
94                 }
95
96                 if (e->language) {
97                         error = maps_place_editorial_set_language(*cloned, e->language);
98                         if (error != MAPS_ERROR_NONE)
99                                 break;
100                 }
101
102                 if (e->media) {
103                         maps_place_editorial_s *e_cloned =
104                                 (maps_place_editorial_s *) (*cloned);
105                         error = maps_place_media_clone(e->media, &e_cloned->media);
106                         if (error != MAPS_ERROR_NONE)
107                                 break;
108                 }
109
110                 return MAPS_ERROR_NONE;
111         } while (false);
112
113         //LCOV_EXCL_START
114         maps_place_editorial_destroy(*cloned);
115         *cloned = NULL;
116         return error;
117         //LCOV_EXCL_STOP
118 }
119
120 /*----------------------------------------------------------------------------*/
121
122 EXPORT_API int maps_place_editorial_get_description(const maps_place_editorial_h place,
123                                                                 char **description)
124 {
125         if (!maps_condition_check_maps_feature())
126                 return MAPS_ERROR_NOT_SUPPORTED;
127         if (!place || !description)
128                 return MAPS_ERROR_INVALID_PARAMETER;
129         if (!((maps_place_editorial_s *) place)->description)
130                 return MAPS_ERROR_NOT_FOUND;
131         return maps_get_string(((maps_place_editorial_s *) place)->description,
132                 _MAPS_PLACE_EDITORIAL_DESCRIPTION_MAX_LENGTH, description);
133 }
134
135 EXPORT_API int maps_place_editorial_get_language(const maps_place_editorial_h place,
136                                                                 char **language)
137 {
138         if (!maps_condition_check_maps_feature())
139                 return MAPS_ERROR_NOT_SUPPORTED;
140         if (!place || !language)
141                 return MAPS_ERROR_INVALID_PARAMETER;
142         if (!((maps_place_editorial_s *) place)->language)
143                 return MAPS_ERROR_NOT_FOUND;
144         return maps_get_string(((maps_place_editorial_s *) place)->language,
145                 _MAPS_PLACE_EDITORIAL_LANGUAGE_MAX_LENGTH, language);
146 }
147
148 EXPORT_API int maps_place_editorial_get_media(const maps_place_editorial_h place,
149                                                                 maps_place_media_h *media)
150 {
151         if (!maps_condition_check_maps_feature())
152                 return MAPS_ERROR_NOT_SUPPORTED;
153         if (!place || !media)
154                 return MAPS_ERROR_INVALID_PARAMETER;
155         if (!((maps_place_editorial_s *) place)->media)
156                 return MAPS_ERROR_NOT_FOUND;
157         return maps_place_media_clone(((maps_place_editorial_s *) place)->media, media);
158 }
159
160 /*----------------------------------------------------------------------------*/
161
162 EXPORT_API int maps_place_editorial_set_description(maps_place_editorial_h place,
163                                                                 const char *description)
164 {
165         if (!maps_condition_check_maps_feature())
166                 return MAPS_ERROR_NOT_SUPPORTED;
167         if (!place || !description)
168                 return MAPS_ERROR_INVALID_PARAMETER;
169         return maps_set_string(description, _MAPS_PLACE_EDITORIAL_DESCRIPTION_MAX_LENGTH,
170                 &((maps_place_editorial_s *) place)->description);
171 }
172
173 EXPORT_API int maps_place_editorial_set_language(maps_place_editorial_h place,
174                                                                 const char *language)
175 {
176         if (!maps_condition_check_maps_feature())
177                 return MAPS_ERROR_NOT_SUPPORTED;
178         if (!place || !language)
179                 return MAPS_ERROR_INVALID_PARAMETER;
180         return maps_set_string(language, _MAPS_PLACE_EDITORIAL_LANGUAGE_MAX_LENGTH,
181                 &((maps_place_editorial_s *) place)->language);
182 }
183
184 EXPORT_API int maps_place_editorial_set_media(maps_place_editorial_h place,
185                                                                 const maps_place_media_h media)
186 {
187         if (!maps_condition_check_maps_feature())
188                 return MAPS_ERROR_NOT_SUPPORTED;
189         if (!place || !media)
190                 return MAPS_ERROR_INVALID_PARAMETER;
191         maps_place_editorial_s *e = (maps_place_editorial_s *) place;
192         if (e->media)
193                 maps_place_media_destroy(e->media);
194         return maps_place_media_clone(media, &e->media);
195 }