Add LCOV remarkers to increase line coverage rate
[platform/core/api/maps-service.git] / src / api / maps_plugin_info.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_plugin_info.h"
19 #include "maps_util.h"
20 #include "maps_condition.h"
21
22 typedef struct _maps_plugin_info_s
23 {
24         char *provider_name;
25 } maps_plugin_info_s;
26
27 const gsize _MAPS_PLUGIN_INFO_NAME_MAX_LENGTH = MAPS_BASE_NAME_MAX_LEN;
28
29 /*----------------------------------------------------------------------------*/
30
31 EXPORT_API int maps_plugin_info_create(maps_plugin_info_h *info)
32 {
33         if (!maps_condition_check_maps_feature())
34                 return MAPS_ERROR_NOT_SUPPORTED;
35         if (!info)
36                 return MAPS_ERROR_INVALID_PARAMETER;
37         *info = g_slice_new0(maps_plugin_info_s);
38
39         if (*info == NULL) {
40                 //LCOV_EXCL_START
41                 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
42                 return MAPS_ERROR_OUT_OF_MEMORY;
43                 //LCOV_EXCL_STOP
44         }
45
46         return MAPS_ERROR_NONE;
47 }
48
49 EXPORT_API int maps_plugin_info_destroy(maps_plugin_info_h info)
50 {
51         if (!maps_condition_check_maps_feature())
52                 return MAPS_ERROR_NOT_SUPPORTED;
53         if (!info)
54                 return MAPS_ERROR_INVALID_PARAMETER;
55         int error = MAPS_ERROR_NONE;
56
57         maps_plugin_info_s *c = (maps_plugin_info_s *) info;
58
59         if (c->provider_name)
60                 g_free(c->provider_name);
61
62         g_slice_free(maps_plugin_info_s, info);
63         return error;
64 }
65
66 EXPORT_API int maps_plugin_info_clone(const maps_plugin_info_h origin,
67                                       maps_plugin_info_h *cloned)
68 {
69         if (!maps_condition_check_maps_feature())
70                 return MAPS_ERROR_NOT_SUPPORTED;
71         if (!cloned || !origin)
72                 return MAPS_ERROR_INVALID_PARAMETER;
73
74         int error = MAPS_ERROR_NONE;
75
76         do {
77                 error = maps_plugin_info_create(cloned);
78                 if (error != MAPS_ERROR_NONE)
79                         break;
80
81                 maps_plugin_info_s *c = (maps_plugin_info_s *) origin;
82
83                 if (c->provider_name) {
84                         error = maps_plugin_info_set_provider_name(*cloned, c->provider_name);
85                         if (error != MAPS_ERROR_NONE)
86                                 break;
87                 }
88
89                 return MAPS_ERROR_NONE;
90         } while (false);
91
92         //LCOV_EXCL_START
93         maps_plugin_info_destroy(*cloned);
94         *cloned = NULL;
95         return error;
96         //LCOV_EXCL_STOP
97 }
98
99 /*----------------------------------------------------------------------------*/
100
101 EXPORT_API int maps_plugin_info_get_provider_name(const maps_plugin_info_h info,
102                                                   char **provider_name)
103 {
104         if (!maps_condition_check_maps_feature())
105                 return MAPS_ERROR_NOT_SUPPORTED;
106         if (!info || !provider_name)
107                 return MAPS_ERROR_INVALID_PARAMETER;
108         return maps_get_string(((maps_plugin_info_s *) info)->provider_name,
109                 _MAPS_PLUGIN_INFO_NAME_MAX_LENGTH, provider_name);
110 }
111
112 /*----------------------------------------------------------------------------*/
113
114 EXPORT_API int maps_plugin_info_set_provider_name(maps_plugin_info_h info,
115                                                   const char *provider_name)
116 {
117         if (!maps_condition_check_maps_feature())
118                 return MAPS_ERROR_NOT_SUPPORTED;
119         if (!info || !provider_name)
120                 return MAPS_ERROR_INVALID_PARAMETER;
121         return maps_set_string(provider_name, _MAPS_PLUGIN_INFO_NAME_MAX_LENGTH,
122                 &((maps_plugin_info_s *) info)->provider_name);
123 }