Add LCOV remarkers to increase line coverage rate
[platform/core/api/maps-service.git] / src / maps_util.cpp
1 /* Copyright (c) 2010-2014 Samsung Electronics Co., Ltd. All rights reserved.
2  *
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "maps_util.h"
18 #include "maps_error.h"
19 #include <glib.h>
20 #include <system_info.h>
21 #include <stdlib.h>
22
23 #define DEFAULT_UNKNOWN_DPI 132
24
25 int maps_set_string(const char *src, const int max_length, char **dst)
26 {
27         if (!dst || !src || (max_length <= 0))
28                 return MAPS_ERROR_INVALID_PARAMETER;
29         if (*dst)
30                 g_free(*dst);
31         *dst = g_strndup(src, max_length);
32         return MAPS_ERROR_NONE;
33 }
34
35 int maps_get_string(const char *src, const int max_length, char **dst)
36 {
37         if (!dst || !src || (max_length <= 0))
38                 return MAPS_ERROR_INVALID_PARAMETER;
39         *dst = g_strndup(src, max_length);
40         return MAPS_ERROR_NONE;
41 }
42
43 int maps_get_screen_dpi(int *dpi)
44 {
45         if (!dpi)
46                 return MAPS_ERROR_INVALID_PARAMETER;
47
48         static int __dpi = DEFAULT_UNKNOWN_DPI;
49         if (__dpi == DEFAULT_UNKNOWN_DPI)
50                 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &__dpi);
51         *dpi = __dpi;
52         return MAPS_ERROR_NONE;
53 }
54
55 //LCOV_EXCL_START
56 tizen_profile_t _get_tizen_profile()
57 {
58         static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
59         if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
60                 return profile;
61
62         char *profileName;
63         system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
64         switch (*profileName) {
65                 case 'm':
66                 case 'M':
67                         profile = TIZEN_PROFILE_MOBILE;
68                         break;
69                 case 'w':
70                 case 'W':
71                         profile = TIZEN_PROFILE_WEARABLE;
72                         break;
73                 case 't':
74                 case 'T':
75                         profile = TIZEN_PROFILE_TV;
76                         break;
77                 case 'i':
78                 case 'I':
79                         profile = TIZEN_PROFILE_IVI;
80                         break;
81                 default: // common or unknown ==> ALL ARE COMMON.
82                         profile = TIZEN_PROFILE_COMMON;
83         }
84         free(profileName);
85
86         return profile;
87 }
88 //LCOV_EXCL_STOP