static GMainLoop *g_dcm_svc_mainloop;
-static void __dcm_svc_kill_service(void)
-{
- if (g_dcm_svc_mainloop) {
- dcm_warn("Shutting down DCM Service");
- g_main_loop_quit(g_dcm_svc_mainloop);
- }
-}
-
-static gboolean __dcm_service_recieve_request(GIOChannel *src, GIOCondition condition, gpointer data)
+static gboolean __dcm_service_recieve_request(GIOChannel *channel, GIOCondition condition, gpointer data)
{
dcmMsg recv_msg;
int sock = -1;
memset((void *)&recv_msg, 0, sizeof(recv_msg));
- sock = g_io_channel_unix_get_fd(src);
+ sock = g_io_channel_unix_get_fd(channel);
dcm_retvm_if(sock < 0, G_SOURCE_CONTINUE, "sock fd is invalid!");
/* Accept tcp client socket */
if (recv_msg.msg_type == DCM_MSG_REQUEST_KILL_SERVER) {
dcm_warn("Receive DCM_MSG_REQUEST_KILL_SERVER");
- __dcm_svc_kill_service();
+ dcm_ipc_close_socket(client_sock);
+ g_main_loop_quit(g_dcm_svc_mainloop);
- } else if (recv_msg.msg_type == DCM_MSG_REQUEST_MEDIA) {
+ return G_SOURCE_REMOVE;
+ }
+
+ if (recv_msg.msg_type == DCM_MSG_REQUEST_MEDIA) {
ret = dcm_scan_single(recv_msg.msg, recv_msg.uid, &face_count);
dcm_debug("Scan single result: ret[%d] face_count[%d]", ret, face_count);
if (ret == MS_MEDIA_ERR_NONE)
int main(int argc, char *argv[])
{
int sockfd = -1;
- GSource *source = NULL;
GIOChannel *channel = NULL;
- GMainContext *context = NULL;
/* Create and bind new socket to main_loop */
if (dcm_ipc_create_socket(&sockfd, DCM_IPC_PORT_DCM_RECV) != MS_MEDIA_ERR_NONE) {
return -1;
}
- g_dcm_svc_mainloop = g_main_loop_new(context, FALSE);
- context = g_main_loop_get_context(g_dcm_svc_mainloop);
+ g_dcm_svc_mainloop = g_main_loop_new(NULL, FALSE);
- /* Create new channel to watch new socket for main_loop */
+ /* Create new channel to watch tcp socket */
channel = g_io_channel_unix_new(sockfd);
- source = g_io_create_watch(channel, G_IO_IN);
-
- /* Set callback to be called when socket is readable */
- g_source_set_callback(source, (GSourceFunc)__dcm_service_recieve_request, NULL, NULL);
- g_source_attach(source, context);
+ g_io_add_watch(channel, G_IO_IN, __dcm_service_recieve_request, NULL);
+ g_io_channel_unref(channel);
if (dcm_face_detect_initialize() != MS_MEDIA_ERR_NONE)
dcm_error("Failed to dcm_face_detect_initialize");
g_main_loop_run(g_dcm_svc_mainloop);
dcm_info("DCM Service is shutting down");
-
- g_io_channel_shutdown(channel, FALSE, NULL);
- g_io_channel_unref(channel);
dcm_ipc_close_socket(sockfd);
g_main_loop_unref(g_dcm_svc_mainloop);
-
dcm_face_detect_finalize();
return 0;