2 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
4 * Licensed under the Apache License, Version 2.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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "MsgCallStatusManager.h"
19 #include "MsgInternalTypes.h"
20 #include "MsgGconfWrapper.h"
22 GDBusConnection *call_status_gdbus_conn = NULL;
23 GDBusProxy *call_status_gdbus_proxy = NULL;
24 gint call_status_subs_id = 0;
27 static void call_status_change_received(GDBusConnection *connection, const gchar *sender_name,
28 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
29 GVariant *parameters, gpointer user_data)
31 MSG_DEBUG("signal_name = [%s]", signal_name);
33 if (g_strcmp0(signal_name, CALL_MGR_MEMBER_NAME) == 0) {
34 g_variant_get(parameters, "(iis)", &call_status, NULL, NULL);
35 MSG_INFO("callStatus = [%d]", call_status);
36 if (call_status == 0) {
37 if (MsgSettingSetInt(MSG_MESSAGE_DURING_CALL, 0) != 0)
38 MSG_FATAL("Fail to set value \n"); //call not active
41 if (MsgSettingSetInt(MSG_MESSAGE_DURING_CALL, 1) != 0)
42 MSG_FATAL("Fail to set value \n"); //call active ( call_status: 2 [Ringing], call_status: 1 [In call])
47 void MsgInitCallStatusManager()
53 if (call_status_gdbus_conn) {
54 g_object_unref(call_status_gdbus_conn);
55 call_status_gdbus_conn = NULL;
58 call_status_gdbus_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
60 MSG_FATAL("g_bus_get_sync() failed : %s", error->message);
66 if (call_status_gdbus_proxy) {
67 g_object_unref(call_status_gdbus_proxy);
68 call_status_gdbus_proxy = NULL;
71 call_status_gdbus_proxy = g_dbus_proxy_new_sync(call_status_gdbus_conn, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
72 NULL, CALL_MGR_BUS_NAME, CALL_MGR_PATH_NAME, CALL_MGR_INTERFACE_NAME, NULL, &error);
74 MSG_FATAL("G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES() failed : %s", error->message);
80 call_status_subs_id = g_dbus_connection_signal_subscribe(call_status_gdbus_conn, NULL,
81 CALL_MGR_INTERFACE_NAME, CALL_MGR_MEMBER_NAME, CALL_MGR_PATH_NAME,
82 NULL, G_DBUS_SIGNAL_FLAGS_NONE,
83 call_status_change_received, NULL, NULL);
88 if (call_status_gdbus_conn) {
89 g_object_unref(call_status_gdbus_conn);
90 call_status_gdbus_conn = NULL;
93 if (call_status_gdbus_proxy) {
94 g_object_unref(call_status_gdbus_proxy);
95 call_status_gdbus_proxy = NULL;
102 void MsgDeInitCallStatusManager()
104 if (call_status_subs_id) {
105 g_dbus_connection_signal_unsubscribe(call_status_gdbus_conn, call_status_subs_id);
106 call_status_subs_id = 0;
109 if (call_status_gdbus_conn) {
110 g_object_unref(call_status_gdbus_conn);
111 call_status_gdbus_conn = NULL;
114 if (call_status_gdbus_proxy) {
115 g_object_unref(call_status_gdbus_proxy);
116 call_status_gdbus_proxy = NULL;
120 int MsgGetCallStatus()
122 /* call_status is defined in <call-manager.h> in callmgr_client package.
124 * CM_CALL_STATUS_IDLE,
125 * CM_CALL_STATUS_RINGING,
126 * CM_CALL_STATUS_OFFHOOK,
128 * } cm_call_status_e;
130 return (int)call_status;