4 * Copyright (c) 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Ja-young Gu <jygu@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
23 * @ingroup TelephonyAPI
24 * @addtogroup COMMON_TAPI COMMON
29 @brief This file serves as a "C" header file defines structures for Utility Services. \n
30 It contains a sample set of constants, enums, structs that would be required by applications.
33 #ifndef _TEL_UTILITY_H_
34 #define _TEL_UTILITY_H_
38 #define INVALID_REQUEST_ID -1 /**< Invalid RequestId Value */
39 #define DBUS_DEFAULT_PATH "/org/tizen/telephony"
43 * Below enumerations are the return codes of TAPI API's
46 TAPI_API_SUCCESS = 0, /**<No Error occurred */
47 TAPI_API_INVALID_INPUT = -1, /**<input values are not correct in TAPI Library */
48 TAPI_API_INVALID_PTR = -2, /**<invalid pointer */
49 TAPI_API_NOT_SUPPORTED = -3, /**<The feature corresponding to requested API is not supported. This may be due to market/network/vendor reasons such as the feature is not available in the network. */
50 TAPI_API_DEPRICATED = -4, /**<This API is deprecated and will be so in future also */
51 TAPI_API_SYSTEM_OUT_OF_MEM = -5, /**<Out of memory */
52 TAPI_API_SYSTEM_RPC_LINK_DOWN = -6, /**<RPC link down */
53 TAPI_API_SERVICE_NOT_READY = -7, /**<Phone was powered on, but yet to receive the power up completed notification */
54 TAPI_API_SERVER_FAILURE = -8, /**<error occurred in Telephony server */
55 TAPI_API_OEM_PLUGIN_FAILURE = -9, /**<Plug-in layer failure */
56 TAPI_API_TRANSPORT_LAYER_FAILURE = -10, /**<Transport layer Failure*/
57 TAPI_API_INVALID_DATA_LEN = -11, /**<Invalid data length */
58 TAPI_API_REQUEST_MAX_IN_PROGRESS = -12, /**<Maximum number of API Request for the same service are already in progress */
59 TAPI_API_OFFLINE_MODE_ERROR = -13, /**<OEM Telephony Provider is in Offline mode. */
60 TAPI_EVENT_CLASS_UNKNOWN = -14, /**<Event class specified is not present in Event Class list. - 20*/
61 TAPI_EVENT_UNKNOWN = -15, /**<Event specified is not present in TAPI Unsolicited Event list. */
62 TAPI_REGISTRATION_OP_FAILED = -16, /**<Callback Registration/De-registration failed */
63 TAPI_API_OPERATION_FAILED = -17, /**<API operation failed*/
64 TAPI_API_INVALID_OPERATION = -18, /**<API Invalid Operation */
66 TAPI_API_SYSTEM_RPC_LINK_NOT_EST = -100, /**< RPC link down */
67 TAPI_API_API_NOT_SUPPORTED = -101, /**<API not supported */
68 TAPI_API_SERVER_LAYER_FAILURE = -102, /**< Server layer failure*/
71 TAPI_API_INVALID_CALL_ID = -200, /**< Invalid call ID*/
72 TAPI_API_CALL_CTXT_OVERFLOW = -201, /**<Call context overflow */
73 TAPI_API_COULD_NOT_GET_CALL_CTXT = -202, /**< Could not get call context*/
74 TAPI_API_CTXT_SEARCH_RET_NON_CALL_CTXT = -203, /**< Context search returned non-call context*/
75 TAPI_API_COULD_NOT_DESTROY_CTXT = -204, /**< could not destroy context*/
76 TAPI_API_INVALID_LINE_ID = -205, /**< invalid line ID*/
77 TAPI_API_INVALID_CALL_HANDLE = -206, /**<Invalid call handle - 35*/
78 TAPI_API_INVALID_CALL_STATE = -207, /**<Invalid call state- Newly added. Need to raise a CR for this */
79 TAPI_API_CALL_PRE_COND_FAILED = -208, /**<Pre condition like MO call can not be established now.*/
80 TAPI_API_CALL_SAME_REQ_PENDING = -209, /**< Can not accept same request multiple times */
83 TAPI_API_MODEM_POWERED_OFF = -300, /**<The Modem is powered off */
84 TAPI_API_MODEM_ALREADY_ON = -301, /**<Modem already on */
85 TAPI_API_MODEM_ALREADY_OFF = -302, /**<Modem already off */
88 TAPI_API_NETTEXT_DEVICE_NOT_READY = -400, /**<Nettext device not ready */
89 TAPI_API_NETTEXT_SCADDR_NOT_SET = -401, /**<Nettext SCA address not set */
90 TAPI_API_NETTEXT_INVALID_DATA_LEN = -402, /**<Nettext Invalid data length */
91 TAPI_NETTEXT_SCADDRESS_NOT_SET = -403, /**<Nettext SCA address not set*/
94 TAPI_API_SIM_CARD_ERROR = -500, /**<SIM error/blocked state */
95 TAPI_API_SIM_NOT_FOUND = -501, /**<SIM is not present / removed */
96 TAPI_API_SIM_NOT_INITIALIZED = -502, /**<SIM has not initialized yet (waiting for PIN verification, etc) */
97 TAPI_API_SIM_LOCKED = -503,
100 TAPI_API_SAT_INVALID_COMMAND_ID = -600, /**<Command Number Invalid */
101 TAPI_API_SAT_COMMAND_TYPE_MISMATCH = -601, /**< Command Type Mismatch */
102 TAPI_API_SAT_EVENT_NOT_REQUIRED_BY_USIM = -602, /**< Event Not Requested by USIM*/
105 TAPI_API_NETWORK_INVALID_CTXT = -700, /**< Network invalid context*/
108 TAPI_API_MISC_RETURN_NULL = -800, /**< MISC return NULL*/
109 TAPI_API_MISC_VALIDITY_ERROR = -801, /**< MISC validity error*/
110 TAPI_API_MISC_INPUTPARM_ERROR = -802, /**< MISC input parameter error*/
111 TAPI_API_MISC_OUTPARAM_NULL = -803, /**< MISC output parameter null*/
115 * This will check the 'scalar_exp' for TRUE, if failed then return 'err_value' from function.
117 #define TAPI_RET_ERR_NUM_IF_FAIL(scalar_exp, err_num) {\
120 err("TAPI_RET_ERR_NUM_IF_FAIL Failed. returning [%d]", err_num);\
126 * Returns from the current function if the expression is not true. If the expression evaluates to FALSE,
127 * a critical message is logged and the function returns. This can only be used in functions which do not
130 * expr : the expression to check.
132 #define TAPI_RETURN_IF_FAIL(scalar_exp) {\
135 err("TAPI_RETURN_IF_FAIL: Failed: Returning from here."); \
141 * Returns from the current function, returning the value ret, if the expression is not true.
142 * If the expression evaluates to FALSE, a critical message is logged and ret is returned.
144 #define TAPI_RETURN_VAL_IF_FAIL(scalar_exp, ret) { \
147 err("TAPI_RETURN_VAL_IF_FAIL: Failed: Returning [%d]", ret); \
153 * Returns from the current function, returning the value ret, if the expression is not true.
154 * If the expression evaluates to FALSE, a critical message is logged and ret is returned.
156 #define TAPI_RETURN_VAL_IF_SUCCESS(scalar_exp, ret) { \
159 err("TAPI_RETURN_VAL_IF_SUCCESS: Failed Returning [%d]", ret); \
165 * This assert will log an err on stderr and abort, if assertion failed,
166 * Use this only if the telephpny sevrer needs to be exited, if asertion fails
168 #define TAPI_ASSERT(scalar_exp) assert(scalar_exp);
171 * Returns from the current function, returning the value ret, if the exp1 and exp2 are of same value.
172 * If the equal expression evaluates to TRUE, a critical message is logged and ret is returned.
174 #define TAPI_RETURN_VAL_IF_EQUAL(exp1, exp2, ret) { \
177 err("TAPI_RETURN_VAL_IF_EQUAL: FAILED, Returning [%d]", ret); \
183 * void *calloc(size_t nelements, size_t bytes);
184 * which allocates a region of memory large enough to hold nelements of size bytes each.
185 * The allocated region is initialized to zero.
187 #define TAPI_CALLOC(ptr, no_elements, type) \
188 ptr = (type *) calloc (no_elements , sizeof (type)); \
190 perror("NULL is returned"); \
191 err("calloc error -NULL, errno is [%d]", errno); \
192 fprintf(stderr,"Calloc ERRNO %d\n", errno); \
197 * why ptr = NULL; after free()?.
198 * If the same pointer is passed to free twice, known as a double free. To avoid this, set pointers to
199 * NULL after passing them to free: free(NULL) is safe (it does nothing).
201 #define TAPI_FREE(ptr) \
207 err("Double Free or NULL"); \
211 * check for available destination buffer size before copying source buffer data to destination buffer.
212 * Assert if destination buffer size less than source buffer size.
214 #define TAPI_MEMCPY(dest, src, dest_len, src_len) \
215 if (dest_len >= src_len) { \
216 memcpy(dest, src, src_len); \
219 err("TAPI_MEMCPY FAILURE - dest_len(%d) < src_len(%d)", dest_len, src_len); \
224 * Encode a sequence of binary data into its Base-64 stringified representation.
226 * data : the binary data to encode.
227 * len : the length of data.
228 * Returns : a newly allocated, zero-terminated Base-64 encoded string representing data.
229 * gchar *g_base64_encode (const guchar *data, gsize len);
231 #define TAPI_BASE64_ENCODE(data, len, encoded_data) \
232 encoded_data = g_base64_encode((const guchar *)data, (gsize) len);
235 * Decode a sequence of Base-64 encoded text into binary data
237 * text : zero-terminated string with base64 text to decode.
238 * out_len : The length of the decoded data is written here.
239 * Returns : a newly allocated buffer containing the binary data that text represents
240 * guchar *g_base64_decode (const gchar *text, gsize *out_len);
242 #define TAPI_BASE64_DECODE(text, decoded_data, ptr_out_len) \
243 decoded_data = g_base64_decode((const gchar *)text, (gsize *)ptr_out_len);
246 * Define Macro for calculate the length of SCA in BCD type.
248 #define TAPI_GET_LENGTH_FROM_BCD(nLength, rtn) { \
249 if (nLength <= 0) { \
252 else if ((nLength) % 2) { \
253 rtn = ((nLength) / 2) + 1; \
256 rtn = (nLength) / 2; \
261 #define TAPI_VALIDATE_EVENTTYPE(val_min ,val_max, type, ret) { \
262 if (type < val_min || type > val_max ) { \
269 #endif //_TEL_UTILITY_H_