4fba0797cd5ec6c924892e9120655a7ef21b5778
[platform/core/api/maps-service.git] / src / api / maps_place_media.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_media_plugin.h"
19 #include "maps_place_link_object_plugin.h"
20 #include "maps_util.h"
21 #include "maps_condition.h"
22
23 typedef struct _maps_place_media_s
24 {
25         char *attribution;
26         maps_place_link_object_h supplier;
27         maps_place_link_object_h via;
28 } maps_place_media_s;
29
30 const gsize _MAPS_PLACE_MEDIA_ATTRIBUTION_MAX_LENGTH = MAPS_BASE_DESC_MAX_LEN;
31
32 /*----------------------------------------------------------------------------*/
33
34 EXPORT_API int maps_place_media_create(maps_place_media_h *place)
35 {
36         if (!maps_condition_check_maps_feature())
37                 return MAPS_ERROR_NOT_SUPPORTED;
38         if (!place)
39                 return MAPS_ERROR_INVALID_PARAMETER;
40         *place = (maps_place_media_h) g_slice_new0(maps_place_media_s);
41
42         if (*place == NULL) {
43                 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
44                 return MAPS_ERROR_OUT_OF_MEMORY;
45         }
46
47         return MAPS_ERROR_NONE;
48 }
49
50 EXPORT_API int maps_place_media_destroy(maps_place_media_h place)
51 {
52         if (!maps_condition_check_maps_feature())
53                 return MAPS_ERROR_NOT_SUPPORTED;
54         if (!place)
55                 return MAPS_ERROR_INVALID_PARAMETER;
56
57         maps_place_media_s *m = (maps_place_media_s *) place;
58
59         if (m->attribution)
60                 g_free(m->attribution);
61         if (m->supplier)
62                 maps_place_link_object_destroy(m->supplier);
63         if (m->via)
64                 maps_place_link_object_destroy(m->via);
65
66         g_slice_free(maps_place_media_s, place);
67         return MAPS_ERROR_NONE;
68 }
69
70 EXPORT_API int maps_place_media_clone(const maps_place_media_h origin,
71                                                                 maps_place_media_h *cloned)
72 {
73         if (!maps_condition_check_maps_feature())
74                 return MAPS_ERROR_NOT_SUPPORTED;
75         if (!cloned || !origin)
76                 return MAPS_ERROR_INVALID_PARAMETER;
77
78         int error = MAPS_ERROR_NONE;
79         do {
80                 error = maps_place_media_create(cloned);
81                 if (!(*cloned) || (error != MAPS_ERROR_NONE))
82                         break;
83
84                 maps_place_media_s *m = (maps_place_media_s *) origin;
85
86                 if (m->attribution) {
87                         error = maps_place_media_set_attribution(*cloned, m->attribution);
88                         if (error != MAPS_ERROR_NONE)
89                                 break;
90                 }
91
92                 if (m->supplier) {
93                         error = maps_place_media_set_supplier(*cloned, m->supplier);
94                         if (error != MAPS_ERROR_NONE)
95                                 break;
96                 }
97
98                 if (m->via) {
99                         error = maps_place_media_set_via(*cloned, m->via);
100                         if (error != MAPS_ERROR_NONE)
101                                 break;
102                 }
103
104                 return MAPS_ERROR_NONE;
105         } while (false);
106
107         maps_place_media_destroy(*cloned);
108         *cloned = NULL;
109         return error;
110 }
111
112 /*----------------------------------------------------------------------------*/
113
114 EXPORT_API int maps_place_media_get_attribution(const maps_place_media_h place,
115                                                                 char **attribution)
116 {
117         if (!maps_condition_check_maps_feature())
118                 return MAPS_ERROR_NOT_SUPPORTED;
119         if (!place || !attribution)
120                 return MAPS_ERROR_INVALID_PARAMETER;
121         if (!((maps_place_media_s *) place)->attribution)
122                 return MAPS_ERROR_NOT_FOUND;
123         return maps_get_string(((maps_place_media_s *) place)->attribution,
124                 _MAPS_PLACE_MEDIA_ATTRIBUTION_MAX_LENGTH, attribution);
125 }
126
127 EXPORT_API int maps_place_media_get_supplier(const maps_place_media_h place,
128                                                                 maps_place_link_object_h *supplier)
129 {
130         if (!maps_condition_check_maps_feature())
131                 return MAPS_ERROR_NOT_SUPPORTED;
132         if (!place || !supplier)
133                 return MAPS_ERROR_INVALID_PARAMETER;
134         if (!((maps_place_media_s *) place)->supplier)
135                 return MAPS_ERROR_NOT_FOUND;
136         return maps_place_link_object_clone(((maps_place_media_s *) place)->supplier, supplier);
137 }
138
139 EXPORT_API int maps_place_media_get_via(const maps_place_media_h place,
140                                                                 maps_place_link_object_h * via)
141 {
142         if (!maps_condition_check_maps_feature())
143                 return MAPS_ERROR_NOT_SUPPORTED;
144         if (!place || !via)
145                 return MAPS_ERROR_INVALID_PARAMETER;
146         if (!((maps_place_media_s *) place)->via)
147                 return MAPS_ERROR_NOT_FOUND;
148         return maps_place_link_object_clone(((maps_place_media_s *) place)->via, via);
149 }
150
151 /*----------------------------------------------------------------------------*/
152
153 EXPORT_API int maps_place_media_set_attribution(maps_place_media_h place,
154                                                                 const char *attribution)
155 {
156         if (!maps_condition_check_maps_feature())
157                 return MAPS_ERROR_NOT_SUPPORTED;
158         if (!place || !attribution)
159                 return MAPS_ERROR_INVALID_PARAMETER;
160         return maps_set_string(attribution,
161                 _MAPS_PLACE_MEDIA_ATTRIBUTION_MAX_LENGTH,
162                 &((maps_place_media_s *) place)->attribution);
163 }
164
165 EXPORT_API int maps_place_media_set_supplier(maps_place_media_h place,
166                                                                 const maps_place_link_object_h supplier)
167 {
168         if (!maps_condition_check_maps_feature())
169                 return MAPS_ERROR_NOT_SUPPORTED;
170         if (!place || !supplier)
171                 return MAPS_ERROR_INVALID_PARAMETER;
172         maps_place_media_s *m = (maps_place_media_s *) place;
173         if (m->supplier)
174                 maps_place_link_object_destroy(m->supplier);
175         return maps_place_link_object_clone(supplier, &m->supplier);
176 }
177
178 EXPORT_API int maps_place_media_set_via(maps_place_media_h place,
179                                                                 const maps_place_link_object_h via)
180 {
181         if (!maps_condition_check_maps_feature())
182                 return MAPS_ERROR_NOT_SUPPORTED;
183         if (!place || !via)
184                 return MAPS_ERROR_INVALID_PARAMETER;
185         maps_place_media_s *m = (maps_place_media_s *) place;
186         if (m->via)
187                 maps_place_link_object_destroy(m->via);
188         return maps_place_link_object_clone(via, &m->via);
189 }