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.
16 #ifndef __MAPS_UTIL_H__
17 #define __MAPS_UTIL_H__
25 #define EXPORT_API __attribute__((__visibility__("default")))
31 #define LOG_TAG "CAPI_MAPS_SERVICE"
33 #define MAPS_BASE_ID_MAX_LEN 128
34 #define MAPS_BASE_NAME_MAX_LEN 128
35 #define MAPS_BASE_URL_MAX_LEN 512
36 #define MAPS_BASE_DESC_MAX_LEN 1024
37 #define MAPS_BASE_TYPE_MAX_LEN 64
38 #define MAPS_BASE_DATE_MAX_LEN 32
39 #define MAPS_PLUGINS_PATH_PREFIX LIBDIR"/maps/plugins"
44 #define MAPS_LOGD(fmt, args...) LOGD(fmt, ##args)
45 #define MAPS_LOGW(fmt, args...) LOGW(fmt, ##args)
46 #define MAPS_LOGI(fmt, args...) LOGI(fmt, ##args)
47 #define MAPS_LOGE(fmt, args...) LOGE(fmt, ##args)
48 #define MAPS_SECLOG(fmt, args...) SECURE_LOGD(fmt, ##args)
50 #define MAPS_CHECK_CONDITION(condition, error, msg) \
54 MAPS_LOGE("%s(0x%08x)", msg, error); \
59 #define MAPS_NULL_ARG_CHECK_RETURN_FALSE(arg)\
63 MAPS_LOGE("MAPS_ERROR_INVALID_PARAMETER"); \
67 #define MAPS_NULL_ARG_CHECK(arg) \
68 MAPS_CHECK_CONDITION(arg != NULL, MAPS_ERROR_INVALID_PARAMETER, "MAPS_ERROR_INVALID_PARAMETER")
70 #define MAPS_PRINT_ERROR_CODE_RETURN(code) \
72 MAPS_LOGE("%s(0x%08x)", #code, code); \
77 #define VERSION(a, b, c) (((a) << 16) + ((b) << 8) + (c))
79 /*----------------------------------------------------------------------------*/
84 * @brief Copies one string to another and releases receiver if needed.
85 * @details This function copies one string to another and releases receiver if
87 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 2.3.2 @endif
89 * @param[out] dst The destination string pointer.
90 * @param[in] src The original string pointer.
91 * @param[in] max_length The maximum size of bytes to be copied.
92 * @return 0 on success, otherwise a negative error value.
93 * @retval #MAPS_ERROR_NONE Successful
94 * @retval #MAPS_ERROR_INVALID_PARAMETER Invalid parameter
96 int maps_set_string(const char *src, const int max_length, char **dst);
99 * @brief Copies one string to another.
100 * @details This function copies one string to another.
101 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 2.3.2 @endif
103 * @param[out] dst The destination string pointer.
104 * @param[in] src The original string pointer.
105 * @param[in] max_length The maximum size of bytes to be copied.
106 * @return 0 on success, otherwise a negative error value.
107 * @retval #MAPS_ERROR_NONE Successful
108 * @retval #MAPS_ERROR_INVALID_PARAMETER Invalid parameter
110 int maps_get_string(const char *src, const int max_length, char **dst);
113 * @brief Get the screen dpi of current device.
114 * @details This function gets the screen dpi of current device.
116 * @param[out] dpi The screen dpi of current device.
117 * @return 0 on success, otherwise a negative error value
118 * @retval #MAPS_ERROR_NONE Successful
119 * @retval #MAPS_ERROR_INVALID_PARAMETER Invalid parameter
121 int maps_get_screen_dpi(int *dpi);
124 /* Prevent utility highlights defects in std::vector and std::string, so
125 * simplified versions of that classes are implemented */
126 template <class T> class vector {
129 unsigned int current_size;
131 vector() : parray(NULL), current_size(0)
133 parray = g_array_new(false, false, sizeof(T *));
137 /*if (!parray || (current_size == 0))*/
140 for (unsigned int i = 0; i < current_size; i++) {
141 T *item = g_array_index(parray, T *, i);
145 g_array_free(parray, TRUE);
150 void push_back(const T &value)
152 T *clone = new T(value);
154 g_array_append_val(parray, clone);
158 T &operator[](size_t idx) const
160 T *item = g_array_index(parray, T *, idx);
163 unsigned int size() const
178 string() : pstring(NULL)
181 string(const char *pstr) : pstring(NULL)
183 pstring = g_strdup(pstr);
185 string(const string &s) : pstring(NULL)
187 pstring = g_strdup(s.pstring);
195 string &operator=(const string &s)
199 pstring = g_strdup(s.pstring);
203 bool operator==(const string &s) const
205 return g_strcmp0(pstring, s.pstring) == 0;
207 bool operator!=(const string &s) const
209 return !(*this == s);
218 return !pstring || (*this == string(""));
223 TIZEN_PROFILE_UNKNOWN = 0,
224 TIZEN_PROFILE_MOBILE = 0x1,
225 TIZEN_PROFILE_WEARABLE = 0x2,
226 TIZEN_PROFILE_TV = 0x4,
227 TIZEN_PROFILE_IVI = 0x8,
228 TIZEN_PROFILE_COMMON = 0x10,
230 extern tizen_profile_t _get_tizen_profile();
231 #endif /* __MAPS_UTIL_H__ */