Fix BT headphone state change monitor
[platform/core/context/device-context-provider.git] / src / device_status / headphone.h
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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 #ifndef _DEVICE_STATUS_HEADPHONE_H_
18 #define _DEVICE_STATUS_HEADPNOHE_H_
19
20 #include <glib.h>
21 #include <runtime_info.h>
22 #include <bluetooth.h>
23 #include "../sub_provider_base.h"
24
25 namespace ctx {
26
27         class device_status_headphone : public sub_provider_base {
28                 public:
29                         device_status_headphone();
30                         ~device_status_headphone() {}
31
32                         int subscribe(const char* subject, const char* zone);
33                         int unsubscribe(const char* subject, const char* zone);
34                         int read(const char* subject, const char* zone);
35
36                 private:
37                         string_set_t client_zone;
38
39                         bool connected;
40                         int audio_jack_state;
41                         bool bt_audio_state;
42                         bool bt_audio_callback_on;
43                         bool bt_event_handler_added;
44                         int bt_event_handling_count;
45
46                         bool get_current_status();
47                         void set_bt_audio_callback();
48                         void unset_bt_audio_callback();
49                         void set_bt_audio_state(bool state);
50
51                         void generate_data_packet(json &data);
52                         bool handle_event();
53                         void handle_audio_jack_event();
54
55                         static gboolean handle_bt_event(gpointer data);
56                         static void on_audio_jack_state_changed(runtime_info_key_e runtime_key, void* user_data);
57                         static void on_bt_connection_changed(bool connected, bt_device_connection_info_s *conn_info, void *user_data);
58                         static bool on_bt_bond(bt_device_info_s *device_info, void* user_data);
59         };
60 }
61
62 #endif // _DEVICE_STATUS_HEADPHONE_H_