2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __CONTEXT_TYPES_H__
18 #define __CONTEXT_TYPES_H__
20 #include <sys/types.h>
27 #define CTX_DBUS_DEST "org.tizen.context"
28 #define CTX_DBUS_PATH "/org/tizen/context"
29 #define CTX_DBUS_IFACE CTX_DBUS_DEST
30 #define CTX_DBUS_TIMEOUT 3000
31 #define CTX_SIGNAL_NEW_CLIENT "NewClient"
34 #define E_NONE TIZEN_ERROR_NONE /* Successful */
35 #define E_PARAM TIZEN_ERROR_INVALID_PARAMETER /* Invalid function parameter */
36 #define E_INV_OP TIZEN_ERROR_INVALID_OPERATION /* Function not implemented */
37 #define E_NO_MEM TIZEN_ERROR_OUT_OF_MEMORY /* Memory allocation failed */
38 #define E_ACCESS TIZEN_ERROR_PERMISSION_DENIED /* Permission denied */
39 #define E_SUPPORT TIZEN_ERROR_NOT_SUPPORTED /* Feature not supported */
40 #define E_NO_DATA TIZEN_ERROR_NO_DATA /* No data available */
41 #define E_UNKNOWN TIZEN_ERROR_UNKNOWN /* Unknown error */
43 #define E_STARTED (TIZEN_ERROR_CONTEXT | 0x01) /* Feature already activated */
44 #define E_NOT_STARTED (TIZEN_ERROR_CONTEXT | 0x02) /* Feature already deactivated */
45 #define E_RANGE (TIZEN_ERROR_CONTEXT | 0x03) /* Index out of range */
46 #define E_FAILED (TIZEN_ERROR_CONTEXT | 0x04) /* Operation failed with some internal errors */
47 #define E_RULE_ON (TIZEN_ERROR_CONTEXT | 0x05) /* Rule enabled */
48 #define E_RULE_OFF (TIZEN_ERROR_CONTEXT | 0x06) /* Rule not enabled */
49 #define E_INV_RULE (TIZEN_ERROR_CONTEXT | 0x07) /* Invalid rule */
50 #define E_NO_RULE (TIZEN_ERROR_CONTEXT | 0x08) /* Rule not exists */
51 #define E_DATA_EXIST (TIZEN_ERROR_CONTEXT | 0X09) /* Data exists */
52 #define E_INV_DATA (TIZEN_ERROR_CONTEXT | 0X0A) /* Invalid data */
54 /* Logging and Error Handling */
59 #define _SI SECURE_SLOGI
60 #define _SD SECURE_SLOGD
61 #define _SW SECURE_SLOGW
62 #define _SE SECURE_SLOGE
64 #define E_STR_ALLOC RED("Memory allocation failed")
65 #define _E_ALLOC _E(E_STR_ALLOC)
67 /* Color code for dlog */
68 #define RED(X) "\033[0;31m" X "\033[0m"
69 #define GREEN(X) "\033[0;32m" X "\033[0m"
70 #define YELLOW(X) "\033[0;33m" X "\033[0m"
71 #define BLUE(X) "\033[0;34m" X "\033[0m"
72 #define PURPLE(X) "\033[0;35m" X "\033[0m"
73 #define CYAN(X) "\033[0;36m" X "\033[0m"
75 /* Error Handling Macros */
76 #define IF_FAIL_RETURN_TAG(cond, ret, tag, fmt, arg...) \
77 do { if (!(cond)) { tag(fmt, ##arg); return ret; } } while (0)
79 #define IF_FAIL_RETURN(cond, ret) \
80 do { if (!(cond)) { return ret; } } while (0)
82 #define IF_FAIL_VOID_TAG(cond, tag, fmt, arg...) \
83 do { if (!(cond)) { tag(fmt, ##arg); return; } } while (0)
85 #define IF_FAIL_VOID(cond) \
86 do { if (!(cond)) { return; } } while (0)
88 #define IF_FAIL_CATCH_TAG(cond, tag, fmt, arg...) \
89 do { if (!(cond)) { tag(fmt, ##arg); goto CATCH; } } while (0)
91 #define IF_FAIL_CATCH(cond) \
92 do { if (!(cond)) { goto CATCH; } } while (0)
94 #define IF_FAIL_THROW_TAG(cond, excp, tag, fmt, arg...) \
95 do { if (!(cond)) { tag(fmt, ##arg); throw excp; } } while (0)
97 #define IF_FAIL_THROW(cond, excp) \
98 do { if (!(cond)) { throw excp; } } while (0)
100 #define IS_FAILED(X) ((X) < 0)
102 #define IS_SUCCESS(X) ((X) >= 0)
104 #define HANDLE_GERROR(Err) \
105 do { if ((Err)) { _E("GError: %s", Err->message); g_error_free(Err); Err = NULL; } } while (0)
109 #endif /* __CONTEXT_TYPES_H__ */