Fix uncheck return of vconf_get_bool
[platform/core/messaging/msg-service.git] / utils / MsgCallStatusManager.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
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 #include "MsgCallStatusManager.h"
18 #include "MsgDebug.h"
19 #include "MsgInternalTypes.h"
20 #include "MsgGconfWrapper.h"
21
22 GDBusConnection *call_status_gdbus_conn = NULL;
23 GDBusProxy *call_status_gdbus_proxy = NULL;
24 gint call_status_subs_id = 0;
25 gint call_status = 0;
26
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)
30 {
31         MSG_DEBUG("signal_name = [%s]", signal_name);
32
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
39                 }
40                 else {
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])
43                 }
44         }
45 }
46
47 void MsgInitCallStatusManager()
48 {
49         MSG_BEGIN();
50
51         GError *error = NULL;
52
53         if (call_status_gdbus_conn) {
54                 g_object_unref(call_status_gdbus_conn);
55                 call_status_gdbus_conn = NULL;
56         }
57
58         call_status_gdbus_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
59         if (error) {
60                 MSG_FATAL("g_bus_get_sync() failed : %s", error->message);
61                 g_error_free(error);
62                 error = NULL;
63                 goto _DBUS_ERROR;
64         }
65
66         if (call_status_gdbus_proxy) {
67                 g_object_unref(call_status_gdbus_proxy);
68                 call_status_gdbus_proxy = NULL;
69         }
70
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);
73         if (error) {
74                 MSG_FATAL("G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES() failed : %s", error->message);
75                 g_error_free(error);
76                 error = NULL;
77                 goto _DBUS_ERROR;
78         }
79
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);
84         MSG_END();
85         return;
86
87 _DBUS_ERROR:
88         if (call_status_gdbus_conn) {
89                 g_object_unref(call_status_gdbus_conn);
90                 call_status_gdbus_conn = NULL;
91         }
92
93         if (call_status_gdbus_proxy) {
94                 g_object_unref(call_status_gdbus_proxy);
95                 call_status_gdbus_proxy = NULL;
96         }
97
98         MSG_END();
99         return;
100 }
101
102 void MsgDeInitCallStatusManager()
103 {
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;
107         }
108
109         if (call_status_gdbus_conn) {
110                 g_object_unref(call_status_gdbus_conn);
111                 call_status_gdbus_conn = NULL;
112         }
113
114         if (call_status_gdbus_proxy) {
115                 g_object_unref(call_status_gdbus_proxy);
116                 call_status_gdbus_proxy = NULL;
117         }
118 }
119
120 int MsgGetCallStatus()
121 {
122         /* call_status is defined in <call-manager.h> in callmgr_client package.
123          * typedef enum {
124          *  CM_CALL_STATUS_IDLE,
125          *  CM_CALL_STATUS_RINGING,
126          *  CM_CALL_STATUS_OFFHOOK,
127          *  CM_CALL_STATUS_MAX
128          * } cm_call_status_e;
129          */
130         return (int)call_status;
131 }