7479847cf2f23e940d6762f784cf2294c600116b
[platform/core/api/maps-service.git] / src / api / maps_place_url.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_url_plugin.h"
19 #include "maps_util.h"
20 #include "maps_condition.h"
21
22 typedef struct _maps_place_url_s
23 {
24         char *path;
25         char *desc;
26 } maps_place_url_s;
27
28 const gsize _MAPS_PLACE_URL_PATH_MAX_LENGTH = MAPS_BASE_URL_MAX_LEN;
29 const gsize _MAPS_PLACE_URL_DESC_MAX_LENGTH = MAPS_BASE_DESC_MAX_LEN;
30
31 /*----------------------------------------------------------------------------*/
32
33 EXPORT_API int maps_place_url_create(maps_place_url_h *place)
34 {
35         if (!maps_condition_check_maps_feature())
36                 return MAPS_ERROR_NOT_SUPPORTED;
37         if (!place)
38                 return MAPS_ERROR_INVALID_PARAMETER;
39
40         *place = (maps_place_url_h) g_slice_new0(maps_place_url_s);
41         if (*place == NULL) {
42                 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
43                 return MAPS_ERROR_OUT_OF_MEMORY;
44         }
45
46         return MAPS_ERROR_NONE;
47 }
48
49 EXPORT_API int maps_place_url_destroy(maps_place_url_h place)
50 {
51         if (!maps_condition_check_maps_feature())
52                 return MAPS_ERROR_NOT_SUPPORTED;
53         if (!place)
54                 return MAPS_ERROR_INVALID_PARAMETER;
55
56         maps_place_url_s *u = (maps_place_url_s *) place;
57
58         if (u->path)
59                 g_free(u->path);
60         if (u->desc)
61                 g_free(u->desc);
62
63         g_slice_free(maps_place_url_s, place);
64         return MAPS_ERROR_NONE;
65 }
66
67 EXPORT_API int maps_place_url_clone(const maps_place_url_h origin,
68                                                                 maps_place_url_h *cloned)
69 {
70         if (!maps_condition_check_maps_feature())
71                 return MAPS_ERROR_NOT_SUPPORTED;
72         if (!cloned || !origin)
73                 return MAPS_ERROR_INVALID_PARAMETER;
74
75         int error = MAPS_ERROR_NONE;
76         do {
77                 error = maps_place_url_create(cloned);
78                 if (!(*cloned) || (error != MAPS_ERROR_NONE))
79                         break;
80
81                 maps_place_url_s* u = (maps_place_url_s*) origin;
82
83                 if (u->path) {
84                         error = maps_place_url_set_path(*cloned, u->path);
85                         if (error != MAPS_ERROR_NONE)
86                                 break;
87                 }
88
89                 if (u->desc) {
90                         error = maps_place_url_set_description(*cloned,
91                                 u->desc);
92                         if (error != MAPS_ERROR_NONE)
93                                 break;
94                 }
95
96                 return MAPS_ERROR_NONE;
97         } while (false);
98
99         maps_place_url_destroy(*cloned);
100         *cloned = NULL;
101         return error;
102 }
103
104 /*----------------------------------------------------------------------------*/
105
106 EXPORT_API int maps_place_url_get_path(const maps_place_url_h place, char **path)
107 {
108         if (!maps_condition_check_maps_feature())
109                 return MAPS_ERROR_NOT_SUPPORTED;
110         if (!place || !path)
111                 return MAPS_ERROR_INVALID_PARAMETER;
112         if (!((maps_place_url_s *) place)->path)
113                 return MAPS_ERROR_NOT_FOUND;
114         return maps_get_string(((maps_place_url_s *) place)->path,
115                 _MAPS_PLACE_URL_PATH_MAX_LENGTH, path);
116 }
117
118 EXPORT_API int maps_place_url_get_description(const maps_place_url_h place, char **desc)
119 {
120         if (!maps_condition_check_maps_feature())
121                 return MAPS_ERROR_NOT_SUPPORTED;
122         if (!place || !desc)
123                 return MAPS_ERROR_INVALID_PARAMETER;
124         if (!((maps_place_url_s *) place)->desc)
125                 return MAPS_ERROR_NOT_FOUND;
126         return maps_get_string(((maps_place_url_s *) place)->desc,
127                 _MAPS_PLACE_URL_DESC_MAX_LENGTH, desc);
128 }
129
130 /*----------------------------------------------------------------------------*/
131
132 EXPORT_API int maps_place_url_set_path(maps_place_url_h place, const char *path)
133 {
134         if (!maps_condition_check_maps_feature())
135                 return MAPS_ERROR_NOT_SUPPORTED;
136         if (!place || !path)
137                 return MAPS_ERROR_INVALID_PARAMETER;
138         return maps_set_string(path, _MAPS_PLACE_URL_PATH_MAX_LENGTH,
139                 &((maps_place_url_s *) place)->path);
140 }
141
142 EXPORT_API int maps_place_url_set_description(maps_place_url_h place,
143                                                                 const char *desc)
144 {
145         if (!maps_condition_check_maps_feature())
146                 return MAPS_ERROR_NOT_SUPPORTED;
147         if (!place || !desc)
148                 return MAPS_ERROR_INVALID_PARAMETER;
149         return maps_set_string(desc, _MAPS_PLACE_URL_DESC_MAX_LENGTH,
150                 &((maps_place_url_s *) place)->desc);
151 }