guint subs_id;
};
+typedef struct _FocusSource {
+ GSource source;
+ GPollFD pollfd;
+} FocusSource;
+
#define GET_CB_DATA(_cb_data, _func, _userdata, _extradata) \
do { \
_cb_data = (struct callback_data*) g_malloc0(sizeof(struct callback_data)); \
}
#endif
-int mm_sound_client_play_tone(int number, int volume_config, double volume, int time, int *handle, bool enable_session)
+int mm_sound_client_play_tone(int number, int volume_config, double volume,
+ int time, int *handle, bool enable_session)
{
int ret = MM_ERROR_NONE;
-// int instance = -1; /* instance is unique to communicate with server : client message queue filter type */
+// int instance = -1; /* instance is unique to communicate with server : client message queue filter type */
int volume_type = MM_SOUND_VOLUME_CONFIG_TYPE(volume_config);
char stream_type[MM_SOUND_STREAM_TYPE_LEN] = {0, };
session_type, session_options, getpid(), enable_session, handle, stream_type, -1);
#ifdef USE_FOCUS
if (enable_session && !g_focus_signal_handle) {
- ret = mm_sound_subscribe_signal(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, &g_focus_signal_handle, _mm_sound_client_focus_signal_callback, NULL);
+ ret = mm_sound_subscribe_signal(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, &g_focus_signal_handle,
+ _mm_sound_client_focus_signal_callback, NULL);
if (ret) {
debug_error("mm_sound_subscribe_signal failed [0x%x]", ret);
return MM_ERROR_POLICY_INTERNAL;
return ret;
}
-int mm_sound_client_play_tone_with_stream_info(int tone, char *stream_type, int stream_id, double volume, int duration, int *handle)
+int mm_sound_client_play_tone_with_stream_info(int tone, char *stream_type, int stream_id,
+ double volume, int duration, int *handle)
{
int ret = MM_ERROR_NONE;
end_cb_data->watching_handle = *handle;
GET_CB_DATA(cb_data, param->callback, param->data, end_cb_data);
- ret = mm_sound_proxy_add_play_sound_end_callback(_mm_sound_stop_callback_wrapper_func, cb_data, play_end_callback_data_free_func, &end_cb_data->subs_id);
+ ret = mm_sound_proxy_add_play_sound_end_callback(_mm_sound_stop_callback_wrapper_func, cb_data,
+ play_end_callback_data_free_func, &end_cb_data->subs_id);
if (ret != MM_ERROR_NONE) {
debug_error("Add callback for play sound(%d) Failed", *handle);
}
}
#ifdef USE_FOCUS
if (!param->skip_session && !g_focus_signal_handle) {
- ret = mm_sound_subscribe_signal(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, &g_focus_signal_handle, _mm_sound_client_focus_signal_callback, NULL);
+ ret = mm_sound_subscribe_signal(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, &g_focus_signal_handle,
+ _mm_sound_client_focus_signal_callback, NULL);
if (ret) {
debug_error("mm_sound_subscribe_signal failed [0x%x]", ret);
return MM_ERROR_POLICY_INTERNAL;
play_sound_end_callback_data_t *end_cb_data;
ret = mm_sound_proxy_play_sound_with_stream_info(param->filename, param->loop, param->volume,
- getpid(), handle, stream_type, stream_id);
+ getpid(), handle, stream_type, stream_id);
if (ret != MM_ERROR_NONE) {
debug_error("Play Sound Failed");
goto failed;
end_cb_data->watching_handle = *handle;
GET_CB_DATA(cb_data, param->callback, param->data, end_cb_data);
- ret = mm_sound_proxy_add_play_sound_end_callback(_mm_sound_stop_callback_wrapper_func, cb_data, play_end_callback_data_free_func, &end_cb_data->subs_id);
+ ret = mm_sound_proxy_add_play_sound_end_callback(_mm_sound_stop_callback_wrapper_func, cb_data,
+ play_end_callback_data_free_func, &end_cb_data->subs_id);
if (ret != MM_ERROR_NONE) {
debug_error("Add callback for play sound(%d) Failed", *handle);
}
device_node = (mm_sound_device_t *)list->data;
if (device_node) {
debug_log(" list idx[%d]: type[%17s], id[%02d], io_direction[%d], state[%d], name[%s]\n",
- count++, device_node->type, device_node->id, device_node->io_direction, device_node->state, device_node->name);
+ count++, device_node->type, device_node->id, device_node->io_direction,
+ device_node->state, device_node->name);
}
}
debug_log("======================== device list : end ============================\n");
}
static void _mm_sound_device_connected_callback_wrapper_func(int device_id, const char *device_type, int io_direction,
- int state, const char *name, int *stream_id, int stream_num, gboolean is_connected, void *userdata)
+ int state, const char *name, int *stream_id, int stream_num,
+ gboolean is_connected, void *userdata)
{
mm_sound_device_t device_h;
struct callback_data *cb_data = (struct callback_data*) userdata;
((mm_sound_device_connected_cb)(cb_data->user_cb))(&device_h, is_connected, cb_data->user_data);
}
-int mm_sound_client_add_device_connected_callback(int device_flags, mm_sound_device_connected_cb func, void* userdata, unsigned int *subs_id)
+int mm_sound_client_add_device_connected_callback(int device_flags, mm_sound_device_connected_cb func,
+ void* userdata, unsigned int *subs_id)
{
int ret = MM_ERROR_NONE;
struct callback_data *cb_data = NULL;
GET_CB_DATA(cb_data, func, userdata, (void*) device_flags);
- ret = mm_sound_proxy_add_device_connected_callback(device_flags, _mm_sound_device_connected_callback_wrapper_func, cb_data, g_free, subs_id);
+ ret = mm_sound_proxy_add_device_connected_callback(device_flags,
+ _mm_sound_device_connected_callback_wrapper_func,
+ cb_data, g_free, subs_id);
if (ret == MM_ERROR_NONE)
g_need_emergent_exit = TRUE;
}
static void _mm_sound_device_info_changed_callback_wrapper_func(int device_id, const char *device_type, int io_direction,
- int state, const char *name, int *stream_id, int stream_num, int changed_device_info_type, void *userdata)
+ int state, const char *name, int *stream_id, int stream_num,
+ int changed_device_info_type, void *userdata)
{
mm_sound_device_t device_h;
struct callback_data *cb_data = (struct callback_data*) userdata;
((mm_sound_device_info_changed_cb)(cb_data->user_cb))(&device_h, changed_device_info_type, cb_data->user_data);
}
-int mm_sound_client_add_device_info_changed_callback(int device_flags, mm_sound_device_info_changed_cb func, void *userdata, unsigned int *subs_id)
+int mm_sound_client_add_device_info_changed_callback(int device_flags, mm_sound_device_info_changed_cb func,
+ void *userdata, unsigned int *subs_id)
{
int ret = MM_ERROR_NONE;
struct callback_data *cb_data = (struct callback_data*) userdata;
GET_CB_DATA(cb_data, func, userdata, (void *) device_flags);
- ret = mm_sound_proxy_add_device_info_changed_callback(device_flags, _mm_sound_device_info_changed_callback_wrapper_func, cb_data, g_free, subs_id);
+ ret = mm_sound_proxy_add_device_info_changed_callback(device_flags,
+ _mm_sound_device_info_changed_callback_wrapper_func,
+ cb_data, g_free, subs_id);
debug_fleave();
return ret;
}
-static void _mm_sound_device_state_changed_callback_wrapper_func(int device_id, const char *device_type, int io_direction,
- int state, const char *name, int *stream_id, int stream_num, void *userdata)
+static void _mm_sound_device_state_changed_callback_wrapper_func(int device_id, const char *device_type,
+ int io_direction, int state, const char *name,
+ int *stream_id, int stream_num, void *userdata)
{
mm_sound_device_t device_h;
struct callback_data *cb_data = (struct callback_data*) userdata;
((mm_sound_device_state_changed_cb)(cb_data->user_cb))(&device_h, state, cb_data->user_data);
}
-int mm_sound_client_add_device_state_changed_callback(int device_flags, mm_sound_device_state_changed_cb func, void *userdata, unsigned int *id)
+int mm_sound_client_add_device_state_changed_callback(int device_flags, mm_sound_device_state_changed_cb func,
+ void *userdata, unsigned int *id)
{
int ret = MM_ERROR_NONE;
struct callback_data *cb_data = (struct callback_data*) userdata;
GET_CB_DATA(cb_data, func, userdata, (void *) device_flags);
- ret = mm_sound_proxy_add_device_state_changed_callback(device_flags, _mm_sound_device_state_changed_callback_wrapper_func, cb_data, g_free, id);
+ ret = mm_sound_proxy_add_device_state_changed_callback(device_flags,
+ _mm_sound_device_state_changed_callback_wrapper_func,
+ cb_data, g_free, id);
debug_fleave();
return ret;
return ret;
}
-static void _mm_sound_volume_changed_callback_wrapper_func(const char *direction, const char *volume_type_str, int volume_level, void *userdata)
+static void _mm_sound_volume_changed_callback_wrapper_func(const char *direction, const char *volume_type_str,
+ int volume_level, void *userdata)
{
volume_type_t volume_type = 0;
struct callback_data *cb_data = (struct callback_data *) userdata;
- debug_log("[Wrapper CB][Volume Changed] direction : %s, volume_type : %s, volume_level : %d", direction, volume_type_str, volume_level);
+ debug_log("[Wrapper CB][Volume Changed] direction : %s, volume_type : %s, volume_level : %d",
+ direction, volume_type_str, volume_level);
if (cb_data == NULL) {
debug_warning("volume changed callback data null");
debug_error("volume type convert failed");
return;
}
- debug_log("Call volume changed user cb, direction : %s, vol_type : %s(%d), level : %u", direction, volume_type_str, volume_type, volume_level);
+ debug_log("Call volume changed user cb, direction : %s, vol_type : %s(%d), level : %u",
+ direction, volume_type_str, volume_type, volume_level);
((mm_sound_volume_changed_cb)(cb_data->user_cb))(volume_type, volume_level, cb_data->user_data);
}
return NULL;
}
+static gboolean _focus_fd_prepare(GSource *source, gint *timeout)
+{
+#ifdef __DEBUG__
+ debug_warning("[ PREPARE : %p, (%p, %d)", source, timeout, timeout? *timeout : -1);
+#endif
+ return FALSE;
+}
+
static gboolean _focus_fd_check(GSource * source)
{
- GSList *fd_list;
- GPollFD *temp;
+ FocusSource* fsource = (FocusSource *)source;
- if (!source) {
+ if (!fsource) {
debug_error("GSource is null");
return FALSE;
}
- fd_list = source->poll_fds;
- if (!fd_list) {
- debug_error("fd_list is null");
+#ifdef __DEBUG__
+ debug_warning("CHECK : %p, 0x%x ]", source, fsource->pollfd.revents);
+#endif
+ if (fsource->pollfd.revents & (POLLIN | POLLPRI))
+ return TRUE;
+ else
return FALSE;
- }
- do {
- temp = (GPollFD*)fd_list->data;
- if (!temp) {
- debug_error("fd_list->data is null");
- return FALSE;
- }
- if (temp->revents & (POLLIN | POLLPRI)) {
- return TRUE;
- }
- fd_list = fd_list->next;
- } while (fd_list);
-
- return FALSE; /* there is no change in any fd state */
}
-static gboolean _focus_fd_prepare(GSource *source, gint *timeout)
+static gboolean _focus_fd_dispatch(GSource *source, GSourceFunc callback, gpointer user_data)
{
- return FALSE;
+ debug_warning("*** DISPATCH : %p, (%p, %p)", source, callback, user_data);
+ return callback(user_data);
}
-static gboolean _focus_fd_dispatch(GSource *source, GSourceFunc callback, gpointer user_data)
+static void _focus_fd_finalize(GSource *source)
{
- callback(user_data);
- return TRUE;
+ debug_warning("### FINALIZE : %p", source);
}
static int _focus_find_index_by_handle(int handle)
if (!data) {
debug_error("GPollFd is null");
- return FALSE;
+ return G_SOURCE_CONTINUE;
}
if (data->revents & (POLLIN | POLLPRI)) {
int changed_state = -1;
char str_error[256];
strerror_r(errno, str_error, sizeof(str_error));
debug_error("GpollFD read fail, errno=%d(%s)",errno, str_error);
- return FALSE;
+ return G_SOURCE_CONTINUE;
}
changed_state = cb_data.state;
focus_index = _focus_find_index_by_handle(cb_data.handle);
if (focus_index == -1) {
debug_error("Could not find index");
- return FALSE;
+ return G_SOURCE_CONTINUE;
}
g_mutex_lock(&g_focus_sound_handle[focus_index].focus_lock);
tid = g_focus_sound_handle[focus_index].focus_tid;
if (changed_state != -1) {
- debug_msg("Got and start CB : TID(%d), handle(%d), type(%d), state(%d,(DEACTIVATED(0)/ACTIVATED(1)), trigger(%s)", tid, cb_data.handle, cb_data.type, cb_data.state, cb_data.stream_type);
+ debug_msg("Got and start CB : TID(%d), handle(%d), type(%d), state(%d,(DEACTIVATED(0)/ACTIVATED(1)), trigger(%s)",
+ tid, cb_data.handle, cb_data.type, cb_data.state, cb_data.stream_type);
if (g_focus_sound_handle[focus_index].focus_callback == NULL) {
debug_error("callback is null..");
g_mutex_unlock(&g_focus_sound_handle[focus_index].focus_lock);
- return FALSE;
+ return G_SOURCE_CONTINUE;
}
debug_msg("[CALLBACK(%p) START]",g_focus_sound_handle[focus_index].focus_callback);
- (g_focus_sound_handle[focus_index].focus_callback)(cb_data.handle, cb_data.type, cb_data.state, cb_data.stream_type, cb_data.option, cb_data.ext_info, g_focus_sound_handle[focus_index].user_data);
+ g_focus_sound_handle[focus_index].focus_callback(cb_data.handle, cb_data.type, cb_data.state,
+ cb_data.stream_type, cb_data.option, cb_data.ext_info,
+ g_focus_sound_handle[focus_index].user_data);
debug_msg("[CALLBACK END]");
if (g_focus_session_interrupt_info.user_cb) {
debug_msg("sending session interrupt callback(%p)", g_focus_session_interrupt_info.user_cb);
- (g_focus_session_interrupt_info.user_cb)(cb_data.state, cb_data.stream_type, false, g_focus_session_interrupt_info.user_data);
+ g_focus_session_interrupt_info.user_cb(cb_data.state, cb_data.stream_type, false,
+ g_focus_session_interrupt_info.user_data);
}
}
#ifdef CONFIG_ENABLE_RETCB
int rett = 0;
int tmpfd = -1;
unsigned int buf = 0;
- char *filename2 = g_strdup_printf("/tmp/FOCUS.%d.%dr", g_focus_sound_handle[focus_index].focus_tid, cb_data.handle);
+ char *filename2 = g_strdup_printf("/tmp/FOCUS.%d.%dr",
+ g_focus_sound_handle[focus_index].focus_tid,
+ cb_data.handle);
tmpfd = open(filename2, O_WRONLY | O_NONBLOCK);
if (tmpfd < 0) {
char str_error[256];
strerror_r(errno, str_error, sizeof(str_error));
- debug_warning("[RETCB][Failed(May Server Close First)]tid(%d) fd(%d) %s errno=%d(%s)\n", tid, tmpfd, filename2, errno, str_error);
+ debug_warning("[RETCB][Failed(May Server Close First)]tid(%d) fd(%d) %s errno=%d(%s)\n",
+ tid, tmpfd, filename2, errno, str_error);
g_free(filename2);
g_mutex_unlock(&g_focus_sound_handle[focus_index].focus_lock);
- return FALSE;
+ return G_SOURCE_CONTINUE;
}
/* buf contains data as below,
* |<--12bits--><--4bits (reacquisition)--><--16bits (handle)-->| */
g_mutex_unlock(&g_focus_sound_handle[focus_index].focus_lock);
- return TRUE;
+ return G_SOURCE_CONTINUE;
}
static gboolean _focus_watch_callback_handler(gpointer d)
if (!data) {
debug_error("GPollFd is null");
- return FALSE;
+ return G_SOURCE_CONTINUE;
}
if (data->revents & (POLLIN | POLLPRI)) {
count = read(data->fd, &cb_data, sizeof(cb_data));
char str_error[256];
strerror_r(errno, str_error, sizeof(str_error));
debug_error("GpollFD read fail, errno=%d(%s)",errno, str_error);
- return FALSE;
+ return G_SOURCE_CONTINUE;
}
focus_index = _focus_watch_find_index_by_handle(cb_data.handle);
if (focus_index == -1) {
debug_error("Could not find index");
- return FALSE;
+ return G_SOURCE_CONTINUE;
}
if (!g_focus_sound_handle[focus_index].is_used) {
- debug_warning("unsetting watch calllback has been already requested");
+ debug_warning("unsetting watch callback has been already requested");
goto SKIP_CB_AND_RET;
}
tid = g_focus_sound_handle[focus_index].focus_tid;
- debug_msg("Got and start CB : TID(%d), handle(%d), type(%d), state(%d,(DEACTIVATED(0)/ACTIVATED(1)), trigger(%s)", tid, cb_data.handle, cb_data.type, cb_data.state, cb_data.stream_type);
+ debug_msg("Got and start CB : TID(%d), handle(%d), type(%d), state(%d,(DEACTIVATED(0)/ACTIVATED(1)), trigger(%s)",
+ tid, cb_data.handle, cb_data.type, cb_data.state, cb_data.stream_type);
if (g_focus_sound_handle[focus_index].watch_callback == NULL) {
debug_msg("callback is null..");
} else {
debug_msg("[CALLBACK(%p) START]",g_focus_sound_handle[focus_index].watch_callback);
- (g_focus_sound_handle[focus_index].watch_callback)(cb_data.handle, cb_data.type, cb_data.state, cb_data.stream_type, cb_data.ext_info, g_focus_sound_handle[focus_index].user_data);
+ (g_focus_sound_handle[focus_index].watch_callback)(cb_data.handle, cb_data.type, cb_data.state,
+ cb_data.stream_type, cb_data.ext_info,
+ g_focus_sound_handle[focus_index].user_data);
debug_msg("[CALLBACK END]");
if (g_focus_session_interrupt_info.user_cb) {
debug_msg("sending session interrupt callback(%p)", g_focus_session_interrupt_info.user_cb);
- (g_focus_session_interrupt_info.user_cb)(cb_data.state, cb_data.stream_type, true, g_focus_session_interrupt_info.user_data);
+ (g_focus_session_interrupt_info.user_cb)(cb_data.state, cb_data.stream_type, true,
+ g_focus_session_interrupt_info.user_data);
}
}
int rett = 0;
int tmpfd = -1;
int buf = -1;
- char *filename2 = g_strdup_printf("/tmp/FOCUS.%d.%d.wchr", g_focus_sound_handle[focus_index].focus_tid, cb_data.handle);
+ char *filename2 = g_strdup_printf("/tmp/FOCUS.%d.%d.wchr",
+ g_focus_sound_handle[focus_index].focus_tid,
+ cb_data.handle);
tmpfd = open(filename2, O_WRONLY | O_NONBLOCK);
if (tmpfd < 0) {
char str_error[256];
strerror_r(errno, str_error, sizeof(str_error));
- debug_warning("[RETCB][Failed(May Server Close First)]tid(%d) fd(%d) %s errno=%d(%s)\n", tid, tmpfd, filename2, errno, str_error);
+ debug_warning("[RETCB][Failed(May Server Close First)]tid(%d) fd(%d) %s errno=%d(%s)\n",
+ tid, tmpfd, filename2, errno, str_error);
g_free(filename2);
g_mutex_unlock(&g_focus_sound_handle[focus_index].focus_lock);
- return FALSE;
+ return G_SOURCE_CONTINUE;
}
buf = cb_data.handle;
rett = write(tmpfd, &buf, sizeof(buf));
debug_fleave();
- return TRUE;
+ return G_SOURCE_CONTINUE;
}
static void _focus_open_callback(int index, bool is_for_watching)
}
if (is_for_watching) {
- filename = g_strdup_printf("/tmp/FOCUS.%d.%d.wch", g_focus_sound_handle[index].focus_tid, g_focus_sound_handle[index].handle);
+ filename = g_strdup_printf("/tmp/FOCUS.%d.%d.wch",
+ g_focus_sound_handle[index].focus_tid,
+ g_focus_sound_handle[index].handle);
} else {
- filename = g_strdup_printf("/tmp/FOCUS.%d.%d", g_focus_sound_handle[index].focus_tid, g_focus_sound_handle[index].handle);
+ filename = g_strdup_printf("/tmp/FOCUS.%d.%d",
+ g_focus_sound_handle[index].focus_tid,
+ g_focus_sound_handle[index].handle);
}
pre_mask = umask(0);
if (mknod(filename, S_IFIFO|0666, 0)) {
if (g_focus_sound_handle[index].focus_fd == -1) {
debug_error("Open fail : index(%d), file open error(%d)", index, errno);
} else {
- debug_log("Open success : index(%d), filename(%s), fd(%d)", index, filename, g_focus_sound_handle[index].focus_fd);
+ debug_log("Open success : index(%d), filename(%s), fd(%d)",
+ index, filename, g_focus_sound_handle[index].focus_fd);
}
g_free(filename);
filename = NULL;
char *filename2;
if (is_for_watching) {
- filename2 = g_strdup_printf("/tmp/FOCUS.%d.%d.wchr", g_focus_sound_handle[index].focus_tid, g_focus_sound_handle[index].handle);
+ filename2 = g_strdup_printf("/tmp/FOCUS.%d.%d.wchr",
+ g_focus_sound_handle[index].focus_tid,
+ g_focus_sound_handle[index].handle);
} else {
- filename2 = g_strdup_printf("/tmp/FOCUS.%d.%dr", g_focus_sound_handle[index].focus_tid, g_focus_sound_handle[index].handle);
+ filename2 = g_strdup_printf("/tmp/FOCUS.%d.%dr",
+ g_focus_sound_handle[index].focus_tid,
+ g_focus_sound_handle[index].handle);
}
pre_mask = umask(0);
if (mknod(filename2, S_IFIFO | 0666, 0)) {
}
if (is_for_watching) {
- filename = g_strdup_printf("/tmp/FOCUS.%d.%d.wch", g_focus_sound_handle[index].focus_tid, g_focus_sound_handle[index].handle);
+ filename = g_strdup_printf("/tmp/FOCUS.%d.%d.wch",
+ g_focus_sound_handle[index].focus_tid,
+ g_focus_sound_handle[index].handle);
} else {
- filename = g_strdup_printf("/tmp/FOCUS.%d.%d", g_focus_sound_handle[index].focus_tid, g_focus_sound_handle[index].handle);
+ filename = g_strdup_printf("/tmp/FOCUS.%d.%d",
+ g_focus_sound_handle[index].focus_tid,
+ g_focus_sound_handle[index].handle);
}
if (remove(filename)) {
- debug_warning("remove(%s) failure (focus_server probably removed it in advance), errno(%d)", filename, errno);
+ debug_warning("remove(%s) failure (focus_server probably removed it in advance), errno(%d)",
+ filename, errno);
}
g_free(filename);
filename = NULL;
char *filename2;
if (is_for_watching) {
- filename2 = g_strdup_printf("/tmp/FOCUS.%d.%d.wchr", g_focus_sound_handle[index].focus_tid, g_focus_sound_handle[index].handle);
+ filename2 = g_strdup_printf("/tmp/FOCUS.%d.%d.wchr",
+ g_focus_sound_handle[index].focus_tid,
+ g_focus_sound_handle[index].handle);
} else {
- filename2 = g_strdup_printf("/tmp/FOCUS.%d.%dr", g_focus_sound_handle[index].focus_tid, g_focus_sound_handle[index].handle);
+ filename2 = g_strdup_printf("/tmp/FOCUS.%d.%dr",
+ g_focus_sound_handle[index].focus_tid,
+ g_focus_sound_handle[index].handle);
}
if (remove(filename2)) {
- debug_warning("remove(%s) failure (focus_server probably removed it in advance), errno(%d)", filename2, errno);
+ debug_warning("remove(%s) failure (focus_server probably removed it in advance), errno(%d)",
+ filename2, errno);
}
g_free(filename2);
filename2 = NULL;
}
-static bool _focus_add_sound_callback(int index, int fd, gushort events, focus_gLoopPollHandler_t p_gloop_poll_handler)
+static GSourceFuncs event_funcs = {
+ .prepare = _focus_fd_prepare,
+ .check = _focus_fd_check,
+ .dispatch = _focus_fd_dispatch,
+ .finalize = _focus_fd_finalize,
+};
+
+static bool _focus_add_sound_callback(int index, focus_gLoopPollHandler_t p_gloop_poll_handler)
{
- GSource* g_src = NULL;
- GSourceFuncs *g_src_funcs = NULL; /* handler function */
- guint g_src_id = 0;
- GPollFD *g_poll_fd = NULL; /* file descriptor */
+ FocusSource *fsrc = NULL;
+ GSource *src = NULL;
+ guint fsrc_id = 0;
debug_fenter();
g_mutex_init(&g_focus_sound_handle[index].focus_lock);
- /* 1. make GSource Object */
- g_src_funcs = (GSourceFuncs *)g_malloc(sizeof(GSourceFuncs));
- if (!g_src_funcs) {
- debug_error("failed to g_malloc for g_src_funcs");
+ src = g_source_new(&event_funcs, sizeof(FocusSource));
+ if (!src) {
+ debug_error("failed to g_source_new for focus source");
goto ERROR;
}
- g_src_funcs->prepare = _focus_fd_prepare;
- g_src_funcs->check = _focus_fd_check;
- g_src_funcs->dispatch = _focus_fd_dispatch;
- g_src_funcs->finalize = NULL;
- g_src = g_source_new(g_src_funcs, sizeof(GSource));
- if (!g_src) {
- debug_error("failed to g_source_new for g_src");
- goto ERROR;
- }
+ fsrc = (FocusSource*) src;
- /* 2. add file description which used in g_loop() */
- g_poll_fd = (GPollFD *)g_malloc(sizeof(GPollFD));
- if (!g_poll_fd) {
- debug_error("failed to g_malloc for g_poll_fd");
- goto ERROR;
- }
- g_poll_fd->fd = fd;
- g_poll_fd->events = events;
+ fsrc->pollfd.fd = g_focus_sound_handle[index].focus_fd;
+ fsrc->pollfd.events = (gushort)(POLLIN | POLLPRI);
+ g_source_add_poll(src, &fsrc->pollfd);
+
+ g_source_set_callback(src, p_gloop_poll_handler, (gpointer)&fsrc->pollfd, NULL);
- /* 3. combine g_source object and file descriptor */
- g_source_add_poll(g_src, g_poll_fd);
- g_src_id = g_source_attach(g_src, g_main_loop_get_context(g_focus_sound_handle[index].focus_loop));
- if (!g_src_id) {
+ debug_warning("fsrc(%p), src_funcs(%p), pollfd(%p), fd(%d)",
+ fsrc, &event_funcs, &fsrc->pollfd, fsrc->pollfd.fd);
+
+ fsrc_id = g_source_attach(src, g_main_loop_get_context(g_focus_sound_handle[index].focus_loop));
+ if (!fsrc_id) {
debug_error("failed to attach the source to context");
goto ERROR;
}
+ g_source_unref(src);
- /* 4. set callback */
- g_source_set_callback(g_src, p_gloop_poll_handler,(gpointer)g_poll_fd, NULL);
-
- debug_log("g_malloc : g_src_funcs(%p), g_poll_fd(%p)", g_src_funcs, g_poll_fd);
-
- /* 5. store to global handle */
- g_focus_sound_handle[index].g_src = g_src;
- g_focus_sound_handle[index].g_src_funcs = g_src_funcs;
- g_focus_sound_handle[index].g_poll_fd = g_poll_fd;
+ g_focus_sound_handle[index].g_src = src;
debug_fleave();
return true;
ERROR:
- g_free(g_src_funcs);
- g_free(g_poll_fd);
- if (g_src)
- g_source_unref(g_src);
+ if (src)
+ g_source_unref(src);
return false;
}
static bool _focus_remove_sound_callback(int index)
{
- bool ret = true;
focus_sound_info_t *h = NULL;
debug_fenter();
}
h = &g_focus_sound_handle[index];
-
- if (h->g_src && h->g_poll_fd) {
- debug_log("g_source_remove_poll : fd(%d), event(0x%x)",
- h->g_poll_fd->fd, h->g_poll_fd->events);
- g_source_remove_poll(h->g_src, h->g_poll_fd);
- } else {
- debug_error("[%d] g_src[%p], g_poll_fd[%p]",
- index, h->g_src, h->g_poll_fd);
- ret = false;
- }
-
if (h->g_src) {
g_source_destroy(h->g_src);
- g_source_unref(h->g_src);
h->g_src = NULL;
}
- debug_log("g_free : g_src_funcs(%p), g_poll_fd(%p)",
- h->g_src_funcs, h->g_poll_fd);
-
- g_free(h->g_src_funcs);
- h->g_src_funcs = NULL;
-
- g_free(h->g_poll_fd);
- h->g_poll_fd = NULL;
-
h->focus_callback = NULL;
h->watch_callback = NULL;
debug_fleave();
- return ret;
+ return true;
}
-
static void _focus_add_callback(int index, bool is_for_watching)
{
debug_fenter();
}
if (!is_for_watching) {
- if (!_focus_add_sound_callback(index, g_focus_sound_handle[index].focus_fd,
- (gushort)POLLIN | POLLPRI, _focus_callback_handler))
+ if (!_focus_add_sound_callback(index, _focus_callback_handler))
debug_error("failed to _focus_add_sound_callback(%p)", _focus_callback_handler);
} else { // need to check if it's necessary
- if (!_focus_add_sound_callback(index, g_focus_sound_handle[index].focus_fd,
- (gushort)POLLIN | POLLPRI, _focus_watch_callback_handler))
+ if (!_focus_add_sound_callback(index, _focus_watch_callback_handler))
debug_error("failed to _focus_add_sound_callback(%p)", _focus_watch_callback_handler);
}
debug_fleave();
return ret;
}
-int mm_sound_client_register_focus(int id, int pid, const char *stream_type, mm_sound_focus_changed_cb callback, bool is_for_session, void* user_data)
+int mm_sound_client_register_focus(int id, int pid, const char *stream_type,
+ mm_sound_focus_changed_cb callback,
+ bool is_for_session, void* user_data)
{
int ret = MM_ERROR_NONE;
int instance;
g_focus_sound_handle[index].is_used = false;
_focus_deinit_context(index);
+
cleanup:
MMSOUND_LEAVE_CRITICAL_SECTION(&g_index_mutex);
debug_fleave();
ret = mm_sound_proxy_get_acquired_focus_stream_type(focus_type, stream_type, option, &ext_str);
if (ret == MM_ERROR_NONE) {
- debug_msg("[Client] Success to get stream type of acquired focus, stream_type(%s), ext_info(%s)\n", *stream_type, ext_str);
+ debug_msg("[Client] Success to get stream type of acquired focus, stream_type(%s), ext_info(%s)\n",
+ *stream_type, ext_str);
*ext_info = strdup(ext_str);
g_free(ext_str);
} else {
return ret;
}
-int mm_sound_client_set_focus_watch_callback(int pid, mm_sound_focus_type_e focus_type, mm_sound_focus_changed_watch_cb callback, bool is_for_session, void* user_data, int *id)
+int mm_sound_client_set_focus_watch_callback(int pid, mm_sound_focus_type_e focus_type,
+ mm_sound_focus_changed_watch_cb callback,
+ bool is_for_session, void* user_data, int *id)
{
int ret = MM_ERROR_NONE;
int instance;
g_focus_sound_handle[index].user_data = user_data;
g_focus_sound_handle[index].is_for_session = is_for_session;
- ret = mm_sound_proxy_set_focus_watch_callback(pid, g_focus_sound_handle[index].handle, focus_type, callback, is_for_session, user_data);
+ ret = mm_sound_proxy_set_focus_watch_callback(pid, g_focus_sound_handle[index].handle, focus_type,
+ callback, is_for_session, user_data);
if (ret == MM_ERROR_NONE) {
debug_msg("[Client] Success to watch focus");
g_focus_sound_handle[index].is_used = false;
- ret = mm_sound_proxy_unset_focus_watch_callback(g_focus_sound_handle[index].focus_tid, g_focus_sound_handle[index].handle, g_focus_sound_handle[index].is_for_session);
+ ret = mm_sound_proxy_unset_focus_watch_callback(g_focus_sound_handle[index].focus_tid,
+ g_focus_sound_handle[index].handle,
+ g_focus_sound_handle[index].is_for_session);
if (ret == MM_ERROR_NONE)
debug_msg("[Client] Success to unwatch focus\n");