blob: b7c3d7ab6b5f172522dacb918ef925f8993eaa6b [file] [log] [blame]
l.yang8e8d5282023-06-15 10:48:26 +08001#include <stdio.h>
2#include <stdlib.h>
3#include <stdint.h>
4#include <string.h>
5#include <errno.h>
6#include <unistd.h>
7#include <liblog/lynq_deflog.h>
8#include <sys/types.h>
9#include <pthread.h>
10#include <libcall/lynq_call.h>
11
12#include "lynq-qser-voice.h"
13
14#define USER_LOG_TAG "LYNQ_QSER_CALL"
15
16#define RESULT_OK (0)
17#define RESULT_ERROR (-1)
18
19static pthread_t s_lynq_voice_tid = -1;
20static QSER_VoiceCall_StateHandlerFunc_t s_voice_cb = NULL;
21static int s_voice_thread_status = 0;
22
23 typedef enum {
24 LYNQ_CALL_ACTIVE = 0,
25 LYNQ_CALL_HOLDING = 1,
26 LYNQ_CALL_DIALING = 2, /* MO call only */
27 LYNQ_CALL_ALERTING = 3, /* MO call only */
28 LYNQ_CALL_INCOMING = 4, /* MT call only */
29 LYNQ_CALL_WAITING = 5, /* MT call only */
30 /*warren add for T800 platform 2022/04/26 start*/
31 LYNQ_CALL_END = 6, /*CALL END*/
32 /*warren add for T800 platform 2022/04/26 end*/
33}lynq_call_state_t;
34
35
36void *voice_thread_recv(void *context)
37{
38 int handle = 0;
39 int call_state;
40 int toa;
41 int direction;
42 char addr[64];
43 E_QSER_VOICE_CALL_STATE_T voice_state;
44 while (s_voice_thread_status)
45 {
46 lynq_wait_call_state_change(&handle);
47 lynq_get_current_call_state(&handle,&call_state,&toa,&direction,addr);
48 if (call_state == LYNQ_CALL_ACTIVE)
49 {
50 voice_state = E_QSER_VOICE_CALL_STATE_ACTIVE;
51 }
52 else if(call_state == LYNQ_CALL_HOLDING)
53 {
54 voice_state = E_QSER_VOICE_CALL_STATE_HOLDING;
55 }
56 else if(call_state == LYNQ_CALL_DIALING)
57 {
58 voice_state = E_QSER_VOICE_CALL_STATE_DIALING;
59 }
60 else if(call_state == LYNQ_CALL_ALERTING)
61 {
62 voice_state = E_QSER_VOICE_CALL_STATE_ALERTING;
63 }
64 else if(call_state == LYNQ_CALL_INCOMING)
65 {
66 voice_state = E_QSER_VOICE_CALL_STATE_INCOMING;
67 }
68 else if(call_state == LYNQ_CALL_WAITING)
69 {
70 voice_state = E_QSER_VOICE_CALL_STATE_WAITING;
71 }
72 else if(call_state == LYNQ_CALL_END)
73 {
74 voice_state = E_QSER_VOICE_CALL_STATE_END;
75 }
76 else
77 {
78 LYERRLOG("unknow call state");
79 continue;
80 }
81 if (s_voice_cb != NULL)
82 {
83 s_voice_cb(handle,addr,voice_state,context);
84 }
85 }
86 return NULL;
87}
88
89int qser_voice_call_client_init(voice_client_handle_type *ph_voice)
90{
91 if(NULL == ph_voice)
92 {
93 LYERRLOG("input error");
94 return RESULT_ERROR;
95 }
96 *ph_voice = (voice_client_handle_type)getpid();
97 return lynq_init_call(*ph_voice);
98}
99
100int qser_voice_call_client_deinit(voice_client_handle_type h_voice)
101{
l.yang6f131362023-07-25 09:45:37 +0800102 if (0 == h_voice)
l.yang8e8d5282023-06-15 10:48:26 +0800103 {
104 LYERRLOG("init first");
105 return RESULT_ERROR;
106 }
107 return lynq_deinit_call();
108}
109
110int qser_voice_call_addstatehandler(voice_client_handle_type h_voice,
111 QSER_VoiceCall_StateHandlerFunc_t handlerPtr,
112 void* contextPtr)
113{
114 if(h_voice == 0 || handlerPtr== NULL)
115 {
116 LYERRLOG("input error");
117 return RESULT_ERROR;
118 }
119 if (s_voice_cb != NULL)
120 {
121 LYERRLOG("The existing state handle does not need to be added");
122 return RESULT_ERROR;
123 }
124 s_voice_cb = handlerPtr;
125 s_voice_thread_status = 1;
126 int rt = pthread_create(&s_lynq_voice_tid, NULL, voice_thread_recv, contextPtr);
127 if(rt < 0)
128 {
129 LYDBGLOG("qser_voice_call_addstatehandler pthread_create error!!!\n");
130 s_voice_cb = NULL;
131 s_voice_thread_status = 0;
132 s_lynq_voice_tid = -1;
133 return RESULT_ERROR;
134 }
135 return RESULT_OK;
136}
137
138int qser_voice_call_removestatehandle(voice_client_handle_type h_voice)
139{
140 int ret;
141 if (s_lynq_voice_tid != -1)
142 {
143 ret = pthread_cancel(s_lynq_voice_tid);
144 LYDBGLOG("pthread cancel ret = %d",ret);
145 }
146 if (s_lynq_voice_tid != -1)
147 {
148 ret = pthread_join(s_lynq_voice_tid,NULL);
149 LYDBGLOG("pthread cancel ret = %d",ret);
150 s_lynq_voice_tid = -1;
151 }
152 s_voice_thread_status = 0;
l.yang6f131362023-07-25 09:45:37 +0800153 s_voice_cb = NULL;
l.yang8e8d5282023-06-15 10:48:26 +0800154 return RESULT_OK;
155}
156
157int qser_voice_call_start(voice_client_handle_type h_voice,
158 E_QSER_VCALL_ID_T simId,
159 char* phone_number,
160 int *call_id)
161{
162 if(h_voice == 0 || NULL == phone_number || NULL == call_id)
163 {
164 LYERRLOG("qser_voice_call_start input error");
165 return RESULT_ERROR;
166 }
167 return lynq_call(call_id,phone_number);
168}
169
170int qser_voice_call_end(voice_client_handle_type h_voice,int call_id)
171{
172 if(h_voice == 0 || call_id <= 0)
173 {
174 LYERRLOG("qser_voice_call_end input error");
175 return RESULT_ERROR;
176 }
177 return lynq_call_hungup(&call_id);
178}
179
180int qser_voice_call_answer(voice_client_handle_type h_voice,int call_id)
181{
182 if(h_voice == 0 || call_id <= 0)
183 {
184 LYERRLOG("qser_voice_call_answer input error");
185 return RESULT_ERROR;
186 }
187 return lynq_call_answer();
188}
189
l.yang6f131362023-07-25 09:45:37 +0800190int qser_voice_call_getwaitingstatus(int h_voice,qser_voice_call_waiting_service_t *pe_service)
l.yang8e8d5282023-06-15 10:48:26 +0800191{
192 LYINFLOG("To be completed");
193 return RESULT_OK;
194}
195
196int qser_voice_call_setwaiting(int h_voice, qser_voice_call_waiting_service_t e_service)
197{
198 LYINFLOG("To be completed");
199 return RESULT_OK;
200}
201
l.yang8e8d5282023-06-15 10:48:26 +0800202
l.yang6f131362023-07-25 09:45:37 +0800203int qser_voice_call_switch_waiting_or_holding_and_active(voice_client_handle_type h_voice)
l.yang8e8d5282023-06-15 10:48:26 +0800204{
205 if (h_voice == 0)
206 {
207 LYERRLOG("init first");
208 return RESULT_ERROR;
209 }
210 return lynq_switch_waiting_or_holding_and_active();
you.chenedc690b2023-09-06 15:02:52 +0800211}
212
213DEFINE_LYNQ_LIB_LOG(LYNQ_QSER_CALL)
214