Make TIZEN 2.0
[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 #ifdef DRM_USED
32 #include "drm-service-types.h"
33 #include "drm-service.h"
34 #endif
35
36 #include <tapi_common.h>
37 #include <TapiUtility.h>
38 #include <ITapiCall.h>
39 #include <ITapiSat.h>
40 #include <ITapiSim.h>
41
42 #include "vconf.h"
43 #include "vconf-keys.h"
44 #include "contacts-svc.h"
45 #ifdef CALL_DEBUG_ON_DLOG
46 #include <dlog.h>
47 #endif
48
49 /* Mcc */
50 #define CALL_NETWORK_MCC_UK                             234             /*UK = 234*/
51 #define CALL_NETWORK_MCC_IRELAND                272             /*Ireland = 272*/
52 #define CALL_NETWORK_MCC_UAE                    424             /*UAE = 424*/
53 #define CALL_NETWORK_MCC_GHANA                  620             /*Ghana = 620*/
54 #define CALL_NETWORK_MCC_ISRAEL                 425             /*Israel = 425*/
55 #define CALL_NETWORK_MCC_CROATIA                219             /*Croatia = 219*/
56 #define CALL_NETWORK_MCC_SERBIA                 220             /*Serbia = 220*/
57 #define CALL_NETWORK_MCC_RUSSIA                 250             /*Russia = 250*/
58
59 #define CALL_NETWORK_MCC_TAIWAN                 466             /*Taiwan = 466*/
60 #define CALL_NETWORK_MCC_HONGKONG               454             /*Hongkong = 454*/
61 #define CALL_NETWORK_MCC_MALAYSIA       502             /*MALAYSIA = 502*/
62 #define CALL_NETWORK_MCC_AUSTRALIA              505             /*Australia = 505*/
63 #define CALL_NETWORK_MCC_NEWZEALAND             530             /*NewZealand = 530*/
64
65 #define CALL_NETWORK_MCC_USA                    310             /*USA = 310*/
66 #define CALL_NETWORK_MCC_CANADA                 302             /*Canada = 302*/
67 #define CALL_NETWORK_MCC_BRASIL                 724             /*Brasil = 724*/
68 #define CALL_NETWORK_MCC_MEXICO                 334             /*Mexico = 334*/
69 #define CALL_NETWORK_MCC_URGUAY                 748             /*Urguay = 748*/
70 #define CALL_NETWORK_MCC_COLOMBIA               732             /*Colombia = 732*/
71 #define CALL_NETWORK_MCC_CHILE                  730             /*Chile = 730*/
72 #define CALL_NETWORK_MCC_PERU                   716             /*Peru = 716*/
73 #define CALL_NETWORK_MCC_VENEZUELA              734             /*Venezuela = 734*/
74 #define CALL_NETWORK_MCC_GUATEMALA              704             /*Guatemala = 704*/
75 #define CALL_NETWORK_MCC_ELSALVADOR             706             /*El Salvador = 706*/
76 #define CALL_NETWORK_MCC_NICARAGUA              710             /*Nicaragua = 710*/
77 #define CALL_NETWORK_MCC_PANAMA                 714             /*Panama = 714*/
78
79 #define CALL_NETWORK_MCC_JAPAN                  440             /*Japan = 440*/
80 #define CALL_NETWORK_MCC_KOREA                  450             /*Korae = 450*/
81 #define CALL_NETWORK_MCC_CHINA                  460             /*China = 460*/
82
83 #define CALL_NETWORK_MCC_FRANCE                 208             /*France = 208*/
84 #define CALL_NETWORK_MCC_PORTUGAL               268             /*Protugal = 268*/
85 #define CALL_NETWORK_MCC_ROMANIA                226             /*Romania = 226*/
86 #define CALL_NETWORK_MCC_DE                             262             /*DE = 262(0x106)*/
87
88 #define CALL_NETWORK_MCC_TEST_USA               0x001   /*Test MMC*/
89
90 /* MNC */
91 #define CALL_NETWORK_MNC_01                     1               /*MNC 01*/
92 #define CALL_NETWORK_MNC_02                     2               /*MNC 02*/
93 #define CALL_NETWORK_MNC_03                     3               /*MNC 03*/
94 #define CALL_NETWORK_MNC_04                     4               /*MNC 04*/
95 #define CALL_NETWORK_MNC_05                     5               /*MNC 05*/
96 #define CALL_NETWORK_MNC_06                     6               /*MNC 06*/
97 #define CALL_NETWORK_MNC_11                     11              /*MNC 11        for +Movil in Panama*/
98 #define CALL_NETWORK_MNC_20                     20              /*MNC 20        for TELCEL in Mexico*/
99 #define CALL_NETWORK_MNC_123            123             /*MNC 123       for Movistar in Colombia*/
100 #define CALL_NETWORK_MNC_103            103             /*MNC 103       for TIGO in Colombia*/
101 #define CALL_NETWORK_MNC_111            111             /*MNC 111       for TIGO in Colombia*/
102 #define CALL_NETWORK_MNC_30                     30              /*MNC 30        for Movistar in Nicaragua*/
103 #define CALL_NETWORK_MNC_300            300             /*MNC 30        for Movistar in Nicaragua*/
104 #define CALL_NETWORK_MNC_TEST_USA       0x01    /*Test MNC*/
105
106 #define IS_DIGIT(value)         ((value) >= '0' && (value) <= '9')
107
108 #ifdef CALL_DEBUG_ON_DLOG
109 #define ENG_ERR                 LOG_ERROR
110 #define ENG_WARN                LOG_WARN
111 #define ENG_DEBUG               LOG_DEBUG
112 #else
113 #define ENG_ERR
114 #define ENG_WARN
115 #define ENG_DEBUG
116 #endif
117
118 #ifdef CALL_DEBUG_ON_DLOG
119 #define CALL_ENG_DEBUG(level, frmt, args...)       \
120         do {LOG(level, TAG_CALL, "[VC_ENGINE] [%s:%d] "frmt"\n",  __func__, __LINE__, ##args); } while (0)
121 #define CALL_ENG_KPI(frmt, args...)       \
122         do {LOG(LOG_DEBUG, TAG_CALL_LAUNCH, "[VC_KPI] [%s:%d] "frmt"\n",  __func__, __LINE__, ##args); } while (0)
123 #else
124 #define CALL_ENG_DEBUG(level, fmt, args...)
125 #endif
126
127 #define VOICECALL_RETURN_IF_FAIL(check_condition)       \
128                         if (!(check_condition)) return;
129
130 #define VOICECALL_RETURN_FALSE_IF_FAIL(check_condition) \
131                         if (!(check_condition)) return FALSE;
132
133 #define VOICECALL_RETURN_VALUE_IF_FAIL(check_condition, value)  \
134                         if (!(check_condition)) return value;
135
136 #define VOICECALL_RETURN_NULL_IF_FAIL(check_condition)  \
137                         if (!(check_condition)) return NULL;
138
139 #define VOICECALL_RETURN_ZERO_IF_FAIL(check_condition)  \
140                         if (!(check_condition)) return 0;
141
142 #define VOICECALL_RETURN_INVALID_IF_FAIL(check_condition)       \
143                         if (!(check_condition)) return -1;
144
145 #define VOICECALL_RETURN_VALUE_IF_NOT_IN_RANGE(value, min_value, max_value, ret_val)    \
146                         if ((value < min_value) || (value > max_value)) return ret_val;
147
148 #ifndef min
149 #define min(a, b)    (((a) < (b)) ? (a) : (b))
150 #endif                          /*#ifndef min*/
151
152 typedef unsigned int call_vc_handle;
153
154 /**
155  * This enumeration defines SS's SI vaild types
156  */
157 typedef enum {
158         SS_SI_FORMAT_INVALID = -1,                              /**< SI format is invalid */
159         SS_SI_FORMAT_VALID                                              /**< SI format is valid */
160 } call_vc_ss_si_format;
161
162 /**
163  * This enumeration defines the publish types
164  */
165 typedef enum {
166         CALL_VC_SAT_RESPONSE                                            /**< SAT response publish type */
167 } call_vc_publish_type_t;
168
169 /**
170  * This enum defines the type of power mode.
171  */
172 typedef enum {
173         CALL_VC_POWER_NONE = 0,
174         CALL_VC_POWER_GRANT_DIMMING,
175         CALL_VC_POWER_GRANT_LCDOFF,
176         CALL_VC_POWER_GRANT_SLEEP,
177         CALL_VC_POWER_PROHIBIT_DIMMING,
178         CALL_VC_POWER_PROHIBIT_LCDOFF,
179         CALL_VC_POWER_PROHIBIT_SLEEP,
180         CALL_VC_POWER_NORMAL_STATUS
181 } call_vc_power_mode_t;
182
183 /**
184  * This function publishes the event of a given publish type
185  *
186  * @return              Returns TRUE on success and FALSE on failure
187  * @param[in]           src             Telehone number from which call number needd to be parsed
188  * @param[out]          dst             Pointer to the buffer to store the parsed number
189  */
190 gboolean _vc_core_util_remove_invalid_chars(const char *src, char *dst);
191
192 /**
193  * This function publishes the event of a given publish type
194  *
195  * @return              Returns TRUE on success and FALSE on failure
196  * @param[in]           pszTelNumber            Telehone number from which call number nned to be extracted
197  * @param[out]  pBuffer                 Pointer to the buffer to store the extracted number
198  * @param[in]           nBufSize                        Size of input buffer
199  */
200 gboolean _vc_core_util_extract_call_number(const char *pszTelNumber, char *pBuffer, const int nBufSize);
201 gboolean _vc_core_util_extract_call_number_without_cli(const char *pszTelNumber, char *pBuffer, const int nBufSize);
202
203 #ifdef TIMER_CHECK      /*unused*/
204 void call_vc_print_elapsed_time(char *string, gulong * tim_out);
205 void call_vc_print_diff_time(time_t time1, time_t time2);
206 #endif
207
208 /**
209  * This function checks whether the given number is SS string or not
210  *
211  * @return              TRUE if the number is SS string, FALSE otherwise
212  * @param[in]           pNumber         number to be verified
213  */
214 gboolean _vc_core_util_check_ss_string(const char *pNumber);
215
216 /**
217  * This function checks whether the given number is SS string or not
218  *
219  * @return              TRUE if the number is in call SS string, FALSE otherwise
220  * @param[in]           pNumber         number to be verified
221  */
222 gboolean _vc_core_util_check_incall_ss_string(const char *number);
223
224 /**
225 * This function extracts the dtmf number from the given telephone number
226 *
227 * @param[in]      tel_number            source telephone number
228 * @param[out] dtmf_number               extracted dtmf number
229 * @param[out] dtmf_buf_len              size of dtmf number buffer
230 */
231 gboolean _vc_core_util_extract_dtmf_number(const char *tel_number, char *dtmf_number, const int dtmf_buf_len);
232
233 /**
234  * This function checks whether the given number ia a valid dtmf number or not
235  *
236  * @return              TRUE if the number can be used for sending dtmf , FALSE otherwise
237  * @param[in]           pnumber         number to be verified
238  */
239 gboolean _vc_core_util_isvalid_dtmf_number(char *pnumber);
240
241 /**
242 * This function checks whether the entire dtmf string is valid or not
243 *
244 * @return               TRUE if the number can be used for sending dtmf , FALSE otherwise
245 * @param[in]            pnumber         number to be verified
246 */
247 gboolean _vc_core_util_isvalid_full_dtmf_number(char *pnumber);
248
249 /**
250 * This function checks the validity of the given string for SS string
251 *
252 * @return               Returns SS_SI_FORMAT_INVALID - if the string is invalid ss string, SS_SI_FORMAT_VALID - if valid
253 * @param[in]    pinput_string   string to be verified
254 */
255 call_vc_ss_si_format _vc_core_util_check_si_format(const char *pinput_string);
256
257 /**
258 * This function checks the validity of the given telephone number
259 *
260 * @return               TRUE if the given number is valid telephone number, FALSE otherwise
261 * @param[in]            ptel_number     telephone number to be verified
262 */
263 gboolean _vc_core_util_isvalid_telephone_number(char *ptel_number);
264
265 /**
266 * This function checks the if it is GCF mode or not
267 *
268 * @return               TRUE if it is GCF mode, FALSE otherwise
269 */
270 gboolean _vc_core_util_check_gcf_status(void);
271
272 /**
273 * This function checks the if it is in zuhause area or not
274 *
275 * @return               TRUE if it is in zuhause area, FALSE otherwise
276 */
277 gboolean _vc_core_util_check_zuhause_status(void);
278
279 /**
280 * This function retreive mcc information from the telephony
281 *
282 * @internal
283 * @return               TRUE on success, FALSE - otherwise
284 * @param[out]           mcc     mcc information to be retreived
285 */
286 gboolean _vc_core_util_get_mcc(unsigned long *mcc);
287
288 /**
289 * This function retreive mnc information from the telephony
290 *
291 * @internal
292 * @return               TRUE on success, FALSE - otherwise
293 * @param[out]           mnc     mnc information to be retreived
294 */
295 gboolean _vc_core_util_get_mnc(unsigned long *mnc);
296
297
298 gboolean _vc_core_util_set_call_status(int call_status);
299 gboolean _vc_core_util_check_video_call_status(void);
300 gboolean _vc_core_util_get_SAP_status();
301 void _vc_core_util_get_cug_info(voicecall_setup_info_t *psetupcall_info);
302 void _vc_core_util_get_identity_mode(voicecall_setup_info_t *psetupcall_info);
303 gboolean _vc_core_util_is_offline_mode(void);
304 gboolean _vc_core_util_is_pwlock(void);
305 gboolean _vc_core_util_get_nw_status(int *network_status);
306 gboolean _vc_core_util_strcpy(char *pbuffer, int buf_count, const char *pstring);
307
308 /**
309  * This function make the date and time string
310  *
311  * @return              Returns newly copied string on success or NULL on failure
312  * @param[out]  pbuffer         Target Buffer
313  * @param[in]   time    time
314  */
315 char *_vc_core_util_get_date_time(time_t time);
316
317 /**
318  * This function check phone lock status
319  *
320  * @return              Returns whether phone is locked or not.
321  * @param[in]   void
322  */
323 gboolean _vc_core_util_phonelock_status(void);
324
325 void _vc_core_util_download_test_call(char *result);
326
327 gboolean _vc_core_util_set_call_volume(int vol_level);
328 int _vc_core_util_get_call_volume(void);
329 #endif                          /* __VC_CORE_UTIL_H_ */