blob: e75e26def93d6bd58b707a0c1516f7566b7315ee [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/* Copyright Statement:
2 *
3 * This software/firmware and related documentation ("MediaTek Software") are
4 * protected under relevant copyright laws. The information contained herein
5 * is confidential and proprietary to MediaTek Inc. and/or its licensors.
6 * Without the prior written permission of MediaTek inc. and/or its licensors,
7 * any reproduction, modification, use or disclosure of MediaTek Software,
8 * and information contained herein, in whole or in part, shall be strictly prohibited.
9 */
10/* MediaTek Inc. (C) 2010. All rights reserved.
11 *
12 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
13 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
14 * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
15 * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
18 * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
19 * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
20 * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
21 * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
22 * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
23 * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
24 * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
25 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
26 * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
27 * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
28 * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
29 * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
30 *
31 * The following software/firmware and/or related documentation ("MediaTek Software")
32 * have been modified by MediaTek Inc. All revisions are subject to any receiver's
33 * applicable license agreements with MediaTek Inc.
34 */
35#include <alloca.h>
36#include <stdlib.h>
37#include <stdio.h>
38#include <vendor-ril/telephony/ril.h>
39#include "common.h"
40#undef LOG_TAG
41#define LOG_TAG "DEMO_RspDisp"
42
43//data struct
44typedef struct{
45 int request;
46 RIL_SOCKET_ID socket_id;
47 char* arg;
48}ResponseDisptachData;
49
50struct RspDisp_Event{
51 struct RspDisp_Event* next;
52 struct RspDisp_Event* prev;
53 ResponseDisptachData data;
54};
55//global variable
56static pthread_mutex_t s_listMutex = PTHREAD_MUTEX_INITIALIZER;
57static pthread_cond_t s_listCond = PTHREAD_COND_INITIALIZER;
58//marco define
59#define LIST_LOCK() pthread_mutex_lock(&s_listMutex)
60#define LIST_UNLOCK() pthread_mutex_unlock(&s_listMutex)
61#define WAITLIST() pthread_cond_wait(&s_listCond,&s_listMutex)
62#define WAKEUPLIST() pthread_cond_signal(&s_listCond)
63
64//list variable and function announce
65static struct RspDisp_Event rspDisp_list;
66void initList(struct RspDisp_Event* list);
67void addToList(struct RspDisp_Event* ev, struct RspDisp_Event* list);
68void removeFromList(struct RspDisp_Event* ev);
69
70void intRspList()
71{
72 LIST_LOCK();
73 initList(&rspDisp_list);
74 LIST_UNLOCK();
75}
76
77//function define
78void initList(struct RspDisp_Event* list)
79{
80 memset(list, 0 ,sizeof(struct RspDisp_Event));
81 list->next = list;
82 list->prev = list;
83 RLOGD("Demo Ril_event init list!");
84}
85
86void addToList(struct RspDisp_Event* ev, struct RspDisp_Event* list)
87{ //add to list tail
88 ev->next = list;
89 ev->prev = list->prev;
90 ev->prev->next = ev;
91 list->prev = ev;
92 RLOGD("Demo Ril_event add an event to list!");
93}
94
95void removeFromList(struct RspDisp_Event* ev)
96{
97 ev->next->prev = ev->prev;
98 ev->prev->next = ev->next;
99 ev->next = NULL;
100 ev->prev = NULL;
101 RLOGD("Demo Ril_event remove an event from list!");
102}
103
104void ARspRequestWithArg(int request, const char* arg,RIL_SOCKET_ID socket_id)
105{
106 struct RspDisp_Event* event = (struct RspDisp_Event*)malloc(sizeof(struct RspDisp_Event));
107
108 if(event == NULL)
109 {
110 RLOGE("malloc event memory error!");
111 return;
112 }
113 RLOGD("A Request happened, request is %s!",android::requestToString(request));
114 event->data.request = request;
115 if (arg != NULL) {
116 event->data.arg = strdup(arg);
117 } else {
118 event->data.arg = NULL;
119 }
120
121 event->data.socket_id = socket_id;
122 event->prev = NULL;
123 event->next = NULL;
124 LIST_LOCK();
125 addToList(event,&rspDisp_list);
126 WAKEUPLIST();
127 LIST_UNLOCK();
128 return;
129}
130
131void ARspRequest (int request,RIL_SOCKET_ID socket_id)
132{
133 ARspRequestWithArg(request, NULL,socket_id);
134}
135
136int dispOnSupport(int request)
137{
138 switch (request){
139 case RIL_REQUEST_GET_CURRENT_CALLS: return 1;
140 case RIL_REQUEST_ANSWER: return 1;
141 case RIL_REQUEST_GET_SIM_STATUS: return 1;
142 case RIL_REQUEST_DATA_REGISTRATION_STATE: return 1;
143 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return 1;
144 case RIL_REQUEST_SMS_ACKNOWLEDGE: return 1;
145 case RIL_REQUEST_OEM_HOOK_RAW: return 1;
146 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return 1;
147 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE: return 1;
148 case RIL_REQUEST_RADIO_POWER: return 1;
149 case RIL_REQUEST_ALLOW_DATA: return 1;
150 case RIL_REQUEST_CDMA_FLASH: return 1;
151 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return 1;
152 //case :return 1;
153 default:return 0;
154 }
155}
156//ResponseDispatch function used for :
157// 1. ril request triggered by RIL_onRequestComplete flow
158// 2. ril request triggered by RIL_onUnsolicitedResponse flow
159void responseDispatch()
160{
161 struct RspDisp_Event* event = NULL;
162 RLOGD("start loop!");
163
164 prctl(PR_SET_NAME,(unsigned long)"demo_Rsp_disp");
165
166 //LIST_LOCK();
167 //initList(&rspDisp_list);
168 //LIST_UNLOCK();
169
170 for(;;){
171
172 LIST_LOCK();
173 if(rspDisp_list.next == &rspDisp_list) { //if blank list then wait
174 RLOGD("blank list ,then wait!");
175 while(rspDisp_list.next == &rspDisp_list){
176 WAITLIST();
177 }
178 }
179 event = rspDisp_list.next;
180 removeFromList(event);
181 LIST_UNLOCK();
182
183 // do ril request
184 if(dispOnSupport(event->data.request) != 1) {
185 RLOGD("event not support!");
186 goto event_done;
187 }
188 android::RspDispFunction(event->data.request, event->data.arg, event->data.socket_id);
189
190 event_done:
191 if(event != NULL) {
192 if(event->data.arg != NULL) {
193 free(event->data.arg);
194 event->data.arg = NULL;
195 }
196 free(event);
197 event = NULL;
198 }
199 }
200
201 return;
202}