int rett = 0;
int tmpfd = -1;
int buf = -1;
- char *filename2 = g_strdup_printf("/tmp/FOCUS.%d.wchr", g_focus_sound_handle[focus_index].focus_tid);
+ 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];
debug_fenter();
if (is_for_watching) {
- filename = g_strdup_printf("/tmp/FOCUS.%d.wch", g_focus_sound_handle[index].focus_tid);
+ 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);
}
debug_error("mknod() failure, errno(%d)", errno);
}
umask(pre_mask);
- g_focus_sound_handle[index].focus_fd = open( filename, O_RDWR|O_NONBLOCK);
+ g_focus_sound_handle[index].focus_fd = open(filename, O_RDWR|O_NONBLOCK);
if (g_focus_sound_handle[index].focus_fd == -1) {
debug_error("Open fail : index(%d), file open error(%d)", index, errno);
} else {
char *filename2;
if (is_for_watching) {
- filename2 = g_strdup_printf("/tmp/FOCUS.%d.wchr", g_focus_sound_handle[index].focus_tid);
+ 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);
}
void _focus_close_callback(int index, bool is_for_watching)
{
+ char *filename = NULL;
+
debug_fenter();
if (g_focus_sound_handle[index].focus_fd < 0) {
- debug_error("Close fail : fd error.");
+ debug_error("Close fail : index(%d)", index);
} else {
- char *filename;
- if (is_for_watching) {
- filename = g_strdup_printf("/tmp/FOCUS.%d.wch", g_focus_sound_handle[index].focus_tid);
- } else {
- filename = g_strdup_printf("/tmp/FOCUS.%d.%d", g_focus_sound_handle[index].focus_tid, g_focus_sound_handle[index].handle);
- }
close(g_focus_sound_handle[index].focus_fd);
- if (remove(filename)) {
- debug_error("remove() failure, filename(%s), errno(%d)", filename, errno);
- }
- debug_log("Close Sucess : index(%d), filename(%s)", index, filename);
- g_free(filename);
- filename = NULL;
+ debug_log("Close Sucess : index(%d)", index);
}
-#ifdef CONFIG_ENABLE_RETCB
- char *filename2;
-
if (is_for_watching) {
- filename2 = g_strdup_printf("/tmp/FOCUS.%d.wchr", g_focus_sound_handle[index].focus_tid);
+ filename = g_strdup_printf("/tmp/FOCUS.%d.%d.wch", 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);
+ 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);
}
+ g_free(filename);
+ filename = NULL;
- /* Defensive code - wait until callback timeout although callback is removed */
- int buf = MM_ERROR_NONE; //no need to specify cb result to server, just notice if the client got the callback properly or not
- int tmpfd = -1;
- char str_error[256];
+#ifdef CONFIG_ENABLE_RETCB
+ char *filename2;
- tmpfd = open(filename2, O_WRONLY | O_NONBLOCK);
- if (tmpfd < 0) {
- strerror_r(errno, str_error, sizeof(str_error));
- debug_warning("could not open file(%s) (may server close it first), tid(%d) fd(%d) %s errno=%d(%s)",
- filename2, g_focus_sound_handle[index].focus_tid, tmpfd, filename2, errno, str_error);
+ 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);
} else {
- ssize_t written;
- debug_msg("write MM_ERROR_NONE(tid:%d) for waiting server", g_focus_sound_handle[index].focus_tid);
- written = write(tmpfd, &buf, sizeof(buf));
- if (written == -1) {
- strerror_r(errno, str_error, sizeof(str_error));
- debug_warning("write failed, %s", str_error);
- }
- close(tmpfd);
+ 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_error("remove() failure, filename(%s), 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;
+
+ debug_fleave();
#endif
}
{
GSource* g_src = NULL;
GSourceFuncs *g_src_funcs = NULL; /* handler function */
- guint gsource_handle;
+ guint g_src_id;
GPollFD *g_poll_fd = NULL; /* file descriptor */
debug_fenter();
/* 1. make GSource Object */
g_src_funcs = (GSourceFuncs *)g_malloc(sizeof(GSourceFuncs));
if (!g_src_funcs) {
- debug_error("g_malloc failed on g_src_funcs");
- return false;
+ debug_error("failed to g_malloc for g_src_funcs");
+ goto ERROR;
}
g_src_funcs->prepare = _focus_fd_prepare;
g_src_funcs->finalize = NULL;
g_src = g_source_new(g_src_funcs, sizeof(GSource));
if (!g_src) {
- debug_error("g_malloc failed on m_readfd");
- return false;
+ debug_error("failed to g_source_new for g_src");
+ goto ERROR;
}
g_focus_sound_handle[index].focus_src = g_src;
g_focus_sound_handle[index].g_src_funcs = g_src_funcs;
/* 2. add file description which used in g_loop() */
g_poll_fd = (GPollFD *)g_malloc(sizeof(GPollFD));
if (!g_poll_fd) {
- debug_error("g_malloc failed on g_poll_fd");
- return false;
+ debug_error("failed to g_malloc for g_poll_fd");
+ goto ERROR;
}
g_poll_fd->fd = fd;
g_poll_fd->events = events;
/* 3. combine g_source object and file descriptor */
g_source_add_poll(g_src, g_poll_fd);
- gsource_handle = g_source_attach(g_src, g_main_loop_get_context(g_focus_loop));
- if (!gsource_handle) {
- debug_error(" Failed to attach the source to context");
- return false;
+ g_src_id = g_source_attach(g_src, g_main_loop_get_context(g_focus_loop));
+ if (!g_src_id) {
+ debug_error("failed to attach the source to context");
+ goto ERROR;
}
- //g_source_unref(g_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(%#X),g_poll_fd(%#X) g_source_add_poll:g_src_id(%d) g_source_set_callback:errno(%d)",
- g_src_funcs, g_poll_fd, gsource_handle, errno);
+ debug_log("g_malloc : g_src_funcs(%x), g_poll_fd(%x)", g_src_funcs, g_poll_fd);
debug_fleave();
return true;
+ERROR:
+ if (g_src_funcs)
+ g_free(g_src_funcs);
+ if (g_poll_fd)
+ g_free(g_poll_fd);
+ if (g_src_id)
+ g_source_destroy(g_src);
+ if (g_src)
+ g_source_unref(g_src);
+ return false;
}
static bool _focus_remove_sound_callback(int index, gushort events)
if (!g_poll_fd) {
debug_error("g_poll_fd is null..");
ret = false;
- goto init_handle;
+ goto RELEASE;
}
g_poll_fd->fd = g_focus_sound_handle[index].focus_fd;
g_poll_fd->events = events;
if (!g_focus_sound_handle[index].focus_src) {
- debug_error("FOCUS_sound_handle[%d].focus_src is null..", index);
- goto init_handle;
+ debug_error("g_focus_sound_handle[%d].focus_src is null..", index);
+ ret = false;
+ goto RELEASE;
}
- debug_log(" g_source_remove_poll : fd(%d), event(%x), errno(%d)", g_poll_fd->fd, g_poll_fd->events, errno);
g_source_remove_poll(g_focus_sound_handle[index].focus_src, g_poll_fd);
+ debug_log("g_source_remove_poll : fd(%d), event(%x)", g_poll_fd->fd, g_poll_fd->events);
-init_handle:
-
- if (g_focus_sound_handle[index].focus_src) {
+RELEASE:
+ if (g_focus_sound_handle[index].focus_src)
g_source_destroy(g_focus_sound_handle[index].focus_src);
- if (!g_source_is_destroyed (g_focus_sound_handle[index].focus_src)) {
- debug_warning(" failed to g_source_destroy(), focus_src(0x%p)", g_focus_sound_handle[index].focus_src);
- }
- }
- debug_log(" g_free : g_src_funcs(%#X), g_poll_fd(%#X)", g_src_funcs, g_poll_fd);
+ debug_log("g_free : g_src_funcs(%x), g_poll_fd(%x)", g_src_funcs, g_poll_fd);
if (g_src_funcs) {
g_free(g_src_funcs);
g_src_funcs = NULL;
g_free(g_poll_fd);
g_poll_fd = NULL;
}
+ if (g_focus_sound_handle[index].focus_src)
+ g_source_unref(g_focus_sound_handle[index].focus_src);
g_focus_sound_handle[index].g_src_funcs = NULL;
g_focus_sound_handle[index].g_poll_fd = NULL;
#ifdef SUPPORT_CONTAINER
container_info_t* container_info = __get_container_info(instance_id);
if (!container_info) {
- debug_error ("__get_container_info failed");
+ debug_error("__get_container_info failed");
return NULL;
}
if (instance_id == container_info->pid) {
- debug_error ("This might be in the HOST(%s)[%d], let's form normal path",
+ debug_warning("This might be in the HOST(%s)[%d], let's form normal path",
container_info->name, instance_id);
if (is_watch) {
- path = g_strdup_printf("/tmp/FOCUS.%d.wch", instance_id);
+ path = g_strdup_printf("/tmp/FOCUS.%d.%d.wch", instance_id, handle);
} else {
path = g_strdup_printf("/tmp/FOCUS.%d.%d", instance_id, handle);
}
} else {
if (is_watch) {
- path = g_strdup_printf("/var/lib/lxc/%s/rootfs/tmp/FOCUS.%d.wch",
- container_info->name, container_info->pid);
+ path = g_strdup_printf("/var/lib/lxc/%s/rootfs/tmp/FOCUS.%d.%d.wch",
+ container_info->name, container_info->pid, handle);
} else {
path = g_strdup_printf("/var/lib/lxc/%s/rootfs/tmp/FOCUS.%d.%d",
container_info->name, container_info->pid, handle);
}
#else
if (is_watch) {
- path = g_strdup_printf("/tmp/FOCUS.%d.wch", instance_id);
+ path = g_strdup_printf("/tmp/FOCUS.%d.%d.wch", instance_id, handle);
} else {
path = g_strdup_printf("/tmp/FOCUS.%d.%d", instance_id, handle);
}
filename = __get_focus_pipe_path(node->pid, node->handle_id, NULL, false);
filename2 = __get_focus_pipe_path(node->pid, node->handle_id, "r", false);
} else {
- filename = __get_focus_pipe_path(node->pid, -1, NULL, true);
- filename2 = __get_focus_pipe_path(node->pid, -1, "r", true);
+ filename = __get_focus_pipe_path(node->pid, node->handle_id, NULL, true);
+ filename2 = __get_focus_pipe_path(node->pid, node->handle_id, "r", true);
}
if (filename) {
if(remove(filename))
debug_error("remove() failure, filename(%s), errno(%d)", filename, errno);
+ else
+ debug_log("removed file(%s)", filename);
free(filename);
}
if (filename2) {
if(remove(filename2))
debug_error("remove() failure, filename2(%s), errno(%d)", filename2, errno);
+ else
+ debug_log("removed file(%s)", filename2);
free(filename2);
}
* Open callback cmd pipe
*
**************************************/
- filename = __get_focus_pipe_path(cb_data.pid, -1, NULL, true);
+ filename = __get_focus_pipe_path(cb_data.pid, cb_data.handle, NULL, true);
+ if (filename == NULL) {
+ debug_error("[CB] failed to get watch pipe");
+ goto RELEASE;
+ }
if ((fd_FOCUS = open(filename, O_WRONLY|O_NONBLOCK)) == -1) {
- debug_error("[CallCB] %s open error\n", filename);
- goto fail;
+ char str_error[256];
+ strerror_r(errno, str_error, sizeof(str_error));
+ debug_error("[CB] failed to open watch pipe (%s, err:%s)\n", filename, str_error);
+ goto RELEASE;
}
/******************************************
* before writing callback cmd to pipe
*
******************************************/
- filename2 = __get_focus_pipe_path(cb_data.pid, -1, "r", true);
+ filename2 = __get_focus_pipe_path(cb_data.pid, cb_data.handle, "r", true);
if (filename2 == NULL) {
- debug_error("[RETCB] Fail to get watch return pipe");
- goto fail;
+ debug_error("[RETCB] failed to get watch return pipe");
+ goto RELEASE;
}
- if ((fd_FOCUS_R= open(filename2,O_RDONLY|O_NONBLOCK)) == -1) {
+ if ((fd_FOCUS_R= open(filename2, O_RDONLY|O_NONBLOCK)) == -1) {
char str_error[256];
- strerror_r (errno, str_error, sizeof(str_error));
- debug_error("[RETCB] Fail to open fifo (%s)\n", str_error);
- goto fail;
+ strerror_r(errno, str_error, sizeof(str_error));
+ debug_error("[RETCB] failed to open watch return pipe (%s, err:%s)\n", filename2, str_error);
+ goto RELEASE;
}
- debug_log(" open return cb %s\n", filename2);
/*******************************************
* Write Callback msg
*******************************************/
if (write(fd_FOCUS, &cb_data ,sizeof(cb_data)) == -1) {
- debug_error("[CallCB] %s fprintf error\n", filename);
- goto fail;
+ char str_error[256];
+ strerror_r(errno, str_error, sizeof(str_error));
+ debug_error("[CallCB] failed to write (err:%s)\n", str_error);
+ goto RELEASE;
}
- /**************************************
- *
- * Close callback cmd pipe
- *
- **************************************/
- close(fd_FOCUS);
- fd_FOCUS = -1;
-
- g_free(filename);
- filename = NULL;
-
- pfd.fd = fd_FOCUS_R;
- pfd.events = POLLIN;
- pfd.revents = 0;
-
/*********************************************
*
* Wait callback result msg
*
********************************************/
- debug_error("[RETCB]wait callback(tid=%d, cmd=%d, timeout=%d)\n", cb_data.pid, command, pollingTimeout);
+ pfd.fd = fd_FOCUS_R;
+ pfd.events = POLLIN;
+ pfd.revents = 0;
+ debug_error("[RETCB] wait callback(tid=%d, cmd=%d, timeout=%d)\n", cb_data.pid, command, pollingTimeout);
pret = poll(&pfd, 1, pollingTimeout); /* timeout 7sec */
debug_error("after poll");
if (pret < 0) {
- debug_error("[RETCB]poll failed (%d)\n", pret);
- goto fail;
+ debug_error("[RETCB] poll failed (%d)\n", pret);
+ goto RELEASE;
}
if (pfd.revents & POLLIN) {
if (read(fd_FOCUS_R, &ret, sizeof(ret)) == -1) {
- debug_error("fscanf error\n");
- goto fail;
+ char str_error[256];
+ strerror_r(errno, str_error, sizeof(str_error));
+ debug_error("[RETCB] failed to read (err:%s)\n", str_error);
+ goto RELEASE;
}
}
- g_free(filename2);
- filename2 = NULL;
-
/* Calculate endtime and display*/
gettimeofday(&time, NULL);
endtime = time.tv_sec * 1000000 + time.tv_usec;
- debug_error("[RETCB] FOCUS_CB_END cbtimelab=%3.3f(second), timeout=%d(milli second) (reciever=%d) Return value = (handle_id=%d)\n", ((endtime-starttime)/1000000.), pollingTimeout, cb_data.pid, ret);
+ debug_error("[RETCB] FOCUS_WATCH_CB_END cbtimelab=%3.3f(second), timeout=%d(milli second) (reciever=%d) Return value = (handle_id=%d)\n",
+ ((endtime-starttime)/1000000.), pollingTimeout, cb_data.pid, ret);
/**************************************
*
* Close callback result pipe
*
**************************************/
+RELEASE:
+ if (filename) {
+ g_free (filename);
+ filename = NULL;
+ }
+ if (filename2) {
+ g_free (filename2);
+ filename2 = NULL;
+ }
+ if (fd_FOCUS != -1) {
+ close(fd_FOCUS);
+ fd_FOCUS = -1;
+ }
if (fd_FOCUS_R != -1) {
close(fd_FOCUS_R);
fd_FOCUS_R = -1;
}
+
+ continue;
}
}
}
debug_fleave();
return MM_ERROR_NONE;
-
-fail:
- if (filename) {
- g_free (filename);
- filename = NULL;
- }
- if (filename2) {
- g_free (filename2);
- filename2 = NULL;
- }
- if (fd_FOCUS != -1) {
- close(fd_FOCUS);
- fd_FOCUS = -1;
- }
- if (fd_FOCUS_R != -1) {
- close (fd_FOCUS_R);
- fd_FOCUS_R = -1;
- }
- debug_fleave();
- return -1;
}
int _mm_sound_mgr_focus_do_callback(focus_command_e command, focus_node_t *victim_node, const _mm_sound_mgr_focus_param_t *assaulter_param, const char *assaulter_stream_type)
{
+ int res = MM_ERROR_NONE;
char *filename = NULL;
char *filename2 = NULL;
struct timeval time;
**************************************/
filename = __get_focus_pipe_path(cb_data.pid, cb_data.handle, NULL, false);
if ((fd_FOCUS = open(filename, O_WRONLY|O_NONBLOCK)) == -1) {
- debug_error("[CallCB] %s open error\n", filename);
- goto fail;
+ char str_error[256];
+ strerror_r(errno, str_error, sizeof(str_error));
+ debug_error("[CB] failed to open pipe (%s, err:%s)\n", filename, str_error);
+ res = -1;
+ goto RELEASE;
}
/******************************************
******************************************/
filename2 = __get_focus_pipe_path(cb_data.pid, cb_data.handle, "r", false);
if (filename2 == NULL) {
- debug_error("[RETCB] Fail to get return pipe");
- goto fail;
+ debug_error("[RETCB] failed to get return pipe");
+ res = -1;
+ goto RELEASE;
}
if ((fd_FOCUS_R = open(filename2,O_RDONLY|O_NONBLOCK)) == -1) {
char str_error[256];
- strerror_r (errno, str_error, sizeof(str_error));
- debug_error("[RETCB] Fail to open fifo (%s)\n", str_error);
- goto fail;
+ strerror_r(errno, str_error, sizeof(str_error));
+ debug_error("[RETCB] failed to open return pipe (%s, err:%s)\n", filename2, str_error);
+ res = -1;
+ goto RELEASE;
}
- debug_log(" open return cb %s\n", filename2);
-
/*******************************************
* Write Callback msg
*******************************************/
if (write(fd_FOCUS, &cb_data, sizeof(cb_data)) == -1) {
- debug_error("[CallCB] %s write error\n", filename);
- goto fail;
+ char str_error[256];
+ strerror_r(errno, str_error, sizeof(str_error));
+ debug_error("[CAllCB] failed to write (err:%s)\n", str_error);
+ res = -1;
+ goto RELEASE;
}
- /**************************************
- *
- * Close callback cmd pipe
- *
- **************************************/
- close(fd_FOCUS);
- fd_FOCUS = -1;
-
- g_free(filename);
- filename = NULL;
-
- pfd.fd = fd_FOCUS_R;
- pfd.events = POLLIN;
- pfd.revents = 0;
/*********************************************
*
* Wait callback result msg
*
********************************************/
- debug_error("[RETCB]wait callback(tid=%d, handle=%d, cmd=%d, timeout=%d)\n",cb_data.pid, cb_data.handle, command, pollingTimeout);
+ pfd.fd = fd_FOCUS_R;
+ pfd.events = POLLIN;
+ pfd.revents = 0;
+ debug_error("[RETCB] wait callback(tid=%d, handle=%d, cmd=%d, timeout=%d)\n",cb_data.pid, cb_data.handle, command, pollingTimeout);
pret = poll(&pfd, 1, pollingTimeout);
if (pret < 0) {
- debug_error("[RETCB]poll failed (%d)\n", pret);
- goto fail;
+ debug_error("[RETCB] poll failed (%d)\n", pret);
+ res = -1;
+ goto RELEASE;
}
if (pfd.revents & POLLIN) {
if (read(fd_FOCUS_R, &ret, sizeof(ret)) == -1) {
- debug_error("read error\n");
- goto fail;
+ char str_error[256];
+ strerror_r(errno, str_error, sizeof(str_error));
+ debug_error("[RETCB] failed to read (err:%s)\n", str_error);
+ res = -1;
+ goto RELEASE;
}
ret_handle = (int)(ret & 0x0000ffff);
victim_node->reacquisition= (bool)((ret >> 16) & 0xf);
}
- g_free(filename2);
- filename2 = NULL;
/* Calculate endtime and display*/
gettimeofday(&time, NULL);
endtime = time.tv_sec * 1000000 + time.tv_usec;
debug_error("[RETCB] FOCUS_CB_END cbtimelab=%3.3f(second), timeout=%d(milli second) (reciever=%d) Return value = (handle_id=%d)\n", ((endtime-starttime)/1000000.), pollingTimeout, cb_data.pid, ret);
- /**************************************
- *
- * Close callback result pipe
- *
- **************************************/
- if (fd_FOCUS_R != -1) {
- close(fd_FOCUS_R);
- fd_FOCUS_R = -1;
- }
- //debug_log("[RETCB] Return value 0x%x\n", buf);
-
/* update victim node */
if (command == FOCUS_COMMAND_RELEASE) {
taken_pid = assaulter_param->pid;
if (strncmp(assaulter_stream_type, victim_node->stream_type, MAX_STREAM_TYPE_LEN))
_mm_sound_mgr_focus_do_watch_callback((focus_type_e)assaulter_param->request_type, command, victim_node, assaulter_param);
-
- return MM_ERROR_NONE;
-
-fail:
+RELEASE:
if (filename) {
g_free (filename);
filename = NULL;
fd_FOCUS_R = -1;
}
- return -1;
+ return res;
}
static int _mm_sound_mgr_focus_list_dump ()
for (i = 0; i < AVAIL_STREAMS_MAX; i++) {
if (g_stream_list.stream_types[i]) {
- free (g_stream_list.stream_types[i]);
+ free(g_stream_list.stream_types[i]);
}
}