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_attribute_plugin.h"
19 #include "maps_util.h"
20 #include "maps_condition.h"
22 typedef struct _maps_place_attribute_s
27 } maps_place_attribute_s;
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;
33 /*----------------------------------------------------------------------------*/
35 EXPORT_API int maps_place_attribute_create(maps_place_attribute_h *place)
37 if (!maps_condition_check_maps_feature())
38 return MAPS_ERROR_NOT_SUPPORTED;
40 return MAPS_ERROR_INVALID_PARAMETER;
41 *place = (maps_place_attribute_h) g_slice_new0(maps_place_attribute_s);
44 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
45 return MAPS_ERROR_OUT_OF_MEMORY;
48 return MAPS_ERROR_NONE;
51 EXPORT_API int maps_place_attribute_destroy(maps_place_attribute_h place)
53 if (!maps_condition_check_maps_feature())
54 return MAPS_ERROR_NOT_SUPPORTED;
56 return MAPS_ERROR_INVALID_PARAMETER;
58 maps_place_attribute_s *a = (maps_place_attribute_s *) place;
67 g_slice_free(maps_place_attribute_s, place);
68 return MAPS_ERROR_NONE;
71 EXPORT_API int maps_place_attribute_clone(const maps_place_attribute_h origin,
72 maps_place_attribute_h *cloned)
74 if (!maps_condition_check_maps_feature())
75 return MAPS_ERROR_NOT_SUPPORTED;
76 if (!cloned || !origin)
77 return MAPS_ERROR_INVALID_PARAMETER;
79 int error = MAPS_ERROR_NONE;
81 error = maps_place_attribute_create(cloned);
82 if (!(*cloned) || (error != MAPS_ERROR_NONE))
85 maps_place_attribute_s *a = (maps_place_attribute_s *) origin;
88 error = maps_place_attribute_set_id(*cloned, a->id);
89 if (error != MAPS_ERROR_NONE)
94 error = maps_place_attribute_set_label(*cloned,
96 if (error != MAPS_ERROR_NONE)
101 error = maps_place_attribute_set_text(*cloned, a->text);
102 if (error != MAPS_ERROR_NONE)
106 return MAPS_ERROR_NONE;
109 maps_place_attribute_destroy(*cloned);
114 /*----------------------------------------------------------------------------*/
116 EXPORT_API int maps_place_attribute_get_id(const maps_place_attribute_h place, char **id)
118 if (!maps_condition_check_maps_feature())
119 return MAPS_ERROR_NOT_SUPPORTED;
121 return MAPS_ERROR_INVALID_PARAMETER;
122 if (!((maps_place_attribute_s *) place)->id)
123 return MAPS_ERROR_NOT_FOUND;
124 return maps_get_string(((maps_place_attribute_s *) place)->id,
125 _MAPS_PLACE_ATTRIBUTE_ID_MAX_LENGTH, id);
128 EXPORT_API int maps_place_attribute_get_text(const maps_place_attribute_h place, char **text)
130 if (!maps_condition_check_maps_feature())
131 return MAPS_ERROR_NOT_SUPPORTED;
133 return MAPS_ERROR_INVALID_PARAMETER;
134 if (!((maps_place_attribute_s *) place)->text)
135 return MAPS_ERROR_NOT_FOUND;
136 return maps_get_string(((maps_place_attribute_s *) place)->text,
137 _MAPS_PLACE_ATTRIBUTE_TEXT_MAX_LENGTH, text);
140 EXPORT_API int maps_place_attribute_get_label(const maps_place_attribute_h place, char **label)
142 if (!maps_condition_check_maps_feature())
143 return MAPS_ERROR_NOT_SUPPORTED;
144 if (!place || !label)
145 return MAPS_ERROR_INVALID_PARAMETER;
146 if (!((maps_place_attribute_s *) place)->label)
147 return MAPS_ERROR_NOT_FOUND;
148 return maps_get_string(((maps_place_attribute_s *) place)->label,
149 _MAPS_PLACE_ATTRIBUTE_LABEL_MAX_LENGTH, label);
152 /*----------------------------------------------------------------------------*/
154 EXPORT_API int maps_place_attribute_set_id(maps_place_attribute_h place, const char * id)
156 if (!maps_condition_check_maps_feature())
157 return MAPS_ERROR_NOT_SUPPORTED;
159 return MAPS_ERROR_INVALID_PARAMETER;
160 return maps_set_string(id, _MAPS_PLACE_ATTRIBUTE_ID_MAX_LENGTH,
161 &((maps_place_attribute_s *) place)->id);
164 EXPORT_API int maps_place_attribute_set_label(maps_place_attribute_h place, const char *label)
166 if (!maps_condition_check_maps_feature())
167 return MAPS_ERROR_NOT_SUPPORTED;
168 if (!place || !label)
169 return MAPS_ERROR_INVALID_PARAMETER;
170 return maps_set_string(label, _MAPS_PLACE_ATTRIBUTE_LABEL_MAX_LENGTH,
171 &((maps_place_attribute_s *) place)->label);
174 EXPORT_API int maps_place_attribute_set_text(maps_place_attribute_h place, const char *text)
176 if (!maps_condition_check_maps_feature())
177 return MAPS_ERROR_NOT_SUPPORTED;
179 return MAPS_ERROR_INVALID_PARAMETER;
180 return maps_set_string(text, _MAPS_PLACE_ATTRIBUTE_TEXT_MAX_LENGTH,
181 &((maps_place_attribute_s *) place)->text);