Merge branch 'tizen' into tizen_3.0 Revert [Hide quickpanel...]
[apps/native/volume-app.git] / src / earphone.c
1 /*
2  * Copyright (c) 2009-2015 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 <vconf.h>
18 #include <vconf-keys.h>
19
20 #include "main.h"
21 #include "_util_log.h"
22
23 int earphone_is_connected;
24
25 static void _volume_earphone_changed_cb(keynode_t *node, void *data)
26 {
27         int status = 0;
28         int ret;
29
30         ret = vconf_get_int(VCONFKEY_SYSMAN_EARJACK, &status);
31         if (ret < 0) {
32                 return;
33         }
34
35         switch (status) {
36                 case VCONFKEY_SYSMAN_EARJACK_3WIRE:
37                 case VCONFKEY_SYSMAN_EARJACK_4WIRE:
38                 case VCONFKEY_SYSMAN_EARJACK_TVOUT:
39                         _D("Earphone is connected");
40                         earphone_is_connected = 1;
41                         break;
42                 default:
43                         _D("Earphone is disconnected");
44                         earphone_is_connected = 0;
45                         break;
46         }
47 }
48
49 static int register_earphone_module(void *data)
50 {
51         int ret;
52
53         ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_EARJACK, _volume_earphone_changed_cb, NULL);
54         if (ret < 0) {
55                 _E("Failed to set earphone changed callback");
56                 return VOLUME_ERROR_FAIL;
57         }
58
59         _volume_earphone_changed_cb(NULL, NULL);
60
61         return VOLUME_ERROR_OK;
62 }
63
64 static int deregister_earphone_module(void *data)
65 {
66         int ret;
67
68         ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_EARJACK, _volume_earphone_changed_cb);
69         if (ret < 0) {
70                 _E("Failed to set earphone changed callback");
71                 return VOLUME_ERROR_FAIL;
72         }
73
74         return VOLUME_ERROR_OK;
75 }
76
77 void earphone_init(void)
78 {
79         _D("Initialization Earphone");
80
81         int ret;
82
83         ret = register_earphone_module(NULL);
84         _D("Initializaion result: %d", ret);
85 }
86
87 void earphone_fini(void)
88 {
89         _D("Deinitialization Earphone");
90         int ret;
91
92         ret = deregister_earphone_module(NULL);
93         _D("Deinitialization result: %d", ret);
94 }
95
96 int earphone_get_earphone_is_connected(void)
97 {
98         return earphone_is_connected;
99 }