3 #include <Elementary.h>
4 #include <appcore-efl.h>
7 #define TRACE(fmt, arg...) \
9 printf("\n[SETTING]\033[0;32m" fmt "\033[0m\t%s:%d\n", \
10 ##arg, (char*)(strrchr(__FILE__, '/')+1), __LINE__);\
14 #define MAX_LOCAL_BUFSIZE 128
15 #define DBUS_PATH "/setting/dbus_handler"
16 #define DBUS_SIGNAL_INTERFACE "org.tizen.setting.signal"
17 #define DBUS_SIGNAL "test"
21 #define PACKAGE "com.samsung.dbus_server"
26 Evas_Object *win_main;
28 Evas_Object *layout_main;
36 static DBusConnection *bus;
38 static DBusHandlerResult __dubs_msg_cb(DBusConnection* conn, DBusMessage* message, void* user_data)
40 int my_pid = getpid();
47 dbus_error_init(&error);
49 if (dbus_message_is_signal(message, DBUS_SIGNAL_INTERFACE, DBUS_SIGNAL))
51 if (dbus_message_get_args(message, &error,
52 DBUS_TYPE_UINT32, &sender_pid,
53 DBUS_TYPE_STRING, &key,
54 DBUS_TYPE_STRING, &value,
55 DBUS_TYPE_INVALID) == FALSE)
57 TRACE("Fail to get data : %s", error.message);
58 dbus_error_free(&error);
59 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
63 if (sender_pid != 0 && my_pid != sender_pid)
65 //TRACE("[SERVER] received key : %s , value : %s ", key, value);
66 if (key && '\0' != key[0] && value && '\0' != value[0] )
73 if (p && '\0' != p[0])
80 //TRACE("[SERVER] title[%s], id[%s]", title, id);
83 p = strchr(value, '|');
84 if (p && '\0' != p[0])
89 if (type && 0 == strcmp("INT", type))
92 TRACE("[SERVER] The value of \"%s\"(its JasonID is %s) had changed to be :%d",
98 TRACE("[SERVER] The value of \"%s\"(its JasonID is %s) had changed to be :%s",
106 return DBUS_HANDLER_RESULT_HANDLED;
109 int __dbus_msg_listen(void)
112 char rule[MAX_LOCAL_BUFSIZE];
114 dbus_error_init(&error);
115 bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
118 TRACE("[SERVER] Fail to connect to the D-BUS daemon: %s ", error.message);
119 dbus_error_free(&error);
123 dbus_connection_setup_with_g_main(bus, NULL);
124 snprintf(rule, MAX_LOCAL_BUFSIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH, DBUS_SIGNAL_INTERFACE);
126 dbus_bus_add_match(bus, rule, &error);
127 if (dbus_error_is_set(&error))
129 TRACE("[SERVER] Fail to rule set; %s ", error.message);
130 dbus_error_free(&error);
134 if (dbus_connection_add_filter(bus, __dubs_msg_cb, NULL, NULL) == FALSE)
139 TRACE("[SERVER] app signal initialized ");
145 int __dbus_msg_unlisten(void)
148 char rule[MAX_LOCAL_BUFSIZE];
150 dbus_error_init(&error);
151 dbus_connection_remove_filter(bus, __dubs_msg_cb, NULL);
152 snprintf(rule, MAX_LOCAL_BUFSIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH, DBUS_SIGNAL_INTERFACE);
153 dbus_bus_remove_match(bus, rule, &error);
155 if (dbus_error_is_set(&error))
157 TRACE("Fail to rule unset: %s ", error.message);
158 dbus_error_free(&error);
162 dbus_connection_close(bus);
163 TRACE("[SERVER] app signal finalized");
168 static void _quit_cb(void *data, Evas_Object* obj, void* event_info)
170 Evas_Object *win = (Evas_Object *) data;
174 static Eina_Bool _keydown_event(void *data, int type, void *event)
176 Ecore_Event_Key *ev = event;
178 if (!strcmp(ev->keyname, "XF86Stop")) {
185 static Evas_Object* create_win(const char *name)
190 eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
191 if (!eo) return NULL;
193 elm_win_title_set(eo, name);
194 elm_win_borderless_set(eo, EINA_TRUE);
195 elm_win_autodel_set(eo, EINA_TRUE);
196 evas_object_smart_callback_add(eo, "delete,request", _quit_cb, NULL);
197 ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
198 evas_object_resize(eo, w, h);
203 static Evas_Object* _create_bg(Evas_Object *parent)
207 bg = elm_bg_add(parent);
208 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
209 //elm_win_resize_object_add(parent, bg);
210 evas_object_show(bg);
215 static Evas_Object* _create_layout_main(Evas_Object* parent)
219 layout = elm_layout_add(parent);
221 elm_layout_theme_set(layout, "layout", "application", "default");
222 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
223 //elm_win_resize_object_add(parent, layout);
225 evas_object_show(layout);
230 static Evas_Object* _create_naviframe_layout(Evas_Object* parent)
234 navi = elm_naviframe_add(parent);
235 elm_object_part_content_set(parent, "elm.swallow.content", navi);
237 evas_object_show(navi);
243 void list_item_touch_handler_exit(void* data, Evas_Object* obj, void* event_info)
248 static Evas_Object* _create_list_winset(Evas_Object* parent, struct appdata* ad)
252 //struct _menu_item *menu_its;
254 li = elm_list_add(parent);
255 elm_list_mode_set(li, ELM_LIST_COMPRESS);
257 elm_list_item_append( li, "QUIT", NULL, NULL, list_item_touch_handler_exit, ad);
263 static void _create_view_layout(struct appdata *ad)
268 list = _create_list_winset(ad->win_main, ad);
269 btn = elm_button_add(ad->navi);
270 elm_object_style_set(btn, "naviframe/end_btn/default");
271 evas_object_smart_callback_add(btn, "clicked", _quit_cb, ad->win_main);
272 elm_naviframe_item_push(ad->navi, _("Tizen UI - Server"), btn, NULL, list, NULL);
277 static void _mouse_down_cb(void *data, Evas *evas, Evas_Object *obj, void *event_info)
279 //struct appdata *ad = (struct appdata *)data;
280 //Evas_Event_Mouse_Down *ev = event_info;
284 static void _mouse_up_cb(void *data, Evas *evas, Evas_Object *obj, void *event_info)
286 //struct appdata *ad = (struct appdata *)data;
290 static void _mouse_move_cb(void *data, Evas *evas, Evas_Object *obj, void *event_info)
292 //struct appdata *ad = (struct appdata *)data;
295 static void _window_resize_cb(void *data, Evas * e, Evas_Object * obj, void *event_info)
297 struct appdata *ad = (struct appdata *)data;
298 evas_object_geometry_get(ad->win_main, NULL, NULL, &ad->root_w, &ad->root_h);
302 static int _rotation_cb(enum appcore_rm mode, void *data)
304 struct appdata *ad = (struct appdata *)data;
308 case APPCORE_RM_LANDSCAPE_NORMAL:
312 case APPCORE_RM_LANDSCAPE_REVERSE:
316 case APPCORE_RM_PORTRAIT_REVERSE:
320 case APPCORE_RM_UNKNOWN:
321 case APPCORE_RM_PORTRAIT_NORMAL:
327 elm_win_rotation_with_resize_set(ad->win_main, angle);
328 // set_rotation_degree(angle);
330 // This is need for customized rotation process.
331 // rotate_for_winset(mode);
337 int app_create(void *data)
339 struct appdata *ad = (struct appdata *) data;
341 // Set the engine to opengl_x11
342 //elm_config_engine_set("opengl_x11");
344 ad->win_main = create_win(PACKAGE);
346 evas_object_event_callback_add(ad->win_main, EVAS_CALLBACK_RESIZE, _window_resize_cb, ad);
347 evas_object_show(ad->win_main);
348 ad->evas = evas_object_evas_get(ad->win_main);
349 // appcore_set_rotation_cb(_rotation_cb, ad);
351 // set_edj_name(NULL);
353 ad->bg = _create_bg(ad->win_main);
354 ad->layout_main = _create_layout_main(ad->win_main);
355 elm_win_indicator_mode_set(ad->win_main, ELM_WIN_INDICATOR_SHOW);
357 ad->navi = _create_naviframe_layout(ad->layout_main);
359 _create_view_layout(ad);
361 evas_object_event_callback_add(ad->navi, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down_cb, ad);
362 evas_object_event_callback_add(ad->navi, EVAS_CALLBACK_MOUSE_UP, _mouse_up_cb, ad);
363 evas_object_event_callback_add(ad->navi, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move_cb, ad);
365 ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, _keydown_event, NULL);
373 int app_terminate(void *data)
375 //struct appdata *ad = data;
378 __dbus_msg_unlisten();
382 int app_pause(void *data)
384 //struct appdata *ad = data;
389 int app_resume(void *data)
391 //struct appdata *ad = data;
396 int app_reset(service_h service, void* data)
398 struct appdata* ad = data;
401 elm_win_activate(ad->win_main);
407 int main(int argc, char* argv[])
411 struct appcore_ops ops = {
412 .create = app_create,
413 .terminate = app_terminate,
415 .resume = app_resume,
421 return appcore_efl_main(PACKAGE, &argc, &argv, &ops);