2 * media-thumbnail-server
4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include "media-thumbnail.h"
23 #include "media-thumb-debug.h"
24 #include "media-thumb-ipc.h"
25 #include "media-thumb-util.h"
26 #include "thumb-server-internal.h"
35 #define LOG_TAG "MEDIA_THUMBNAIL_SERVER"
36 #define POWEROFF_NOTI_NAME "power_off_start" /*poeroff noti from system-server*/
38 extern GMainLoop *g_thumb_server_mainloop;
40 static void _media_thumb_signal_handler(void *user_data)
42 thumb_dbg("Singal Hander for HEYNOTI \"power_off_start\"");
44 if (g_thumb_server_mainloop)
45 g_main_loop_quit(g_thumb_server_mainloop);
56 GSource *source = NULL;
57 GIOChannel *channel = NULL;
58 GMainContext *context = NULL;
60 /*heynoti for power off*/
62 int heynoti_id = heynoti_init();
65 thumb_err("heynoti_init failed");
67 err = heynoti_subscribe(heynoti_id, POWEROFF_NOTI_NAME, _media_thumb_signal_handler, NULL);
69 thumb_err("heynoti_attach_handler failed: %d", err);
71 err = heynoti_attach_handler(heynoti_id);
73 thumb_err("heynoti_attach_handler failed: %d", err);
77 /* Set VCONFKEY_SYSMAN_MMC_FORMAT callback to get noti for SD card format */
78 err = vconf_notify_key_changed(VCONFKEY_SYSMAN_MMC_FORMAT, (vconf_callback_fn) _thumb_daemon_vconf_cb, NULL);
80 thumb_err("vconf_notify_key_changed : %s fails", VCONFKEY_SYSMAN_MMC_FORMAT);
82 /* Set VCONFKEY_SYSMAN_MMC_STATUS callback to get noti when SD card is ejected */
83 err = vconf_notify_key_changed(VCONFKEY_SYSMAN_MMC_STATUS, (vconf_callback_fn) _thumb_daemon_mmc_eject_vconf_cb, NULL);
85 thumb_err("vconf_notify_key_changed : %s fails", VCONFKEY_SYSMAN_MMC_STATUS);
87 /* Create and bind new UDP socket */
88 if (!_thumb_server_prepare_socket(&sockfd)) {
89 thumb_err("Failed to create socket");
93 g_thumb_server_mainloop = g_main_loop_new(context, FALSE);
95 /* Create new channel to watch udp socket */
96 channel = g_io_channel_unix_new(sockfd);
97 source = g_io_create_watch(channel, G_IO_IN);
99 /* Set callback to be called when socket is readable */
100 g_source_set_callback(source, (GSourceFunc)_thumb_server_read_socket, NULL, NULL);
101 g_source_attach(source, context);
103 GSource *source_init = NULL;
104 source_init = g_idle_source_new ();
105 g_source_set_callback (source_init, _thumb_daemon_start_jobs, NULL, NULL);
106 g_source_attach (source_init, context);
108 /* Would be used when glib 2.32 is installed
109 GSource *sig_handler_src = NULL;
110 sig_handler_src = g_unix_signal_source_new (SIGTERM);
111 g_source_set_callback(sig_handler_src, (GSourceFunc)_media_thumb_signal_handler, NULL, NULL);
112 g_source_attach(sig_handler_src, context);
114 thumb_dbg("************************************");
115 thumb_dbg("*** Thumbnail server is running ***");
116 thumb_dbg("************************************");
118 g_main_loop_run(g_thumb_server_mainloop);
120 thumb_dbg("Thumbnail server is shutting down...");
121 g_io_channel_shutdown(channel, FALSE, NULL);
122 g_io_channel_unref(channel);
123 _thumb_daemon_finish_jobs();