c18bf1c8037535c5b9b0463d5237626ef92f3b17
[apps/home/call.git] / call-engine / core / include / vc-core-util.h
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
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
18 #ifndef __VC_CORE_UTIL_H_
19 #define __VC_CORE_UTIL_H_
20
21 #include <stdlib.h>
22 #include <glib.h>
23 #include <glib-object.h>
24 #include <stdbool.h>
25 #include <assert.h>
26 #include <stdio.h>
27 #include <string.h>
28 #include "vc-core-error.h"
29 #include "vc-core-engine-types.h"
30
31 #include "TelDefines.h"
32 #include "TelNetwork.h"
33 #include "TelSim.h"
34 #include "TapiCommon.h"
35 #include "TapiEvent.h"
36 #include "ITapiCall.h"
37 #include "ITapiSim.h"
38 #include "ITapiNetwork.h"
39 #include "ITapiSound.h"
40 #include "ITapiSs.h"
41 #include "ITapiSat.h"
42
43 #include "vconf.h"
44 #include "vconf-keys.h"
45 #include "contacts-svc.h"
46 #ifdef CALL_DEBUG_ON_DLOG
47 #include <dlog.h>
48 #endif
49
50 #define CALL_NETWORK_MCC_UK     0xEA    /*234*/
51 #define CALL_NETWORK_MCC_IE     0x110   /*272*/
52 #define CALL_NETWORK_MCC_UKRAINE        0xFF    /*255*/
53 #define CALL_NETWORK_MCC_SAMSUNG_SUWON_3G       450001  /*450001*/
54 #define CALL_NETWORK_MCC_ITALY  222
55
56 #define IS_DIGIT(value)         ((value) >= '0' && (value) <= '9')
57
58 #ifdef CALL_DEBUG_ON_DLOG
59 #define ENG_ERR                 LOG_ERROR
60 #define ENG_WARN                LOG_WARN
61 #define ENG_DEBUG               LOG_DEBUG
62 #else
63 #define ENG_ERR
64 #define ENG_WARN
65 #define ENG_DEBUG
66 #endif
67
68 #ifdef CALL_DEBUG_ON_DLOG
69 #define CALL_ENG_DEBUG(level, frmt, args...)       \
70         do {LOG(level, TAG_CALL, "[VC_ENGINE] [%s:%d] "frmt"\n",  __func__, __LINE__, ##args); } while (0)
71 #define CALL_ENG_KPI(frmt, args...)       \
72         do {LOG(LOG_DEBUG, TAG_CALL_LAUNCH, "[VC_KPI] [%s:%d] "frmt"\n",  __func__, __LINE__, ##args); } while (0)
73 #else
74 #define CALL_ENG_DEBUG(level, fmt, args...)
75 #endif
76
77 #define VOICECALL_RETURN_IF_FAIL(check_condition)       \
78                         if (!(check_condition)) return;
79
80 #define VOICECALL_RETURN_FALSE_IF_FAIL(check_condition) \
81                         if (!(check_condition)) return FALSE;
82
83 #define VOICECALL_RETURN_VALUE_IF_FAIL(check_condition, value)  \
84                         if (!(check_condition)) return value;
85
86 #define VOICECALL_RETURN_NULL_IF_FAIL(check_condition)  \
87                         if (!(check_condition)) return NULL;
88
89 #define VOICECALL_RETURN_ZERO_IF_FAIL(check_condition)  \
90                         if (!(check_condition)) return 0;
91
92 #define VOICECALL_RETURN_INVALID_IF_FAIL(check_condition)       \
93                         if (!(check_condition)) return -1;
94
95 #define VOICECALL_RETURN_VALUE_IF_NOT_IN_RANGE(value, min_value, max_value, ret_val)    \
96                         if ((value < min_value) || (value > max_value)) return ret_val;
97
98 #ifndef min
99 #define min(a, b)    (((a) < (b)) ? (a) : (b))
100 #endif                          /*#ifndef min*/
101
102 typedef unsigned int call_vc_handle;
103
104 #ifdef TIMER_ENABLED
105 #define GET_CURR_TIME() _vc_core_util_get_curr_time()
106 #define PRINT_DIFF_TIME(start, end, message)    _vc_core_util_print_diff_time(start, end, message)
107 #define PRINT_CURRENT_TIME(message) _vc_core_util_print_curr_time(message)
108
109 #else
110 #define GET_CURR_TIME() 0
111 #define         PRINT_DIFF_TIME(start, end, message)
112 #define PRINT_CURRENT_TIME(message)
113 #endif
114
115 /**
116  * This enumeration defines SS's SI vaild types
117  */
118 typedef enum {
119         SS_SI_FORMAT_INVALID = -1,                              /**< SI format is invalid */
120         SS_SI_FORMAT_VALID                                              /**< SI format is valid */
121 } call_vc_ss_si_format;
122
123 /**
124  * This enumeration defines the publish types
125  */
126 typedef enum {
127         CALL_VC_SAT_RESPONSE                                            /**< SAT response publish type */
128 } call_vc_publish_type_t;
129
130 /**
131  * This enum defines the type of power mode.
132  */
133 typedef enum {
134         CALL_VC_POWER_NONE = 0,
135         CALL_VC_POWER_GRANT_DIMMING,
136         CALL_VC_POWER_GRANT_LCDOFF,
137         CALL_VC_POWER_GRANT_SLEEP,
138         CALL_VC_POWER_PROHIBIT_DIMMING,
139         CALL_VC_POWER_PROHIBIT_LCDOFF,
140         CALL_VC_POWER_PROHIBIT_SLEEP,
141         CALL_VC_POWER_NORMAL_STATUS
142 } call_vc_power_mode_t;
143
144 /**
145  * This function publishes the event of a given publish type
146  *
147  * @return              Returns TRUE on success and FALSE on failure
148  * @param[in]           src             Telehone number from which call number needd to be parsed
149  * @param[out]          dst             Pointer to the buffer to store the parsed number
150  */
151 gboolean _vc_core_util_remove_invalid_chars(const char *src, char *dst);
152
153 /**
154  * This function publishes the event of a given publish type
155  *
156  * @return              Returns TRUE on success and FALSE on failure
157  * @param[in]           pszTelNumber            Telehone number from which call number nned to be extracted
158  * @param[out]  pBuffer                 Pointer to the buffer to store the extracted number
159  * @param[in]           nBufSize                        Size of input buffer
160  */
161 gboolean _vc_core_util_extract_call_number(const char *pszTelNumber, char *pBuffer, const int nBufSize);
162 gboolean _vc_core_util_extract_call_number_without_cli(const char *pszTelNumber, char *pBuffer, const int nBufSize);
163
164 #ifdef TIMER_CHECK      /*unused*/
165 void call_vc_print_elapsed_time(char *string, gulong * tim_out);
166 void call_vc_print_diff_time(time_t time1, time_t time2);
167 #endif
168
169 /**
170  * This function checks whether the given number is emergency number by verifying with sim emergency numbers
171  *
172  * @return              TRUE if the number is emergency number, FALSE otherwise
173  * @param[in]           card_type       simcard type
174  * @param[in]           pNumber         number to be verified
175  */
176 gboolean _vc_core_util_check_emergency_number(TelSimCardType_t card_type, char *pNumber, gboolean b_is_no_sim, int *ecc_category);
177
178 /**
179  * This function checks whether the given number is SS string or not
180  *
181  * @return              TRUE if the number is SS string, FALSE otherwise
182  * @param[in]           pNumber         number to be verified
183  */
184 gboolean _vc_core_util_check_ss_string(const char *pNumber);
185
186 /**
187  * This function checks whether the given number is SS string or not
188  *
189  * @return              TRUE if the number is in call SS string, FALSE otherwise
190  * @param[in]           pNumber         number to be verified
191  */
192 gboolean _vc_core_util_check_incall_ss_string(const char *number);
193
194 /*PDIAL_SEND_DTMF*/
195 /**
196 * This function extracts the dtmf number from the given telephone number
197 *
198 * @param[in]      tel_number            source telephone number
199 * @param[out] dtmf_number               extracted dtmf number
200 * @param[out] dtmf_buf_len              size of dtmf number buffer
201 */
202 gboolean _vc_core_util_extract_dtmf_number(const char *tel_number, char *dtmf_number, const int dtmf_buf_len);
203 /*PDIAL_SEND_DTMF*/
204
205 /**
206  * This function checks whether the given number ia a valid dtmf number or not
207  *
208  * @return              TRUE if the number can be used for sending dtmf , FALSE otherwise
209  * @param[in]           pnumber         number to be verified
210  */
211 gboolean _vc_core_util_isvalid_dtmf_number(char *pnumber);
212
213 /**
214 * This function checks whether the entire dtmf string is valid or not
215 *
216 * @return               TRUE if the number can be used for sending dtmf , FALSE otherwise
217 * @param[in]            pnumber         number to be verified
218 */
219 gboolean _vc_core_util_isvalid_full_dtmf_number(char *pnumber);
220
221 /**
222 * This function checks the validity of the given string for SS string
223 *
224 * @return               Returns SS_SI_FORMAT_INVALID - if the string is invalid ss string, SS_SI_FORMAT_VALID - if valid
225 * @param[in]    pinput_string   string to be verified
226 */
227 call_vc_ss_si_format _vc_core_util_check_si_format(const char *pinput_string);
228
229 /**
230 * This function checks the validity of the given telephone number
231 *
232 * @return               TRUE if the given number is valid telephone number, FALSE otherwise
233 * @param[in]            ptel_number     telephone number to be verified
234 */
235 gboolean _vc_core_util_isvalid_telephone_number(char *ptel_number);
236
237 /**
238 * This function checks the if it is GCF mode or not
239 *
240 * @return               TRUE if it is GCF mode, FALSE otherwise
241 */
242 gboolean _vc_core_util_check_gcf_status(void);
243
244 /**
245 * This function checks the if it is in zuhause area or not
246 *
247 * @return               TRUE if it is in zuhause area, FALSE otherwise
248 */
249 gboolean _vc_core_util_check_zuhause_status(void);
250
251 /**
252 * This function retreive mcc information from the telephony
253 *
254 * @internal
255 * @return               TRUE on success, FALSE - otherwise
256 * @param[out]           mcc     mcc information to be retreived
257 */
258 gboolean _vc_core_util_get_mcc(unsigned long *mcc);
259
260 gboolean _vc_core_util_set_call_status(int call_status);
261 gboolean _vc_core_util_check_video_call_status(void);
262 gboolean _vc_core_util_get_SAP_status();
263 void _vc_core_util_get_cug_info(voicecall_setup_info_t *psetupcall_info);
264 void _vc_core_util_get_identity_mode(voicecall_setup_info_t *psetupcall_info);
265 gboolean _vc_core_util_is_offline_mode(void);
266 gboolean _vc_core_util_is_pwlock(void);
267 gboolean _vc_core_util_get_nw_status(int *network_status);
268 gboolean _vc_core_util_strcpy(char *pbuffer, int buf_count, const char *pstring);
269
270 /**
271  * This function make the date and time string
272  *
273  * @return              Returns newly copied string on success or NULL on failure
274  * @param[out]  pbuffer         Target Buffer
275  * @param[in]   time    time
276  */
277 char *_vc_core_util_get_date_time(time_t time);
278
279 /**
280  * This function check phone lock status
281  *
282  * @return              Returns whether phone is locked or not.
283  * @param[in]   void
284  */
285 gboolean _vc_core_util_phonelock_status(void);
286
287 gboolean _vc_core_util_set_sleep_status(call_vc_power_mode_t type);
288 gboolean _vc_core_util_get_call_alert_type(int *alert_type);
289
290 #ifdef TIMER_ENABLED    /*unused*/
291 clock_t _vc_core_util_get_curr_time();
292 void _vc_core_util_print_diff_time(clock_t start, clock_t end, char *message);
293 void _vc_core_util_print_curr_time(char *message);
294 #endif
295
296 void _vc_core_util_download_test_call(char *result);
297
298 gboolean _vc_core_util_set_call_volume(int vol_level);
299 int _vc_core_util_get_call_volume(void);
300 #endif                          /* __VC_CORE_UTIL_H_ */