1 /* Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
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
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
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"
23 typedef struct _maps_place_media_s
26 maps_place_link_object_h supplier;
27 maps_place_link_object_h via;
30 const gsize _MAPS_PLACE_MEDIA_ATTRIBUTION_MAX_LENGTH = MAPS_BASE_DESC_MAX_LEN;
32 /*----------------------------------------------------------------------------*/
34 EXPORT_API int maps_place_media_create(maps_place_media_h *place)
36 if (!maps_condition_check_maps_feature())
37 return MAPS_ERROR_NOT_SUPPORTED;
39 return MAPS_ERROR_INVALID_PARAMETER;
40 *place = (maps_place_media_h) g_slice_new0(maps_place_media_s);
43 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
44 return MAPS_ERROR_OUT_OF_MEMORY;
47 return MAPS_ERROR_NONE;
50 EXPORT_API int maps_place_media_destroy(maps_place_media_h place)
52 if (!maps_condition_check_maps_feature())
53 return MAPS_ERROR_NOT_SUPPORTED;
55 return MAPS_ERROR_INVALID_PARAMETER;
57 maps_place_media_s *m = (maps_place_media_s *) place;
60 g_free(m->attribution);
62 maps_place_link_object_destroy(m->supplier);
64 maps_place_link_object_destroy(m->via);
66 g_slice_free(maps_place_media_s, place);
67 return MAPS_ERROR_NONE;
70 EXPORT_API int maps_place_media_clone(const maps_place_media_h origin,
71 maps_place_media_h *cloned)
73 if (!maps_condition_check_maps_feature())
74 return MAPS_ERROR_NOT_SUPPORTED;
75 if (!cloned || !origin)
76 return MAPS_ERROR_INVALID_PARAMETER;
78 int error = MAPS_ERROR_NONE;
80 error = maps_place_media_create(cloned);
81 if (!(*cloned) || (error != MAPS_ERROR_NONE))
84 maps_place_media_s *m = (maps_place_media_s *) origin;
87 error = maps_place_media_set_attribution(*cloned, m->attribution);
88 if (error != MAPS_ERROR_NONE)
93 error = maps_place_media_set_supplier(*cloned, m->supplier);
94 if (error != MAPS_ERROR_NONE)
99 error = maps_place_media_set_via(*cloned, m->via);
100 if (error != MAPS_ERROR_NONE)
104 return MAPS_ERROR_NONE;
107 maps_place_media_destroy(*cloned);
112 /*----------------------------------------------------------------------------*/
114 EXPORT_API int maps_place_media_get_attribution(const maps_place_media_h place,
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);
127 EXPORT_API int maps_place_media_get_supplier(const maps_place_media_h place,
128 maps_place_link_object_h *supplier)
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);
139 EXPORT_API int maps_place_media_get_via(const maps_place_media_h place,
140 maps_place_link_object_h * via)
142 if (!maps_condition_check_maps_feature())
143 return MAPS_ERROR_NOT_SUPPORTED;
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);
151 /*----------------------------------------------------------------------------*/
153 EXPORT_API int maps_place_media_set_attribution(maps_place_media_h place,
154 const char *attribution)
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);
165 EXPORT_API int maps_place_media_set_supplier(maps_place_media_h place,
166 const maps_place_link_object_h supplier)
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;
174 maps_place_link_object_destroy(m->supplier);
175 return maps_place_link_object_clone(supplier, &m->supplier);
178 EXPORT_API int maps_place_media_set_via(maps_place_media_h place,
179 const maps_place_link_object_h via)
181 if (!maps_condition_check_maps_feature())
182 return MAPS_ERROR_NOT_SUPPORTED;
184 return MAPS_ERROR_INVALID_PARAMETER;
185 maps_place_media_s *m = (maps_place_media_s *) place;
187 maps_place_link_object_destroy(m->via);
188 return maps_place_link_object_clone(via, &m->via);