blob: f93a65ea2d4096ebec391857466062de937dab6f [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
36#include <glib.h>
37#include <vendor-ril/telephony/ril.h>
38#include <stdio.h>
39#include <log/log.h>
40
41#undef LOG_TAG
42#define LOG_TAG "DEMO_RESP_TIMEOUT"
43
44static GSource *g_resp_source[2];
45static GMutex mutex;
46static bool tag[2] = {false,false};
47static char* name[2] = {"one_minutes_timesout_0","ont_minutes_timesout_1"};
48
49extern void ARspRequest (int request, RIL_SOCKET_ID socket_id);
50
51static gboolean resp_cb(gpointer data) {
52 RLOGD("execute response command: RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM");
53 ARspRequest(RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM, (RIL_SOCKET_ID)(GPOINTER_TO_INT (data)));
54 return G_SOURCE_REMOVE;
55}
56
57static gpointer start_timeout_func(gpointer data) {
58 RLOGD("start_timeout_func");
59 GMainContext *ctx;
60 GMainLoop *loop;
61
62 ctx = g_main_context_new ();
63 loop = g_main_loop_new (ctx, FALSE);
64 int slot = GPOINTER_TO_INT(data);
65 g_resp_source[slot] = g_timeout_source_new (1000*60); //one minutes
66 g_source_set_callback (g_resp_source[slot], resp_cb, data, NULL);
67 g_source_attach (g_resp_source[slot], ctx);
68 g_source_unref (g_resp_source[slot]);
69
70 g_main_loop_run (loop);
71
72 RLOGD("release loop and context");
73 g_main_loop_unref (loop);
74 g_main_context_unref (ctx);
75 return NULL;
76}
77
78void setup_timeout(int slot_id) {
79 RLOGD("setup_timeout");
80 g_mutex_lock(&mutex);
81 gpointer result;
82 GThread *thread;
83 GError *error = NULL;
84
85 thread = g_thread_try_new (name[slot_id], start_timeout_func, GINT_TO_POINTER (slot_id), &error);
86 tag[slot_id] = true;
87 g_mutex_unlock(&mutex);
88 g_thread_unref (thread);
89}
90
91void clear_timeout(int slot_id) {
92 RLOGD("stop timeout configuration");
93 g_mutex_lock(&mutex);
94 if (tag[slot_id])
95 {
96 tag[slot_id] = false;
97 if (!g_source_is_destroyed(g_resp_source[slot_id]))
98 {
99 g_source_destroy(g_resp_source[slot_id]);
100 }
101 }
102 g_mutex_unlock(&mutex);
103}