Add LCOV remarkers to increase line coverage rate
[platform/core/api/maps-service.git] / src / api / maps_place_contact.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_contact_plugin.h"
19 #include "maps_util.h"
20 #include "maps_condition.h"
21
22 typedef struct _maps_place_contact_s
23 {
24         char *label;
25         char *type;
26         char * value;
27 } maps_place_contact_s;
28
29 const gsize _MAPS_PLACE_CONTACT_LABEL_MAX_LENGTH = MAPS_BASE_NAME_MAX_LEN;
30 const gsize _MAPS_PLACE_CONTACT_TYPE_MAX_LENGTH = MAPS_BASE_TYPE_MAX_LEN;
31 const gsize _MAPS_PLACE_CONTACT_VALUE_MAX_LENGTH = MAPS_BASE_DESC_MAX_LEN;
32
33 /*----------------------------------------------------------------------------*/
34
35 EXPORT_API int maps_place_contact_create(maps_place_contact_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_contact_h) g_slice_new0(maps_place_contact_s);
43         if (*place == NULL) {
44                 //LCOV_EXCL_START
45                 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
46                 return MAPS_ERROR_OUT_OF_MEMORY;
47                 //LCOV_EXCL_STOP
48         }
49
50         return MAPS_ERROR_NONE;
51 }
52
53 EXPORT_API int maps_place_contact_destroy(maps_place_contact_h place)
54 {
55         if (!maps_condition_check_maps_feature())
56                 return MAPS_ERROR_NOT_SUPPORTED;
57         if (!place)
58                 return MAPS_ERROR_INVALID_PARAMETER;
59
60         maps_place_contact_s *c = (maps_place_contact_s *) place;
61
62         if (c->label)
63                 g_free(c->label);
64         if (c->type)
65                 g_free(c->type);
66         if (c->value)
67                 g_free(c->value);
68
69         g_slice_free(maps_place_contact_s, place);
70         return MAPS_ERROR_NONE;
71 }
72
73 EXPORT_API int maps_place_contact_clone(const maps_place_contact_h origin,
74                                         maps_place_contact_h *cloned)
75 {
76         if (!maps_condition_check_maps_feature())
77                 return MAPS_ERROR_NOT_SUPPORTED;
78         if (!cloned || !origin)
79                 return MAPS_ERROR_INVALID_PARAMETER;
80
81         int error = MAPS_ERROR_NONE;
82         do {
83                 error = maps_place_contact_create(cloned);
84                 if (!(*cloned) || (error != MAPS_ERROR_NONE))
85                         break;
86
87                 maps_place_contact_s *c = (maps_place_contact_s *) origin;
88
89                 if (c->label) {
90                         error = maps_place_contact_set_label(*cloned, c->label);
91                         if (error != MAPS_ERROR_NONE)
92                                 break;
93                 }
94
95                 if (c->type) {
96                         error = maps_place_contact_set_type(*cloned, c->type);
97                         if (error != MAPS_ERROR_NONE)
98                                 break;
99                 }
100
101                 if (c->value) {
102                         error = maps_place_contact_set_value(*cloned, c->value);
103                         if (error != MAPS_ERROR_NONE)
104                                 break;
105                 }
106
107                 return MAPS_ERROR_NONE;
108         } while (false);
109
110         //LCOV_EXCL_START
111         maps_place_contact_destroy(*cloned);
112         *cloned = NULL;
113         return error;
114         //LCOV_EXCL_STOP
115 }
116
117 /*----------------------------------------------------------------------------*/
118
119 EXPORT_API int maps_place_contact_get_label(const maps_place_contact_h place, char **label)
120 {
121         if (!maps_condition_check_maps_feature())
122                 return MAPS_ERROR_NOT_SUPPORTED;
123         if (!place || !label)
124                 return MAPS_ERROR_INVALID_PARAMETER;
125         if (!((maps_place_contact_s *) place)->label)
126                 return MAPS_ERROR_NOT_FOUND;
127         return maps_get_string(((maps_place_contact_s *) place)->label,
128                 _MAPS_PLACE_CONTACT_LABEL_MAX_LENGTH, label);
129 }
130
131 EXPORT_API int maps_place_contact_get_type(const maps_place_contact_h place, char **type)
132 {
133         if (!maps_condition_check_maps_feature())
134                 return MAPS_ERROR_NOT_SUPPORTED;
135         if (!place || !type)
136                 return MAPS_ERROR_INVALID_PARAMETER;
137         if (!((maps_place_contact_s *) place)->type)
138                 return MAPS_ERROR_NOT_FOUND;
139         return maps_get_string(((maps_place_contact_s *) place)->type,
140                 _MAPS_PLACE_CONTACT_TYPE_MAX_LENGTH, type);
141 }
142
143 EXPORT_API int maps_place_contact_get_value(const maps_place_contact_h place, char **value)
144 {
145         if (!maps_condition_check_maps_feature())
146                 return MAPS_ERROR_NOT_SUPPORTED;
147         if (!place || !value)
148                 return MAPS_ERROR_INVALID_PARAMETER;
149         if (!((maps_place_contact_s *) place)->value)
150                 return MAPS_ERROR_NOT_FOUND;
151         return maps_get_string(((maps_place_contact_s *) place)->value,
152                 _MAPS_PLACE_CONTACT_VALUE_MAX_LENGTH, value);
153 }
154
155 /*----------------------------------------------------------------------------*/
156
157 EXPORT_API int maps_place_contact_set_label(maps_place_contact_h place, const char *label)
158 {
159         if (!maps_condition_check_maps_feature())
160                 return MAPS_ERROR_NOT_SUPPORTED;
161         if (!place || !label)
162                 return MAPS_ERROR_INVALID_PARAMETER;
163         return maps_set_string(label, _MAPS_PLACE_CONTACT_LABEL_MAX_LENGTH,
164                 &((maps_place_contact_s *) place)->label);
165 }
166
167 EXPORT_API int maps_place_contact_set_type(maps_place_contact_h place, const char *type)
168 {
169         if (!maps_condition_check_maps_feature())
170                 return MAPS_ERROR_NOT_SUPPORTED;
171         if (!place || !type)
172                 return MAPS_ERROR_INVALID_PARAMETER;
173         return maps_set_string(type, _MAPS_PLACE_CONTACT_TYPE_MAX_LENGTH,
174                 &((maps_place_contact_s *) place)->type);
175 }
176
177 EXPORT_API int maps_place_contact_set_value(maps_place_contact_h place, const char *value)
178 {
179         if (!maps_condition_check_maps_feature())
180                 return MAPS_ERROR_NOT_SUPPORTED;
181         if (!place || !value)
182                 return MAPS_ERROR_INVALID_PARAMETER;
183         return maps_set_string(value, _MAPS_PLACE_CONTACT_VALUE_MAX_LENGTH,
184                 &((maps_place_contact_s *) place)->value);
185 }