Manage focus cb thread and focus watch cb thread separately
[platform/core/multimedia/libmm-sound.git] / include / mm_sound_focus_private.h
1 /*
2  * libmm-sound
3  *
4  * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Sangchul Lee <sc11.lee@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #ifndef __MM_SOUND_FOCUS_PRIVATE_H__
23 #define __MM_SOUND_FOCUS_PRIVATE_H__
24
25 #include "mm_sound_common.h"
26 #include "mm_sound_stream.h"
27 #include "mm_sound_focus.h"
28
29 #define FOCUS_HANDLE_MAX 512
30 #define FOCUS_HANDLE_INIT_VAL -1
31
32 typedef struct _FocusSource {
33         GSource source;
34         GPollFD poll_fd;
35 } FocusSource;
36
37 typedef struct {
38         int focus_pid;
39         int handle;
40         int client_fd;
41         int focus_fd;
42         FocusSource *fsrc;
43         bool is_used;
44         bool auto_reacquire;
45         GMutex focus_lock;
46         GThread *focus_cb_thread;
47         GThread *focus_watch_cb_thread;
48         GMainLoop *focus_loop;
49         mm_sound_focus_changed_cb focus_callback;
50         mm_sound_focus_changed_watch_cb watch_callback;
51         void* user_data;
52         bool unset_watch_callback_requested;
53 } focus_sound_info_t;
54
55 typedef struct {
56         int pid;
57         int handle;
58         int type;
59         int state;
60         char stream_type[MAX_STREAM_TYPE_LEN];
61         char ext_info[MM_SOUND_NAME_NUM];
62         int option;
63 } focus_cb_data_lib;
64
65 typedef gboolean(*focus_callback_handler_t)(gpointer user_data);
66 extern focus_sound_info_t g_focus_sound_handle[FOCUS_HANDLE_MAX];
67
68 int focus_find_empty_index(int *handle);
69 int focus_find_index_by_handle(int handle);
70 int focus_watch_find_index_by_handle(int handle);
71
72 int focus_init_context(int index, bool is_for_watching);
73 void focus_deinit_context(int index, bool is_for_watching);
74 void focus_init_callback(int index, bool is_for_watching);
75 void focus_deinit_callback(int index, bool is_for_watching);
76
77 #endif /* __MM_SOUND_FOCUS_PRIVATE_H__ */