adjust code to public bluetooth audio API
[apps/core/preloaded/indicator-win.git] / src / modules / processing / call.c
1 /*
2  *  Indicator
3  *
4  * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <vconf.h>
24 //#include <Ecore_X.h>
25 #include <minicontrol-monitor.h>
26 #include <bluetooth.h>
27 //#include <bluetooth_extention.h>
28
29 #include "common.h"
30 #include "indicator.h"
31 #include "main.h"
32 #include "modules.h"
33 #include "icon.h"
34 #include "util.h"
35 #include "log.h"
36
37 #define ICON_PRIORITY   INDICATOR_PRIORITY_MINICTRL3
38 #define MODULE_NAME             "call"
39 #define MINICONTROL_VOICE_NAME  "[voicecall-quickpanel]"
40 #define MINICONTROL_VIDEO_NAME  "[videocall-quickpanel]"
41
42 static int register_call_module(void *data);
43 static int unregister_call_module(void);
44 static void show_call_icon( void *data);
45
46 enum {
47         CALL_UI_STATUS_NONE = 0,
48         CALL_UI_STATUS_INCOM,
49         CALL_UI_STATUS_OUTGOING,
50         CALL_UI_STATUS_ACTIVE,
51         CALL_UI_STATUS_HOLD,
52         CALL_UI_STATUS_END,
53 };
54
55 icon_s call = {
56         .type = INDICATOR_IMG_ICON,
57         .name = MODULE_NAME,
58         .priority = ICON_PRIORITY,
59         .always_top = EINA_TRUE,
60         .exist_in_view = EINA_FALSE,
61         .img_obj = {0,},
62         .obj_exist = EINA_FALSE,
63         .area = INDICATOR_ICON_AREA_MINICTRL,
64         .init = register_call_module,
65         .fini = unregister_call_module,
66         .minictrl_control = NULL //mctrl_monitor_cb
67 };
68
69 static int bt_state = 0;
70
71 static const char *icon_path[] = {
72         "Call/B03_Call_Duringcall.png",
73         "Call/B03_Call_bluetooth.png",
74         NULL
75 };
76
77 static void set_app_state(void* data)
78 {
79         call.ad = data;
80 }
81
82 static void show_image_icon(void *data)
83 {
84         if (bt_state == 1) {
85                 call.img_obj.data = icon_path[1];
86         } else {
87                 call.img_obj.data = icon_path[0];
88         }
89         icon_show(&call);
90 }
91
92 static void hide_image_icon(void)
93 {
94         icon_hide(&call);
95 }
96
97 static void icon_animation_set(enum indicator_icon_ani type)
98 {
99         icon_ani_set(&call, type);
100 }
101
102 static void __bt_ag_sco_state_changed_cb(int result, bool connected, const char *remote_address, bt_audio_profile_type_e type, void *user_data)
103 {
104         int status = 0;
105
106         if (connected) bt_state=1;
107         else bt_state=0;
108
109         vconf_get_int(VCONFKEY_CALL_STATE, &status);
110
111         if (status != VCONFKEY_CALL_OFF) show_call_icon(user_data);
112 }
113
114 static void register_bt_state( void *data)
115 {
116         int error = -1;
117
118         error = bt_initialize();
119         if (error != BT_ERROR_NONE) _E("bt_initialize return [%d]", error);
120
121         error = bt_audio_initialize();
122         if (error != BT_ERROR_NONE) _E("bt_audio_initialize return [%d]", error);
123
124         error = bt_audio_set_connection_state_changed_cb(__bt_ag_sco_state_changed_cb, data);   // callback µî·Ï
125         if (error != BT_ERROR_NONE) _E("bt_ag_set_sco_state_changed_cb return [%d]", error);
126
127 }
128
129 static void unregister_bt_state( void )
130 {
131         int error = -1;
132
133         error = bt_audio_unset_connection_state_changed_cb();
134         if (error != BT_ERROR_NONE) _E("bt_ag_unset_sco_state_changed_cb return [%d]", error);
135
136         error = bt_audio_deinitialize();
137         if (error != BT_ERROR_NONE) _E("bt_audio_deinitialize return [%d]", error);
138
139         error = bt_deinitialize();
140         if (error != BT_ERROR_NONE) _E("bt_audio_deinitialize return [%d]", error);
141 }
142
143 static void show_call_icon( void *data)
144 {
145         int status = 0;
146         int ret = 0;
147
148         ret_if(!data);
149
150         ret = vconf_get_int(VCONFKEY_CALL_STATE, &status);
151         if (ret != OK) {
152                 _E("Failed to get VCONFKEY_CALL_STATE!");
153                 return;
154         }
155
156         switch (status) {
157         case VCONFKEY_CALL_VOICE_CONNECTING:
158         case VCONFKEY_CALL_VIDEO_CONNECTING:
159                 show_image_icon(data);
160                 icon_animation_set(ICON_ANI_BLINK);
161                 break;
162         case VCONFKEY_CALL_VOICE_ACTIVE:
163         case VCONFKEY_CALL_VIDEO_ACTIVE:
164                 show_image_icon(data);
165                 icon_animation_set(ICON_ANI_NONE);
166                 break;
167         case VCONFKEY_CALL_OFF:
168                 hide_image_icon();
169                 break;
170         default:
171                 _E("Invalid value %d", status);
172                 break;
173         }
174 }
175
176 static void indicator_call_change_cb(keynode_t *node, void *data)
177 {
178         int status = 0;
179         int ret = 0;
180         bool bt_opened = 0;
181
182         ret_if(!data);
183
184         ret = vconf_get_int(VCONFKEY_CALL_STATE, &status);
185         if (ret != OK) {
186                 _E("Failed to get VCONFKEY_CALL_STATE!");
187                 return;
188         }
189
190         switch (status) {
191         case VCONFKEY_CALL_VOICE_CONNECTING:
192         case VCONFKEY_CALL_VIDEO_CONNECTING:
193                 show_image_icon(data);
194                 icon_animation_set(ICON_ANI_BLINK);
195                 break;
196         case VCONFKEY_CALL_VOICE_ACTIVE:
197         case VCONFKEY_CALL_VIDEO_ACTIVE:
198                 show_image_icon(data);
199                 icon_animation_set(ICON_ANI_NONE);
200                 break;
201         case VCONFKEY_CALL_OFF:
202                 hide_image_icon();
203                 break;
204         default:
205                 _E("Invalid value %d", status);
206                 break;
207         }
208 }
209
210 static int register_call_module(void *data)
211 {
212         int ret = 0;
213
214         retv_if(!data, 0);
215
216         set_app_state(data);
217
218         ret = vconf_notify_key_changed(VCONFKEY_CALL_STATE, indicator_call_change_cb, data);
219         register_bt_state(data);
220         if (ret != OK) _E("Failed to register VCONFKEY_CALL_STATE callback!");
221
222         return ret;
223 }
224
225 static int unregister_call_module(void)
226 {
227         int ret = 0;
228
229         ret = vconf_ignore_key_changed(VCONFKEY_CALL_STATE, indicator_call_change_cb);
230         unregister_bt_state();
231         if (ret != OK) _E("Failed to register VCONFKEY_CALL_STATE callback!");
232
233         return ret;
234 }
235 /* End of file */