6c98fdabe92d753ed5cd734cd082a44317fd5cb4
[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                 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
45                 return MAPS_ERROR_OUT_OF_MEMORY;
46         }
47
48         return MAPS_ERROR_NONE;
49 }
50
51 EXPORT_API int maps_place_editorial_destroy(maps_place_editorial_h place)
52 {
53         if (!maps_condition_check_maps_feature())
54                 return MAPS_ERROR_NOT_SUPPORTED;
55         if (!place)
56                 return MAPS_ERROR_INVALID_PARAMETER;
57
58         maps_place_editorial_s *e = (maps_place_editorial_s *) place;
59
60         if (e->description)
61                 g_free(e->description);
62         if (e->language)
63                 g_free(e->language);
64
65         if (e->media)
66                 maps_place_media_destroy(e->media);
67
68         g_slice_free(maps_place_editorial_s, place);
69         return MAPS_ERROR_NONE;
70 }
71
72 EXPORT_API int maps_place_editorial_clone(const maps_place_editorial_h origin,
73                                                                 maps_place_editorial_h *cloned)
74 {
75         if (!maps_condition_check_maps_feature())
76                 return MAPS_ERROR_NOT_SUPPORTED;
77         if (!cloned || !origin)
78                 return MAPS_ERROR_INVALID_PARAMETER;
79
80         int error = MAPS_ERROR_NONE;
81         do {
82                 error = maps_place_editorial_create(cloned);
83                 if (!(*cloned) || (error != MAPS_ERROR_NONE))
84                         break;
85
86                 maps_place_editorial_s *e = (maps_place_editorial_s *) origin;
87
88                 if (e->description) {
89                         error = maps_place_editorial_set_description(*cloned, e->description);
90                         if (error != MAPS_ERROR_NONE)
91                                 break;
92                 }
93
94                 if (e->language) {
95                         error = maps_place_editorial_set_language(*cloned, e->language);
96                         if (error != MAPS_ERROR_NONE)
97                                 break;
98                 }
99
100                 if (e->media) {
101                         maps_place_editorial_s *e_cloned =
102                                 (maps_place_editorial_s *) (*cloned);
103                         error = maps_place_media_clone(e->media, &e_cloned->media);
104                         if (error != MAPS_ERROR_NONE)
105                                 break;
106                 }
107
108                 return MAPS_ERROR_NONE;
109         } while (false);
110
111         maps_place_editorial_destroy(*cloned);
112         *cloned = NULL;
113         return error;
114 }
115
116 /*----------------------------------------------------------------------------*/
117
118 EXPORT_API int maps_place_editorial_get_description(const maps_place_editorial_h place,
119                                                                 char **description)
120 {
121         if (!maps_condition_check_maps_feature())
122                 return MAPS_ERROR_NOT_SUPPORTED;
123         if (!place || !description)
124                 return MAPS_ERROR_INVALID_PARAMETER;
125         if (!((maps_place_editorial_s *) place)->description)
126                 return MAPS_ERROR_NOT_FOUND;
127         return maps_get_string(((maps_place_editorial_s *) place)->description,
128                 _MAPS_PLACE_EDITORIAL_DESCRIPTION_MAX_LENGTH, description);
129 }
130
131 EXPORT_API int maps_place_editorial_get_language(const maps_place_editorial_h place,
132                                                                 char **language)
133 {
134         if (!maps_condition_check_maps_feature())
135                 return MAPS_ERROR_NOT_SUPPORTED;
136         if (!place || !language)
137                 return MAPS_ERROR_INVALID_PARAMETER;
138         if (!((maps_place_editorial_s *) place)->language)
139                 return MAPS_ERROR_NOT_FOUND;
140         return maps_get_string(((maps_place_editorial_s *) place)->language,
141                 _MAPS_PLACE_EDITORIAL_LANGUAGE_MAX_LENGTH, language);
142 }
143
144 EXPORT_API int maps_place_editorial_get_media(const maps_place_editorial_h place,
145                                                                 maps_place_media_h *media)
146 {
147         if (!maps_condition_check_maps_feature())
148                 return MAPS_ERROR_NOT_SUPPORTED;
149         if (!place || !media)
150                 return MAPS_ERROR_INVALID_PARAMETER;
151         if (!((maps_place_editorial_s *) place)->media)
152                 return MAPS_ERROR_NOT_FOUND;
153         return maps_place_media_clone(((maps_place_editorial_s *) place)->media, media);
154 }
155
156 /*----------------------------------------------------------------------------*/
157
158 EXPORT_API int maps_place_editorial_set_description(maps_place_editorial_h place,
159                                                                 const char *description)
160 {
161         if (!maps_condition_check_maps_feature())
162                 return MAPS_ERROR_NOT_SUPPORTED;
163         if (!place || !description)
164                 return MAPS_ERROR_INVALID_PARAMETER;
165         return maps_set_string(description, _MAPS_PLACE_EDITORIAL_DESCRIPTION_MAX_LENGTH,
166                 &((maps_place_editorial_s *) place)->description);
167 }
168
169 EXPORT_API int maps_place_editorial_set_language(maps_place_editorial_h place,
170                                                                 const char *language)
171 {
172         if (!maps_condition_check_maps_feature())
173                 return MAPS_ERROR_NOT_SUPPORTED;
174         if (!place || !language)
175                 return MAPS_ERROR_INVALID_PARAMETER;
176         return maps_set_string(language, _MAPS_PLACE_EDITORIAL_LANGUAGE_MAX_LENGTH,
177                 &((maps_place_editorial_s *) place)->language);
178 }
179
180 EXPORT_API int maps_place_editorial_set_media(maps_place_editorial_h place,
181                                                                 const maps_place_media_h media)
182 {
183         if (!maps_condition_check_maps_feature())
184                 return MAPS_ERROR_NOT_SUPPORTED;
185         if (!place || !media)
186                 return MAPS_ERROR_INVALID_PARAMETER;
187         maps_place_editorial_s *e = (maps_place_editorial_s *) place;
188         if (e->media)
189                 maps_place_media_destroy(e->media);
190         return maps_place_media_clone(media, &e->media);
191 }