Remove Ecore evas dependency
[platform/core/multimedia/libmedia-thumbnail.git] / server / thumb-server.c
1 /*
2  * media-thumbnail-server
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Hyunjun Ko <zzoon.ko@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 #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"
27
28 #include <pthread.h>
29 #include <heynoti.h>
30 #include <vconf.h>
31 //#include <signal.h>
32 //#include <glib-unix.h>
33
34
35 #ifdef LOG_TAG
36 #undef LOG_TAG
37 #endif
38
39 #define LOG_TAG "MEDIA_THUMBNAIL_SERVER"
40 #define POWEROFF_NOTI_NAME "power_off_start" /*poeroff noti from system-server*/
41
42
43 extern GMainLoop *g_thumb_server_mainloop;
44
45 static void _media_thumb_signal_handler(void *user_data)
46 {
47         thumb_dbg("Singal Hander for HEYNOTI \"power_off_start\"");
48
49         if (g_thumb_server_mainloop)
50                 g_main_loop_quit(g_thumb_server_mainloop);
51         else
52                 exit(1);
53
54         return;
55 }
56
57 int main()
58 {
59         
60         int sockfd = -1;
61
62     GSource *source = NULL;
63         GIOChannel *channel = NULL;
64         GMainContext *context = NULL;
65
66         /*heynoti for power off*/
67         int err = 0;
68         int heynoti_id = heynoti_init();
69
70         if (heynoti_id < 0) {
71                 thumb_err("heynoti_init failed");
72         } else {
73                 err = heynoti_subscribe(heynoti_id, POWEROFF_NOTI_NAME, _media_thumb_signal_handler, NULL);
74                 if (err < 0) {
75                         thumb_err("heynoti_attach_handler failed: %d", err);
76                 } else {
77                         err = heynoti_attach_handler(heynoti_id);
78                         if (err < 0)
79                                 thumb_err("heynoti_attach_handler failed: %d", err);
80                 }
81         }
82
83         /* Set VCONFKEY_SYSMAN_MMC_FORMAT callback to get noti for SD card format */
84         err = vconf_notify_key_changed(VCONFKEY_SYSMAN_MMC_FORMAT, (vconf_callback_fn) _thumb_daemon_vconf_cb, NULL);
85         if (err == -1)
86                 thumb_err("vconf_notify_key_changed : %s fails", VCONFKEY_SYSMAN_MMC_FORMAT);
87
88         /* Set VCONFKEY_SYSMAN_MMC_STATUS callback to get noti when SD card is ejected */
89         err = vconf_notify_key_changed(VCONFKEY_SYSMAN_MMC_STATUS, (vconf_callback_fn) _thumb_daemon_mmc_eject_vconf_cb, NULL);
90         if (err == -1)
91                 thumb_err("vconf_notify_key_changed : %s fails", VCONFKEY_SYSMAN_MMC_STATUS);
92
93         /* Create and bind new UDP socket */
94         if (!_thumb_server_prepare_socket(&sockfd)) {
95                 thumb_err("Failed to create socket\n");
96                 return -1;
97         }
98
99         g_thumb_server_mainloop = g_main_loop_new(context, FALSE);
100         
101         /* Create new channel to watch udp socket */
102         channel = g_io_channel_unix_new(sockfd);
103         source = g_io_create_watch(channel, G_IO_IN);
104
105         /* Set callback to be called when socket is readable */
106         g_source_set_callback(source, (GSourceFunc)_thumb_server_read_socket, NULL, NULL);
107         g_source_attach(source, context);
108
109         GSource *source_init = NULL;
110         source_init = g_idle_source_new ();
111         g_source_set_callback (source_init, _thumb_daemon_start_jobs, NULL, NULL);
112         g_source_attach (source_init, context);
113
114 /*      Would be used when glib 2.32 is installed
115         GSource *sig_handler_src = NULL;
116         sig_handler_src = g_unix_signal_source_new (SIGTERM);
117         g_source_set_callback(sig_handler_src, (GSourceFunc)_media_thumb_signal_handler, NULL, NULL);
118         g_source_attach(sig_handler_src, context);
119 */
120
121         thumb_dbg("************************************");
122         thumb_dbg("*** Thumbnail server is running ***");
123         thumb_dbg("************************************");
124
125         g_main_loop_run(g_thumb_server_mainloop);
126         
127         thumb_dbg("Thumbnail server is shutting down...");
128
129         g_io_channel_shutdown(channel,  FALSE, NULL);
130         g_io_channel_unref(channel);
131         _thumb_daemon_finish_jobs();
132
133         return 0;
134 }