00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "config.h"
00032
00033
00034 #include <stdio.h>
00035 #include <stdlib.h>
00036 #include <gdk/gdkx.h>
00037 #include <sys/types.h>
00038 #include <unistd.h>
00039
00040
00041 #include <liberipc/eripc.h>
00042
00043
00044 #include "log.h"
00045 #include "i18n.h"
00046 #include "ipc.h"
00047 #include "main.h"
00048 #include "menu.h"
00049
00050
00051
00052
00053
00054
00055 typedef struct
00056 {
00057 eripc_handler_t *handler;
00058 const gchar *message_name;
00059 const gchar *interface;
00060 gint handler_id;
00061 } functionEntry;
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 #define DBUS_APPL_NAME "helloworld" "settings" // lower-case and digits only
00072 #define DBUS_SERVICE "com.irexnet." DBUS_APPL_NAME
00073 #define DBUS_PATH "/com/irexnet/" DBUS_APPL_NAME
00074 #define DBUS_INTERFACE "com.irexnet." DBUS_APPL_NAME
00075
00076
00077 #define DBUS_SERVICE_SYSTEM_CONTROL "com.irexnet.sysd"
00078
00079
00080 #define DBUS_SERVICE_POPUP_MENU "com.irexnet.popupmenu"
00081
00082
00083
00084
00085
00086
00087 static eripc_context_t *eripcContext = NULL;
00088
00089
00090
00091
00092
00093
00094 static void on_menu_item ( eripc_context_t *context,
00095 const eripc_event_info_t *info,
00096 void *user_data );
00097
00098 static void on_window_activated ( eripc_context_t *context,
00099 const eripc_event_info_t *info,
00100 void *user_data );
00101
00102 static void on_window_deactivated( eripc_context_t *context,
00103 const eripc_event_info_t *info,
00104 void *user_data );
00105
00106 static void on_prepare_standby ( eripc_context_t *context,
00107 const eripc_event_info_t *info,
00108 void *user_data );
00109
00110 static void on_changed_locale ( eripc_context_t *context,
00111 const eripc_event_info_t *info,
00112 void *user_data );
00113
00114 static void on_changed_orientation(eripc_context_t *context,
00115 const eripc_event_info_t *info,
00116 void *user_data );
00117
00118
00119 static functionEntry service_functions[] =
00120 {
00121
00122 { on_menu_item, "menuItemActivated", NULL },
00123 { on_window_activated, "activatedWindow", NULL },
00124 { on_window_deactivated, "deactivatedWindow", NULL },
00125
00126 { on_prepare_standby, "sysPrepareStandby", DBUS_SERVICE_SYSTEM_CONTROL },
00127 { on_changed_locale, "sysChangedLocale", DBUS_SERVICE_SYSTEM_CONTROL },
00128 { on_changed_orientation, "sysChangedOrientation", DBUS_SERVICE_SYSTEM_CONTROL },
00129 { NULL }
00130 };
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 void ipc_set_services (void)
00144 {
00145 gint i;
00146 eripc_error_t retval;
00147
00148 LOGPRINTF("entry");
00149 g_assert(eripcContext == NULL);
00150
00151
00152 eripcContext = eripc_init(DBUS_APPL_NAME, "1.0", NULL);
00153 if (eripcContext == NULL)
00154 {
00155 ERRORPRINTF("Failed to initialize eripc context\n");
00156 exit(1);
00157 }
00158
00159
00160 for (i = 0 ; service_functions[i].handler != NULL ; i++)
00161 {
00162 if (service_functions[i].interface)
00163 {
00164
00165 retval = eripc_set_signal_handler( eripcContext,
00166 service_functions[i].handler,
00167 NULL,
00168 ERIPC_BUS_SESSION,
00169 service_functions[i].interface,
00170 service_functions[i].message_name,
00171 &(service_functions[i].handler_id) );
00172 if (retval != ERIPC_ERROR_SUCCESS)
00173 {
00174 ERRORPRINTF( "eripc_set_signal_handler [%s] returns [%d]",
00175 service_functions[i].message_name,
00176 retval );
00177 }
00178 }
00179 else
00180 {
00181
00182 retval = eripc_set_message_handler( eripcContext,
00183 service_functions[i].handler,
00184 NULL,
00185 ERIPC_BUS_SESSION,
00186 DBUS_INTERFACE,
00187 service_functions[i].message_name,
00188 &(service_functions[i].handler_id) );
00189
00190 if (retval != ERIPC_ERROR_SUCCESS)
00191 {
00192 ERRORPRINTF( "eripc_set_message_handler [%s] returns [%d]",
00193 service_functions[i].message_name,
00194 retval );
00195 }
00196 }
00197 }
00198 }
00199
00200
00201
00202 void ipc_unset_services (void)
00203 {
00204 gint i;
00205
00206 for (i = 0 ; service_functions[i].handler_id != 0 ; i++)
00207 {
00208 eripc_unset_handler(eripcContext, service_functions[i].handler_id);
00209 }
00210 }
00211
00212
00213
00214
00215
00216
00217
00218 void ipc_sys_startup_complete ( void )
00219 {
00220 eripc_error_t result;
00221
00222
00223 const int my_pid = getpid();
00224 const int my_xid = GDK_WINDOW_XID(g_main_window->window);
00225 const gboolean is_multidoc = FALSE;
00226
00227 LOGPRINTF("entry");
00228 g_assert( eripcContext );
00229
00230
00231 result = eripc_send_signal_varargs( eripcContext,
00232 ERIPC_BUS_SESSION,
00233 DBUS_PATH,
00234 DBUS_SERVICE_SYSTEM_CONTROL,
00235 "startupComplete",
00236 ERIPC_TYPE_STRING, DBUS_APPL_NAME,
00237 ERIPC_TYPE_INT, my_pid,
00238 ERIPC_TYPE_BOOL, is_multidoc,
00239 ERIPC_TYPE_STRING, DBUS_SERVICE,
00240 ERIPC_TYPE_INT, my_xid,
00241 ERIPC_TYPE_INVALID );
00242
00243 if (result != ERIPC_ERROR_SUCCESS)
00244 {
00245 ERRORPRINTF("eripc_send_varargs returns [%d]", result);
00246 }
00247 }
00248
00249
00250
00251
00252
00253
00254
00255 gboolean ipc_menu_add_menu( const char *name,
00256 const char *group1,
00257 const char *group2,
00258 const char *group3 )
00259 {
00260 gboolean ok = TRUE;
00261 eripc_error_t result;
00262
00263 LOGPRINTF( "entry: name [%s] groups [%s] [%s] [%s]",
00264 name, group1, group2, group3 );
00265 g_assert( eripcContext );
00266
00267 result = eripc_send_varargs( eripcContext,
00268 NULL,
00269 NULL,
00270 ERIPC_BUS_SESSION,
00271 DBUS_SERVICE_POPUP_MENU,
00272 "addMenu",
00273 ERIPC_TYPE_STRING, name,
00274 ERIPC_TYPE_STRING, "",
00275 ERIPC_TYPE_STRING, DBUS_SERVICE,
00276 ERIPC_TYPE_STRING, group1,
00277 ERIPC_TYPE_STRING, group2,
00278 ERIPC_TYPE_STRING, group3,
00279 ERIPC_TYPE_STRING, "",
00280 ERIPC_TYPE_INVALID );
00281
00282 if (result != ERIPC_ERROR_SUCCESS)
00283 {
00284 ERRORPRINTF("eripc_send_varargs returns [%d]", result);
00285 ok = FALSE;
00286 }
00287
00288 return ok;
00289 }
00290
00291
00292
00293 gboolean ipc_menu_add_group( const char *name,
00294 const char *parent,
00295 const char *image )
00296 {
00297 gboolean ok = TRUE;
00298 eripc_error_t result;
00299
00300 LOGPRINTF( "entry: name [%s] parent [%s] image [%s]",
00301 name, parent, image );
00302 g_assert( eripcContext );
00303
00304 result = eripc_send_varargs( eripcContext,
00305 NULL,
00306 NULL,
00307 ERIPC_BUS_SESSION,
00308 DBUS_SERVICE_POPUP_MENU,
00309 "addGroup",
00310 ERIPC_TYPE_STRING, name,
00311 ERIPC_TYPE_STRING, parent,
00312 ERIPC_TYPE_STRING, "",
00313 ERIPC_TYPE_STRING, image,
00314 ERIPC_TYPE_INVALID );
00315
00316 if (result != ERIPC_ERROR_SUCCESS)
00317 {
00318 ERRORPRINTF("eripc_send_varargs returns [%d]", result);
00319 ok = FALSE;
00320 }
00321
00322 return ok;
00323 }
00324
00325
00326
00327 gboolean ipc_menu_add_item( const char *name,
00328 const char *parent,
00329 const char *image )
00330 {
00331 gboolean ok = TRUE;
00332 eripc_error_t result;
00333
00334 LOGPRINTF( "entry: name [%s] parent [%s] image [%s]",
00335 name, parent, image );
00336 g_assert( eripcContext );
00337
00338 result = eripc_send_varargs( eripcContext,
00339 NULL,
00340 NULL,
00341 ERIPC_BUS_SESSION,
00342 DBUS_SERVICE_POPUP_MENU,
00343 "addItem",
00344 ERIPC_TYPE_STRING, name,
00345 ERIPC_TYPE_STRING, parent,
00346 ERIPC_TYPE_STRING, "",
00347 ERIPC_TYPE_STRING, image,
00348 ERIPC_TYPE_INVALID);
00349
00350 if (result != ERIPC_ERROR_SUCCESS)
00351 {
00352 ERRORPRINTF("eripc_send_varargs returns [%d]", result);
00353 ok = FALSE;
00354 }
00355
00356 return ok;
00357 }
00358
00359
00360
00361 gboolean ipc_menu_set_menu_label ( const char *name,
00362 const char *label )
00363 {
00364 gboolean ok = TRUE;
00365 eripc_error_t result;
00366
00367 LOGPRINTF( "entry: name [%s] label [%s]", name, label );
00368 g_assert( eripcContext );
00369
00370 result = eripc_send_varargs( eripcContext,
00371 NULL,
00372 NULL,
00373 ERIPC_BUS_SESSION,
00374 DBUS_SERVICE_POPUP_MENU,
00375 "setMenuLabel",
00376 ERIPC_TYPE_STRING, name,
00377 ERIPC_TYPE_STRING, label,
00378 ERIPC_TYPE_INVALID );
00379
00380 if (result != ERIPC_ERROR_SUCCESS)
00381 {
00382 ERRORPRINTF("eripc_send_varargs returns [%d]", result);
00383 ok = FALSE;
00384 }
00385
00386 return ok;
00387 }
00388
00389
00390
00391 gboolean ipc_menu_set_group_label ( const char *name,
00392 const char *label )
00393 {
00394 gboolean ok = TRUE;
00395 eripc_error_t result;
00396
00397 LOGPRINTF( "entry: name [%s] label [%s]", name, label );
00398 g_assert( eripcContext );
00399
00400 result = eripc_send_varargs( eripcContext,
00401 NULL,
00402 NULL,
00403 ERIPC_BUS_SESSION,
00404 DBUS_SERVICE_POPUP_MENU,
00405 "setGroupLabel",
00406 ERIPC_TYPE_STRING, name,
00407 ERIPC_TYPE_STRING, label,
00408 ERIPC_TYPE_INVALID );
00409
00410 if (result != ERIPC_ERROR_SUCCESS)
00411 {
00412 ERRORPRINTF("eripc_send_varargs returns [%d]", result);
00413 ok = FALSE;
00414 }
00415
00416 return ok;
00417 }
00418
00419
00420
00421 gboolean ipc_menu_set_item_label ( const char *name,
00422 const char *parent,
00423 const char *label )
00424 {
00425 gboolean ok = TRUE;
00426 eripc_error_t result;
00427
00428 LOGPRINTF( "entry: name [%s] parent [%s] label [%s]", name, parent, label );
00429 g_assert( eripcContext );
00430
00431 result = eripc_send_varargs( eripcContext,
00432 NULL,
00433 NULL,
00434 ERIPC_BUS_SESSION,
00435 DBUS_SERVICE_POPUP_MENU,
00436 "setItemLabel",
00437 ERIPC_TYPE_STRING, name,
00438 ERIPC_TYPE_STRING, parent,
00439 ERIPC_TYPE_STRING, label,
00440 ERIPC_TYPE_INVALID );
00441
00442 if (result != ERIPC_ERROR_SUCCESS)
00443 {
00444 ERRORPRINTF("eripc_send_varargs returns [%d]", result);
00445 ok = FALSE;
00446 }
00447
00448 return ok;
00449 }
00450
00451
00452
00453 gboolean ipc_menu_show_menu( const char *name )
00454 {
00455 gboolean ok = TRUE;
00456 eripc_error_t result;
00457
00458 LOGPRINTF( "entry: name [%s]", name );
00459 g_assert( eripcContext );
00460
00461 result = eripc_send_varargs( eripcContext,
00462 NULL,
00463 NULL,
00464 ERIPC_BUS_SESSION,
00465 DBUS_SERVICE_POPUP_MENU,
00466 "showMenu",
00467 ERIPC_TYPE_STRING, name,
00468 ERIPC_TYPE_INVALID );
00469
00470 if (result != ERIPC_ERROR_SUCCESS)
00471 {
00472 ERRORPRINTF("eripc_send_varargs returns [%d]", result);
00473 ok = FALSE;
00474 }
00475
00476 return ok;
00477 }
00478
00479
00480
00481 gboolean ipc_remove_menu( const char *name )
00482 {
00483 gboolean ok = TRUE;
00484 eripc_error_t result;
00485
00486 LOGPRINTF( "entry: name [%s]", name );
00487 g_assert( eripcContext );
00488
00489 result = eripc_send_varargs( eripcContext,
00490 NULL,
00491 NULL,
00492 ERIPC_BUS_SESSION,
00493 DBUS_SERVICE_POPUP_MENU,
00494 "removeMenu",
00495 ERIPC_TYPE_STRING, name,
00496 ERIPC_TYPE_INVALID );
00497
00498 if (result != ERIPC_ERROR_SUCCESS)
00499 {
00500 ERRORPRINTF("eripc_send_varargs returns [%d]", result);
00501 ok = FALSE;
00502 }
00503
00504 return ok;
00505 }
00506
00507
00508
00509 gboolean ipc_menu_set_group_state( const char *name,
00510 const char *state )
00511 {
00512 gboolean ok = TRUE;
00513 eripc_error_t result;
00514
00515 LOGPRINTF( "entry: name [%s] state [%s]", name, state );
00516 g_assert( eripcContext );
00517
00518 result = eripc_send_varargs( eripcContext,
00519 NULL,
00520 NULL,
00521 ERIPC_BUS_SESSION,
00522 DBUS_SERVICE_POPUP_MENU,
00523 "setGroupState",
00524 ERIPC_TYPE_STRING, name,
00525 ERIPC_TYPE_STRING, state,
00526 ERIPC_TYPE_INVALID );
00527
00528 if (result != ERIPC_ERROR_SUCCESS)
00529 {
00530 ERRORPRINTF("eripc_send_varargs returns [%d]", result);
00531 ok = FALSE;
00532 }
00533
00534 return ok;
00535 }
00536
00537
00538
00539 gboolean ipc_menu_set_item_state( const char *name,
00540 const char *parent,
00541 const char *state )
00542 {
00543 gboolean ok = TRUE;
00544 eripc_error_t result;
00545
00546 LOGPRINTF( "entry: name [%s] parent [%s] state [%s]", name, parent, state );
00547 g_assert( eripcContext );
00548
00549 result = eripc_send_varargs( eripcContext,
00550 NULL,
00551 NULL,
00552 ERIPC_BUS_SESSION,
00553 DBUS_SERVICE_POPUP_MENU,
00554 "setItemState",
00555 ERIPC_TYPE_STRING, name,
00556 ERIPC_TYPE_STRING, parent,
00557 ERIPC_TYPE_STRING, state,
00558 ERIPC_TYPE_INVALID );
00559
00560 if (result != ERIPC_ERROR_SUCCESS)
00561 {
00562 ERRORPRINTF("eripc_send_varargs returns [%d]", result);
00563 ok = FALSE;
00564 }
00565
00566 return ok;
00567 }
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582 static void on_menu_item ( eripc_context_t *context,
00583 const eripc_event_info_t *info,
00584 void *user_data )
00585 {
00586 LOGPRINTF("entry");
00587 const eripc_arg_t *arg_array = info->args;
00588
00589 if ((arg_array[0].type == ERIPC_TYPE_STRING) &&
00590 (arg_array[1].type == ERIPC_TYPE_STRING) &&
00591 (arg_array[2].type == ERIPC_TYPE_STRING) &&
00592 (arg_array[3].type == ERIPC_TYPE_STRING))
00593 {
00594 const char *item = arg_array[0].value.s;
00595 const char *group = arg_array[1].value.s;
00596 const char *menu = arg_array[2].value.s;
00597 const char *state = arg_array[3].value.s;
00598
00599 if (item && group && menu && state)
00600 {
00601 menu_on_item_activated( item, group, menu, state );
00602 }
00603 }
00604 }
00605
00606
00607
00608
00609
00610
00611
00612 static void on_window_activated( eripc_context_t *context,
00613 const eripc_event_info_t *info,
00614 void *user_data )
00615 {
00616 LOGPRINTF("entry");
00617 gboolean result = FALSE;
00618 const eripc_arg_t *arg_array = info->args;
00619
00620 if (arg_array[0].type == ERIPC_TYPE_INT)
00621 {
00622
00623
00624 menu_show();
00625
00626 result = TRUE;
00627 }
00628
00629
00630 eripc_reply_bool(context, info->message_id, result);
00631 }
00632
00633
00634
00635
00636
00637
00638 static void on_window_deactivated( eripc_context_t *context,
00639 const eripc_event_info_t *info,
00640 void *user_data )
00641 {
00642 LOGPRINTF("entry");
00643 gboolean result = FALSE;
00644 const eripc_arg_t *arg_array = info->args;
00645
00646 if (arg_array[0].type == ERIPC_TYPE_INT)
00647 {
00648
00649
00650 result = TRUE;
00651 }
00652
00653
00654 eripc_reply_bool(context, info->message_id, result);
00655 }
00656
00657
00658
00659
00660
00661
00662
00663 static void on_prepare_standby ( eripc_context_t *context,
00664 const eripc_event_info_t *info,
00665 void *user_data )
00666 {
00667 LOGPRINTF("entry");
00668
00669
00670 }
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680 static void on_changed_locale ( eripc_context_t *context,
00681 const eripc_event_info_t *info,
00682 void *user_data )
00683 {
00684 LOGPRINTF("entry");
00685 const eripc_arg_t *arg_array = info->args;
00686
00687 if (arg_array[0].type == ERIPC_TYPE_STRING)
00688 {
00689 const char *locale = arg_array[0].value.s;
00690 if (locale)
00691 {
00692 const char *old_locale = g_getenv("LANG");
00693 if (!old_locale || (strcmp(old_locale, locale) != 0))
00694 {
00695 main_set_locale(locale);
00696 }
00697 }
00698 }
00699 }
00700
00701
00702
00703
00704
00705
00706
00707 static void on_changed_orientation ( eripc_context_t *context,
00708 const eripc_event_info_t *info,
00709 void *user_data )
00710 {
00711 LOGPRINTF("entry");
00712 const eripc_arg_t *arg_array = info->args;
00713
00714 if (arg_array[0].type == ERIPC_TYPE_STRING)
00715 {
00716 const char *orientation = arg_array[0].value.s;
00717 if (orientation)
00718 {
00719
00720 }
00721 }
00722 }