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
00032 #include <sys/stat.h>
00033 #include <unistd.h>
00034 #include <gtk/gtk.h>
00035
00036
00037 #include <liberipc/eripc.h>
00038 #include <liberipc/eripc_support.h>
00039
00040
00041 #include "log.h"
00042 #include "i18n.h"
00043 #include "ipc.h"
00044 #include "settings.h"
00045 #include "sd_settings.h"
00046 #include "reset.h"
00047 #include "datetime.h"
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 #define DBUS_APPL_NAME PACKAGE_NAME
00059 #define DBUS_SERVICE "com.irexnet."DBUS_APPL_NAME
00060 #define DBUS_PATH "/com/irexnet/"DBUS_APPL_NAME
00061 #define DBUS_INTERFACE "com.irexnet."DBUS_APPL_NAME
00062
00063
00064 #define DBUS_SERVICE_SYSD "com.irexnet.sysd"
00065 #define DBUS_SERVICE_CTB "com.irexnet.ctb"
00066
00067
00068
00069
00070
00071
00072
00073 static eripc_client_context_t *eripcClient = NULL;
00074 static gboolean g_menu_blocked = FALSE;
00075
00076
00077
00078
00079
00080
00081 extern void main_quit();
00082
00083 static void on_mounted ( eripc_context_t *context,
00084 const eripc_event_info_t *info,
00085 void *user_data );
00086
00087 static void on_unmounted ( eripc_context_t *context,
00088 const eripc_event_info_t *info,
00089 void *user_data );
00090
00091 static void on_changed_locale ( eripc_context_t *context,
00092 const eripc_event_info_t *info,
00093 void *user_data );
00094
00095 static void on_window_activated ( eripc_context_t *context,
00096 const eripc_event_info_t *info,
00097 void *user_data );
00098
00099 static void on_window_deactivated ( eripc_context_t *context,
00100 const eripc_event_info_t *info,
00101 void *user_data );
00102
00103 static void on_changed_orientation ( eripc_context_t *context,
00104 const eripc_event_info_t *info,
00105 void *user_data );
00106
00107 static gboolean ipc_menu_add_menu(const char *name,
00108 const char *label,
00109 const char *group1,
00110 const char *group2,
00111 const char *group3,
00112 const char *group4);
00113
00114
00115 static eripc_callback_function_t
00116 service_functions[] = {
00117 { on_window_activated, "activatedWindow", NULL, 0 },
00118 { on_window_deactivated,"deactivatedWindow", NULL, 0 },
00119 { on_mounted, "sysVolumeMounted", NULL, 0 },
00120 { on_mounted, "sysVolumeMounted", DBUS_SERVICE_SYSD, 0 },
00121 { on_unmounted, "sysVolumeUnmounted", DBUS_SERVICE_SYSD, 0 },
00122 { on_changed_locale, "sysChangedLocale", DBUS_SERVICE_SYSD, 0 },
00123 { on_changed_orientation, "sysChangedOrientation", DBUS_SERVICE_SYSD, 0 },
00124 { NULL, NULL, NULL, 0 }
00125 };
00126
00127
00128
00129
00130
00131
00132 gboolean ipc_set_services()
00133 {
00134 eripcClient = eripc_client_context_new(
00135 DBUS_APPL_NAME,
00136 "1.0",
00137 DBUS_SERVICE,
00138 DBUS_PATH,
00139 DBUS_INTERFACE,
00140 service_functions);
00141
00142 return TRUE;
00143 }
00144
00145
00146 void ipc_unset_services()
00147 {
00148 eripc_client_context_free(eripcClient, service_functions);
00149 }
00150
00151
00152 void ipc_sys_startup_complete (int xid)
00153 {
00154 eripc_sysd_startup_complete( eripcClient, getpid(), FALSE, xid);
00155 }
00156
00157
00158 gboolean ipc_menu_show_menu( const char *name )
00159 {
00160 return eripc_menu_show_menu(eripcClient, name);
00161 }
00162
00163
00164 gboolean ipc_remove_menu( const char *name )
00165 {
00166 return eripc_menu_remove_menu(eripcClient, name);
00167 }
00168
00169
00170 gboolean ipc_menu_popup(const char* state)
00171 {
00172 return eripc_sysd_set_menu_state(eripcClient, state);
00173 }
00174
00175
00176 gboolean ipc_sys_busy( gboolean look_busy )
00177 {
00178 if (look_busy)
00179 return eripc_sysd_set_busy(eripcClient, "delaydialog", NULL);
00180 else
00181 return eripc_sysd_reset_busy(eripcClient);
00182 }
00183
00184
00185 gboolean ipc_set_stylus(const char* state)
00186 {
00187 g_return_val_if_fail( (state != NULL), FALSE);
00188 return eripc_menu_set_statusitem_state(eripcClient, "statusbar_stylus", state);
00189 }
00190
00191
00192 void menu_init()
00193 {
00194 LOGPRINTF("entry");
00195
00196 ipc_menu_add_menu(SETTINGS_MENU, _("Menu"), NULL, NULL, NULL, NULL);
00197
00198 ipc_menu_show_menu(SETTINGS_MENU);
00199 }
00200
00201
00202 gboolean get_device_capabilities(gboolean* has_stylus,
00203 gboolean* has_wifi,
00204 gboolean* has_bluetooth,
00205 gboolean* has_3g)
00206 {
00207 eripc_device_caps_t er_dev_caps;
00208
00209 eripc_sysd_get_device_capabilities( eripcClient, &er_dev_caps );
00210
00211 *has_stylus = er_dev_caps.has_stylus;
00212 *has_wifi = er_dev_caps.has_wifi;
00213 *has_bluetooth = er_dev_caps.has_bluetooth;
00214 *has_3g = er_dev_caps.has_3g;
00215
00216 return TRUE;
00217 }
00218
00219
00220 void mount_sd_card()
00221 {
00222 eripc_sysd_mount_sd_card(eripcClient, FALSE);
00223 }
00224
00225
00226 void unmount_sd_card()
00227 {
00228 eripc_sysd_unmount_sd_card(eripcClient);
00229 }
00230
00231
00232
00233 static gboolean ipc_menu_add_menu(const char *name,
00234 const char *label,
00235 const char *group1,
00236 const char *group2,
00237 const char *group3,
00238 const char *group4)
00239 {
00240 return eripc_menu_add_menu(eripcClient, name, group1, group2, group3, group4);
00241 }
00242
00243
00244
00245
00246
00247
00248
00249 static void on_mounted(eripc_context_t *context,
00250 const eripc_event_info_t *info,
00251 void *user_data)
00252 {
00253 LOGPRINTF("entry");
00254
00255 g_return_if_fail(info->args);
00256 g_return_if_fail(info->args[0].type == ERIPC_TYPE_STRING);
00257
00258 const eripc_arg_t *arg_array = info->args;
00259 const char *mountpoint = arg_array[0].value.s;
00260
00261 LOGPRINTF("mountpoint=%s", mountpoint);
00262 if (mountpoint && strcmp(mountpoint, SD_CARD_MOUNTPOINT) == 0)
00263 {
00264 LOGPRINTF("Calling sd_card_mounted(TRUE)\n");
00265 sd_card_mounted(TRUE);
00266 reset_sdcard_mounted(TRUE);
00267 }
00268 }
00269
00270
00271
00272 static void on_unmounted(eripc_context_t *context,
00273 const eripc_event_info_t *info,
00274 void *user_data)
00275 {
00276 LOGPRINTF("entry");
00277
00278 g_return_if_fail(info->args);
00279 g_return_if_fail(info->args[0].type == ERIPC_TYPE_STRING);
00280
00281 const eripc_arg_t *arg_array = info->args;
00282 const char *mountpoint = arg_array[0].value.s;
00283
00284 LOGPRINTF("mountpoint=%s", mountpoint);
00285 if (mountpoint && strcmp(mountpoint, SD_CARD_MOUNTPOINT) == 0)
00286 {
00287 LOGPRINTF("Calling sd_card_mounted(FALSE)\n");
00288 sd_card_mounted(FALSE);
00289 reset_sdcard_mounted(FALSE);
00290 }
00291 }
00292
00293
00294 static void on_window_activated(eripc_context_t *context,
00295 const eripc_event_info_t *info,
00296 void *user_data)
00297 {
00298 LOGPRINTF("entry");
00299 gboolean result = FALSE;
00300 const eripc_arg_t *arg_array = info->args;
00301
00302 if (arg_array[0].type == ERIPC_TYPE_INT)
00303 {
00304 ipc_menu_show_menu(SETTINGS_MENU);
00305 result = TRUE;
00306 }
00307
00308
00309 eripc_reply_bool(context, info->message_id, result);
00310 }
00311
00312 static void on_window_deactivated(eripc_context_t *context,
00313 const eripc_event_info_t *info,
00314 void *user_data)
00315 {
00316 LOGPRINTF("entry");
00317 gboolean result = FALSE;
00318 const eripc_arg_t *arg_array = info->args;
00319
00320 if (arg_array[0].type == ERIPC_TYPE_INT)
00321 {
00322
00323 main_quit();
00324 result = TRUE;
00325 }
00326
00327
00328 eripc_reply_bool(context, info->message_id, result);
00329 }
00330
00331
00332 static void on_changed_locale (eripc_context_t *context,
00333 const eripc_event_info_t *info,
00334 void *user_data)
00335 {
00336 LOGPRINTF("entry");
00337 const eripc_arg_t *arg_array = info->args;
00338
00339 if (arg_array[0].type == ERIPC_TYPE_STRING)
00340 {
00341 const char *locale = arg_array[0].value.s;
00342 if (locale)
00343 {
00344 const char *old_locale = g_getenv("LANG");
00345
00346 if (!old_locale || (strcmp(old_locale, locale) != 0))
00347 {
00348 LOGPRINTF("Locale has changed to %s", locale);
00349
00350
00351 g_setenv("LANG", locale, TRUE);
00352 setlocale(LC_ALL, "");
00353 }
00354 }
00355 }
00356 }
00357
00358
00359
00360 gint ipc_sys_open_url ( const gchar *url,
00361 const gchar *label,
00362 const gchar *back_text,
00363 gchar **err_message )
00364 {
00365 LOGPRINTF("entry: url [%s] label [%s] back_text [%s]",
00366 url, label, back_text );
00367 g_assert( url && *url );
00368 return eripc_sysd_open_url( eripcClient, url, label, back_text, err_message );
00369 }
00370
00371
00372
00373 gint ipc_sys_start_task ( const gchar *cmd_line,
00374 const gchar *work_dir,
00375 const gchar *label,
00376 const gchar *thumbnail_path,
00377 gchar **err_message )
00378 {
00379 LOGPRINTF("entry: cmd_line [%s] work_dir [%s] label [%s] thumbnail_path [%s]",
00380 cmd_line, work_dir, label, thumbnail_path );
00381 g_assert( cmd_line && *cmd_line );
00382 return eripc_sysd_start_task( eripcClient,
00383 cmd_line,
00384 work_dir,
00385 label,
00386 thumbnail_path,
00387 err_message);
00388 }
00389
00390
00391
00392 gboolean ipc_sys_stop_task ( const gchar *cmd_line )
00393 {
00394 LOGPRINTF("entry: cmd_line [%s]", cmd_line );
00395 g_assert( cmd_line && *cmd_line );
00396 return eripc_sysd_stop_task( eripcClient, cmd_line );
00397 }
00398
00399
00400 gboolean ipc_menu_block( void )
00401 {
00402 if (g_menu_blocked)
00403 {
00404 return FALSE;
00405 }
00406 g_menu_blocked = TRUE;
00407 return eripc_sysd_set_menu_state(eripcClient, "block");
00408 }
00409
00410
00411 gboolean ipc_menu_unblock( void )
00412 {
00413 if (!g_menu_blocked)
00414 {
00415 return FALSE;
00416 }
00417 g_menu_blocked = FALSE;
00418 return eripc_sysd_set_menu_state(eripcClient, "unblock");
00419 }
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429 gboolean ipc_sys_is_in_portrait_mode(void)
00430 {
00431
00432 gboolean result = TRUE;
00433
00434 eripc_error_t retval;
00435 eripc_event_info_t* info = NULL;
00436
00437 LOGPRINTF("entry");
00438
00439 retval = eripc_send_varargs_and_wait(eripcClient->context,
00440 &info,
00441 ERIPC_BUS_SESSION,
00442 DBUS_SERVICE_SYSD,
00443 "sysGetOrientation",
00444 ERIPC_TYPE_INVALID);
00445
00446 if (retval != ERIPC_ERROR_SUCCESS)
00447 {
00448 ERRORPRINTF("Error launching eripc handler");
00449 }
00450 else if (info == NULL || info->args == NULL)
00451 {
00452 ERRORPRINTF("sysd returns OK but no reply structure");
00453 }
00454 else
00455 {
00456 const eripc_arg_t *arg_array = info->args;
00457
00458 if (arg_array[0].type == ERIPC_TYPE_STRING)
00459 {
00460 if ( strcmp("portrait", arg_array[0].value.s) == 0 )
00461 {
00462 result = TRUE;
00463 }
00464 else
00465 {
00466 result = FALSE;
00467 }
00468 }
00469 else
00470 {
00471 result = FALSE ;
00472 }
00473 }
00474 eripc_event_info_free(eripcClient->context, info);
00475 return result;
00476 }
00477
00478
00479
00480
00481
00482
00483 static void on_changed_orientation ( eripc_context_t *context,
00484 const eripc_event_info_t *info,
00485 void *user_data )
00486 {
00487 LOGPRINTF("entry");
00488 const eripc_arg_t *arg_array = info->args;
00489
00490 if (arg_array[0].type == ERIPC_TYPE_STRING)
00491 {
00492 const char *orientation = arg_array[0].value.s;
00493 if (orientation)
00494 {
00495
00496 if ( 0 == strcasecmp( orientation, "portrait") )
00497 {
00498 datetime_set_orientation(TRUE);
00499 }
00500 else
00501 {
00502 datetime_set_orientation(FALSE);
00503 }
00504 }
00505 }
00506 }
00507
00508 gboolean ipc_get_battery_state(gint *level, gchar **state, gint *timeleft)
00509 {
00510 eripc_error_t retval;
00511 eripc_event_info_t *info = NULL;
00512 gboolean result = FALSE;
00513
00514 LOGPRINTF("entry");
00515
00516 retval = eripc_send_varargs_and_wait(eripcClient->context,
00517 &info,
00518 ERIPC_BUS_SESSION,
00519 DBUS_SERVICE_SYSD,
00520 "sysGetBatteryState",
00521 ERIPC_TYPE_INVALID);
00522
00523 if (retval == ERIPC_ERROR_SUCCESS)
00524 {
00525 const eripc_arg_t *arg_array = info->args;
00526
00527 if ((arg_array[0].type == ERIPC_TYPE_INT) &&
00528 (arg_array[1].type == ERIPC_TYPE_STRING) &&
00529 (arg_array[2].type == ERIPC_TYPE_INT))
00530 {
00531 *level = arg_array[0].value.i;
00532 *state = g_strdup(arg_array[1].value.s);
00533 if (timeleft != NULL)
00534 {
00535 *timeleft = arg_array[2].value.i;
00536 LOGPRINTF("Reply received: battery at %d%% %s, time left: %d", *level, *state, *timeleft);
00537 }
00538 else
00539 {
00540 LOGPRINTF("Reply received: battery at %d%% %s", *level, *state);
00541 }
00542
00543 result = TRUE;
00544 }
00545 }
00546 else
00547 {
00548 ERRORPRINTF("Error launching eripc handler: %s", eripc_error_string(retval));
00549 }
00550
00551 eripc_event_info_free(eripcClient->context, info);
00552 return result;
00553 }
00554
00555
00556