sysd/src/ipc.c

Go to the documentation of this file.
00001 /*
00002  * File Name: ipc.c
00003  */
00004 
00005 /*
00006  * This file is part of sysd.
00007  *
00008  * sysd is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * sysd is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00020  */
00021 
00022 /**
00023  * Copyright (C) 2008 iRex Technologies B.V.
00024  * All rights reserved.
00025  */
00026 
00027 //----------------------------------------------------------------------------
00028 // Include Files
00029 //----------------------------------------------------------------------------
00030 
00031 #include "config.h"
00032 
00033 // system include files, between < >
00034 #include <glib.h>
00035 #include <stdio.h>
00036 #include <stdlib.h>
00037 #include <string.h>
00038 
00039 // ereader include files, between < >
00040 #include <liberipc/eripc.h>
00041 #include <liberipc/eripc_support.h>
00042 #include <liberkeyb/erkeyb-client.h>
00043 
00044 // local include files, between " "
00045 #include "log.h"
00046 #include "busy.h"
00047 #include "ipc.h"
00048 #include "connections.h"
00049 #include "hal.h"
00050 #include "process.h"
00051 #include "system.h"
00052 #include "tasks.h"
00053 #include "wacom.h"
00054 #include "xwindow.h"
00055 
00056 
00057 //----------------------------------------------------------------------------
00058 // Type Declarations
00059 //----------------------------------------------------------------------------
00060 
00061 #define CHECK_ARG_STRING(x) \
00062     if (arg_array[x].type != ERIPC_TYPE_STRING || arg_array[x].value.s == NULL) { \
00063         ERRORPRINTF("arg %d is not a string", x); \
00064         return; \
00065     }
00066 
00067 #define CHECK_ARG_INT(x) \
00068     if (arg_array[x].type != ERIPC_TYPE_INT) { \
00069         ERRORPRINTF("arg %d is not an integer", x); \
00070         return; \
00071     }
00072 
00073 #define CHECK_ARG_BOOL(x) \
00074     if (arg_array[x].type != ERIPC_TYPE_BOOL) { \
00075         ERRORPRINTF("arg %d is not a boolean", x); \
00076         return; \
00077     }
00078 
00079 //----------------------------------------------------------------------------
00080 // Global Constants
00081 //----------------------------------------------------------------------------
00082 
00083 static const char *charge_text[]       = { "", "low", "charging", "discharging", "full" };
00084 static const char *orientation_text[]  = { "portrait", "landscape_clockwise", "landscape_anticlockwise" };
00085 
00086 static const gchar *browser_path       = "/usr/bin/erbrowser";
00087 static const gchar *browser_options    = "-n"; // start without navigation bar
00088 
00089 static const gchar *ade_fulfill_path    = "/usr/bin/adobe-fulfill";
00090 static const gchar *downloadmgr_path    = "/usr/bin/downloadmgr";
00091 
00092 
00093 //----------------------------------------------------------------------------
00094 // Static Variables
00095 //----------------------------------------------------------------------------
00096 
00097 eripc_client_context_t *eripcClient = NULL;
00098 
00099 
00100 //============================================================================
00101 // Local Function Definitions
00102 //============================================================================
00103 
00104 static void cb_sys_get_battery_state    (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00105 static void cb_sys_get_orientation      (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00106 static void cb_sys_get_pageturn_inverted(eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00107 static void cb_sys_get_card_mountpoint  (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00108 static void cb_sys_get_device_capabilities (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00109 static void cb_sys_set_busy_led         (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00110 static void cb_sys_set_bg_busy          (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00111 static void cb_sys_reset_bg_busy        (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00112 static void cb_sys_set_fg_busy          (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00113 static void cb_sys_reset_fg_busy        (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00114 static void cb_sys_beep                 (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00115 static void cb_sys_rotate               (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00116 static void cb_sys_lock_sensors         (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00117 static void cb_sys_set_stylus           (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00118 static void cb_sys_get_stylus           (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00119 static void cb_sys_card_mount           (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00120 static void cb_sys_card_unmount         (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00121 static void cb_sys_shutdown             (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00122 static void cb_sys_standby              (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00123 static void cb_sys_set_keyboard         (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00124 static void cb_task_start               (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00125 static void cb_task_activate            (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00126 static void cb_task_stop                (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00127 static void cb_task_rename              (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00128 static void cb_menu_request_popup       (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00129 static void cb_menu_item_activated      (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00130 static void cb_status_item_activated    (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00131 static void cb_startup_complete         (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00132 static void cb_open_url                 (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00133 static void cb_opened_window            (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00134 static void cb_closed_window            (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00135 static void on_confirm_usbconnect       (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00136 static void on_confirm_install_drz      (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00137 static void on_confirm_install_update   (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00138 static void cb_conn_connect             (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00139 static void cb_conn_disconnect          (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00140 static void cb_conn_status              (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00141 static void cb_conn_status_request      (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00142 static void cb_conn_signal              (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00143 static void cb_conn_add_profile         (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00144 static void cb_conn_edit_profile        (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00145 static void testing_list_tasks          (eripc_context_t *context, const eripc_event_info_t *info, void *user_data);
00146 
00147 static const gchar *medium_service      (const char *medium);
00148 static gint sender_from_service         (const char *service);
00149 
00150 // Exported DBUS API list
00151 static eripc_callback_function_t service_functions[] = {
00152         // message handlers (method calls to this service)
00153         { cb_sys_get_battery_state,         "sysGetBatteryState",           NULL,              0 },
00154         { cb_sys_get_orientation,           "sysGetOrientation",            NULL,              0 },
00155         { cb_sys_get_pageturn_inverted,     "sysGetPageturnInverted",       NULL,              0 },
00156         { cb_sys_get_card_mountpoint,       "sysGetCardMountPoint",         NULL,              0 },
00157         { cb_sys_get_device_capabilities,   "sysGetDeviceCapabilities",     NULL,              0 },
00158         { cb_sys_beep,                      "sysBeep",                      NULL,              0 },
00159         { cb_sys_set_busy_led,              "sysSetBusyLed",                NULL,              0 },
00160         { cb_sys_set_bg_busy,               "sysSetBgBusy",                 NULL,              0 },
00161         { cb_sys_reset_bg_busy,             "sysResetBgBusy",               NULL,              0 },
00162         { cb_sys_set_fg_busy,               "sysSetBusy",                   NULL,              0 },
00163         { cb_sys_reset_fg_busy,             "sysResetBusy",                 NULL,              0 },
00164         { cb_sys_rotate,                    "sysRotate",                    NULL,              0 },
00165         { cb_sys_lock_sensors,              "sysLockSensors",               NULL,              0 },
00166         { cb_sys_set_stylus,                "sysSetStylus",                 NULL,              0 },
00167         { cb_sys_get_stylus,                "sysGetStylus",                 NULL,              0 },
00168         { cb_sys_card_mount,                "sysCardMount",                 NULL,              0 },
00169         { cb_sys_card_unmount,              "sysCardUnmount",               NULL,              0 },
00170         { cb_sys_shutdown,                  "sysShutdown",                  NULL,              0 },
00171         { cb_sys_standby,                   "sysStandby",                   NULL,              0 },
00172         { cb_sys_set_keyboard,              "sysSetKeyboard",               NULL,              0 },
00173         { cb_task_start,                    "startTask",                    NULL,              0 },
00174         { cb_task_activate,                 "activateTask",                 NULL,              0 },
00175         { cb_task_stop,                     "stopTask",                     NULL,              0 },
00176         { cb_task_rename,                   "renameTask",                   NULL,              0 },
00177         { cb_open_url,                      "openUrl",                      NULL,              0 },
00178         { cb_opened_window,                 "openedWindow",                 NULL,              0 },
00179         { cb_closed_window,                 "closedWindow",                 NULL,              0 },
00180         { cb_menu_request_popup,            "menuRequestPopup",             NULL,              0 },
00181         { cb_menu_item_activated,           "menuItemActivated",            NULL,              0 },
00182         { cb_status_item_activated,         "statusItemActivated",          NULL,              0 },
00183         { cb_conn_connect,                  "connConnect",                  NULL,              0 },
00184         { cb_conn_disconnect,               "connDisconnect",               NULL,              0 },
00185         { cb_conn_status,                   "connConnectionStatus",         NULL,              0 },
00186         { cb_conn_signal,                   "connConnectionSignal",         NULL,              0 },
00187         { cb_conn_status_request,           "connConnectionStatusRequest",  NULL,              0 },
00188         { cb_conn_add_profile,              "connAddProfile",               NULL,              0 },
00189         { cb_conn_edit_profile,             "connEditProfile",              NULL,              0 },
00190         // signal handlers (broadcasted from given service)
00191         { cb_startup_complete,              "startupComplete",              DBUS_INTERFACE,    0 },
00192         { cb_closed_window,                 "closedWindow",                 DBUS_INTERFACE,    0 },
00193         // for testing
00194         { testing_list_tasks,               "testingListTasks",             NULL,              0 },
00195         { NULL, NULL, NULL, 0 }
00196     };
00197 
00198 
00199 //============================================================================
00200 // Functions Implementation
00201 //============================================================================
00202 
00203 void ipc_set_services(void)
00204 {
00205     eripcClient = eripc_client_context_new(
00206                     DBUS_APPL_NAME,
00207                     "1.0",
00208                     DBUS_SERVICE,
00209                     DBUS_PATH,
00210                     DBUS_INTERFACE,
00211                     service_functions);
00212     
00213     erkeyb_client_init();
00214 }
00215 
00216 
00217 void ipc_unset_services(void)
00218 {
00219     erkeyb_client_term();
00220     eripc_client_context_free(eripcClient, service_functions);
00221 }
00222 
00223 
00224 void ipc_send_battery_state(gint battery_level, enum state_charge charge_state, gint time_left)
00225 {
00226     LOGPRINTF("entry");
00227     
00228     // broadcast signal over session bus
00229     //
00230     eripc_send_signal_varargs(eripcClient->context, 
00231                               ERIPC_BUS_SESSION,
00232                               DBUS_PATH,
00233                               DBUS_INTERFACE,
00234                               "sysBatteryState",
00235                               ERIPC_TYPE_INT, battery_level,
00236                               ERIPC_TYPE_STRING, charge_text[charge_state],
00237                               ERIPC_TYPE_INT, time_left,
00238                               ERIPC_TYPE_INVALID);
00239     
00240     LOGPRINTF("Sent signal sysBatteryState: %d, %s", battery_level, charge_text[charge_state]);
00241 }
00242 
00243 
00244 void ipc_send_prepare_standby()
00245 {
00246     LOGPRINTF("entry");
00247     
00248     // broadcast signal over session bus
00249     //
00250     eripc_send_signal_varargs(eripcClient->context, 
00251                               ERIPC_BUS_SESSION,
00252                               DBUS_PATH,
00253                               DBUS_INTERFACE,
00254                               "sysPrepareStandby",
00255                               ERIPC_TYPE_INVALID);
00256     
00257     LOGPRINTF("Sent signal sysPrepareStandby");
00258 }
00259 
00260 
00261 void ipc_send_prepare_unmount(const char *mount_point)
00262 {
00263     LOGPRINTF("entry");
00264 
00265     // broadcast signal over session bus
00266     //
00267     eripc_send_signal_varargs(eripcClient->context, 
00268                               ERIPC_BUS_SESSION,
00269                               DBUS_PATH,
00270                               DBUS_INTERFACE,
00271                               "sysPrepareUnmount",
00272                               ERIPC_TYPE_STRING, mount_point,
00273                               ERIPC_TYPE_INVALID);
00274     
00275     LOGPRINTF("Sent signal sysPrepareUnmount %s", mount_point);
00276 }
00277 
00278 
00279 void ipc_send_volume_mounted(const char *mount_point)
00280 {
00281     LOGPRINTF("entry");
00282     
00283     // broadcast signal over session bus
00284     //
00285     eripc_send_signal_varargs(eripcClient->context, 
00286                               ERIPC_BUS_SESSION,
00287                               DBUS_PATH,
00288                               DBUS_INTERFACE,
00289                               "sysVolumeMounted",
00290                               ERIPC_TYPE_STRING, mount_point,
00291                               ERIPC_TYPE_INVALID);
00292     
00293     LOGPRINTF("Sent signal sysVolumeMounted %s", mount_point);
00294 }
00295 
00296 
00297 void ipc_send_volume_mounted_to(const char *service, const char *mount_point)
00298 {
00299     eripc_error_t retval;
00300 
00301     LOGPRINTF("entry");
00302     
00303     retval = eripc_send_string(eripcClient->context, 
00304                                NULL,
00305                                NULL,
00306                                ERIPC_BUS_SESSION,
00307                                service,
00308                                "sysVolumeMounted",
00309                                mount_point);
00310     
00311     if (retval != ERIPC_ERROR_SUCCESS) 
00312     {
00313         ERRORPRINTF("Error launching eripc handler: %s", eripc_error_string(retval));
00314         return;
00315     }
00316 
00317     LOGPRINTF("Sent sysVolumeMounted %s to %s", mount_point, service);
00318 }
00319 
00320 
00321 void ipc_send_volume_unmounted(const char *mount_point)
00322 {
00323     LOGPRINTF("entry");
00324     
00325     // broadcast signal over session bus
00326     //
00327     eripc_send_signal_varargs(eripcClient->context, 
00328                               ERIPC_BUS_SESSION,
00329                               DBUS_PATH,
00330                               DBUS_INTERFACE,
00331                               "sysVolumeUnmounted",
00332                               ERIPC_TYPE_STRING, mount_point,
00333                               ERIPC_TYPE_INVALID);
00334     
00335     LOGPRINTF("Sent signal sysVolumeUnmounted %s", mount_point);
00336 }
00337 
00338 void ipc_refresh_ctb()
00339 {
00340     eripc_send_varargs(eripcClient->context,
00341                       NULL,
00342                       NULL,
00343                       ERIPC_BUS_SESSION,
00344                       DBUS_SERVICE_CTB,
00345                       "filesystemChanged", ERIPC_TYPE_INVALID);
00346 }
00347 
00348 
00349 void ipc_send_usb_state(const char *state)
00350 {
00351     LOGPRINTF("state = '%s'", state);
00352     
00353     // broadcast signal over session bus
00354     //
00355     eripc_send_signal_varargs(eripcClient->context, 
00356                               ERIPC_BUS_SESSION,
00357                               DBUS_PATH,
00358                               DBUS_INTERFACE,
00359                               "sysUsbState",
00360                               ERIPC_TYPE_STRING, state,
00361                               ERIPC_TYPE_INVALID);
00362     
00363     LOGPRINTF("Sent signal sysUsbState %s", state);
00364 }
00365 
00366 
00367 void ipc_send_changed_locale(const char *locale)
00368 {
00369     LOGPRINTF("entry");
00370     
00371     // broadcast signal over session bus
00372     //
00373     eripc_send_signal_varargs(eripcClient->context, 
00374                               ERIPC_BUS_SESSION,
00375                               DBUS_PATH,
00376                               DBUS_INTERFACE,
00377                               "sysChangedLocale",
00378                               ERIPC_TYPE_STRING, locale,
00379                               ERIPC_TYPE_INVALID);
00380     
00381     LOGPRINTF("Sent signal sysChangedLocale %s", locale);
00382 }
00383 
00384 
00385 void ipc_send_demo_mode(gboolean demo_mode)
00386 {
00387     LOGPRINTF("entry");
00388 
00389     // broadcast signal over session bus
00390     //
00391     eripc_send_signal_varargs(eripcClient->context,
00392                               ERIPC_BUS_SESSION,
00393                               DBUS_PATH,
00394                               DBUS_INTERFACE,
00395                               "sysChangeDemoMode",
00396                               ERIPC_TYPE_BOOL, demo_mode,
00397                               ERIPC_TYPE_INVALID);
00398 
00399     LOGPRINTF("Sent signal sysChangeDemoMode %d", demo_mode);
00400 }
00401 
00402 
00403 void ipc_send_changed_pageturn_inverted(gboolean is_inverted)
00404 {
00405     LOGPRINTF("entry");
00406 
00407     // broadcast signal over session bus
00408     //
00409     eripc_send_signal_varargs(eripcClient->context, 
00410                               ERIPC_BUS_SESSION,
00411                               DBUS_PATH,
00412                               DBUS_INTERFACE,
00413                               "sysChangedPageturnInverted",
00414                               ERIPC_TYPE_BOOL, is_inverted,
00415                               ERIPC_TYPE_INVALID);
00416     
00417     LOGPRINTF("Sent signal sysChangedPageturnInverted %d", (gint)is_inverted);
00418 }
00419 
00420 
00421 void ipc_send_changed_orientation(guint orientation)
00422 {
00423     LOGPRINTF("entry");
00424 
00425     if (orientation >= sizeof(orientation_text))
00426     {
00427         ERRORPRINTF("Orientation %d unknown, signal not sent.", orientation);
00428         return;
00429     }
00430     
00431     // broadcast signal over session bus
00432     //
00433     eripc_send_signal_varargs(eripcClient->context, 
00434                               ERIPC_BUS_SESSION,
00435                               DBUS_PATH,
00436                               DBUS_INTERFACE,
00437                               "sysChangedOrientation",
00438                               ERIPC_TYPE_STRING, orientation_text[orientation],
00439                               ERIPC_TYPE_INVALID);
00440     
00441     LOGPRINTF("Sent signal sysChangedOrientation %s", orientation_text[orientation]);
00442 }
00443 
00444 
00445 static void ipc_send_window_show(const char *ipc_interface, gint window)
00446 {
00447     LOGPRINTF("entry");
00448     
00449     eripc_error_t retval;
00450     retval = eripc_send_int(eripcClient->context,
00451                             NULL,
00452                             NULL,
00453                             ERIPC_BUS_SESSION,
00454                             ipc_interface,
00455                             "showWindow",
00456                             window);
00457 
00458     if (retval != ERIPC_ERROR_SUCCESS) 
00459     {
00460         ERRORPRINTF("Error launching eripc handler: %s", eripc_error_string(retval));
00461     }
00462 }
00463 
00464 
00465 void ipc_menu_set_item_state(const char *iname, const char *pname, const char *state) 
00466 {
00467     eripc_menu_set_item_state(eripcClient, iname, pname, state);
00468 }
00469 
00470 
00471 void ipc_menu_set_statusitem_state(const char *name, const char *state) 
00472 {
00473     eripc_menu_set_statusitem_state(eripcClient, name, state);
00474 }
00475 
00476 
00477 void ipc_menu_add_task(gint xid, const char *label)
00478 {
00479     LOGPRINTF("entry, xid=%d  label='%s'", xid, label);
00480     g_return_if_fail(label != NULL);
00481 
00482     eripc_error_t retval = eripc_send_varargs(eripcClient->context,
00483                                 NULL,
00484                                 NULL,
00485                                 ERIPC_BUS_SESSION,
00486                                 DBUS_SERVICE_MENU,
00487                                 "addTask",
00488                                 ERIPC_TYPE_INT, xid,
00489                                 ERIPC_TYPE_STRING, label,
00490                                 ERIPC_TYPE_STRING, DBUS_INTERFACE,
00491                                 ERIPC_TYPE_INVALID);
00492     
00493     if (retval != ERIPC_ERROR_SUCCESS) 
00494     {
00495         ERRORPRINTF("Error launching eripc handler: %s", eripc_error_string(retval));
00496     } 
00497 }
00498 
00499 
00500 void ipc_menu_set_first_task(int xid) 
00501 {
00502     LOGPRINTF("xid=%d", xid);
00503 
00504     eripc_error_t retval = eripc_send_int(eripcClient->context,
00505                                 NULL,
00506                                 NULL,
00507                                 ERIPC_BUS_SESSION,
00508                                 DBUS_SERVICE_MENU,
00509                                 "setTaskToTop",
00510                                 xid);
00511 
00512     if (retval != ERIPC_ERROR_SUCCESS) 
00513     {
00514         ERRORPRINTF("Error launching eripc handler: %s", eripc_error_string(retval));
00515     } 
00516 }
00517 
00518 
00519 void ipc_menu_remove_task(int xid) 
00520 {
00521     LOGPRINTF("entry, xid=%d", xid);
00522 
00523     eripc_error_t retval = eripc_send_int(eripcClient->context,
00524                                NULL,
00525                                NULL,
00526                                ERIPC_BUS_SESSION,
00527                                DBUS_SERVICE_MENU,
00528                                "removeTask", xid);
00529     if (retval != ERIPC_ERROR_SUCCESS) 
00530     {
00531         ERRORPRINTF("Error launching eripc handler: %s", eripc_error_string(retval));
00532     } 
00533 }
00534 
00535 
00536 void ipc_menu_rename_task(int xid, const char* label)
00537 {
00538     LOGPRINTF("entry, xid=%d  label=%s", xid, label);
00539 
00540     eripc_error_t retval = eripc_send_varargs(eripcClient->context,
00541                                NULL,
00542                                NULL,
00543                                ERIPC_BUS_SESSION,
00544                                DBUS_SERVICE_MENU,
00545                                "renameTask",
00546                                ERIPC_TYPE_INT, xid,
00547                                ERIPC_TYPE_STRING, label,
00548                                ERIPC_TYPE_INVALID);
00549     if (retval != ERIPC_ERROR_SUCCESS) 
00550     {
00551         ERRORPRINTF("Error launching eripc handler: %s", eripc_error_string(retval));
00552     } 
00553 }
00554 
00555 
00556 void ipc_menu_show(const char *menu)
00557 {
00558     eripc_menu_show_menu(eripcClient, menu);
00559 }
00560 
00561 
00562 void ipc_show_popup(const char *state)
00563 {
00564     LOGPRINTF("entry");
00565     
00566     eripc_error_t retval;
00567     retval = eripc_send_string(eripcClient->context,
00568                                NULL,
00569                                NULL,
00570                                ERIPC_BUS_SESSION,
00571                                DBUS_SERVICE_MENU,
00572                                "setPopupShow",
00573                                state);
00574 
00575     if (retval != ERIPC_ERROR_SUCCESS) 
00576     {
00577         ERRORPRINTF("Error launching eripc handler: %s", eripc_error_string(retval));
00578     }
00579 }
00580 
00581 
00582 void ipc_show_busy(gboolean show_mode, const gchar *message)
00583 {
00584     LOGPRINTF("entry");
00585     eripc_error_t retval;
00586 
00587     retval = eripc_send_varargs(eripcClient->context,
00588                                 NULL,
00589                                 NULL,
00590                                 ERIPC_BUS_SESSION,
00591                                 DBUS_SERVICE_MENU,
00592                                "setBusyShow",
00593                                 ERIPC_TYPE_STRING, show_mode ? "show" : "hide",
00594                                 ERIPC_TYPE_STRING, message,
00595                                 ERIPC_TYPE_INVALID);
00596 
00597     if (retval != ERIPC_ERROR_SUCCESS) 
00598     {
00599         ERRORPRINTF("Error launching eripc handler: %s", eripc_error_string(retval));
00600     }
00601 }
00602 
00603 
00604 void ipc_show_splash(const char *type)
00605 {
00606     LOGPRINTF("entry [%s]", type);
00607     eripc_error_t retval;
00608     
00609     g_return_if_fail(type != NULL);
00610 
00611     // it may take a little while for the splash to show up
00612     // so make sure we don't suspend early
00613     sys_reset_idle_time();
00614     
00615     retval = eripc_send_string(eripcClient->context,
00616                                NULL,
00617                                NULL,
00618                                ERIPC_BUS_SESSION,
00619                                DBUS_SERVICE_MENU,
00620                                "setSplashShow", type);
00621     
00622     if (retval != ERIPC_ERROR_SUCCESS) 
00623     {
00624         ERRORPRINTF("Error launching eripc handler: %s", eripc_error_string(retval));
00625     }
00626 }
00627 
00628 
00629 void ipc_show_message(const char *type, const void *reply_handler, const void *user_data)
00630 {
00631     LOGPRINTF("entry");
00632     eripc_error_t retval;
00633     
00634     g_return_if_fail(type != NULL);
00635 
00636     retval = eripc_send_string(eripcClient->context,
00637                                (eripc_handler_t *) reply_handler,
00638                                user_data,
00639                                ERIPC_BUS_SESSION,
00640                                DBUS_SERVICE_MENU,
00641                                "setMessageShow",
00642                                type);
00643 
00644     if (retval != ERIPC_ERROR_SUCCESS) 
00645     {
00646         ERRORPRINTF("Error launching eripc handler: %s", eripc_error_string(retval));
00647     }
00648 }
00649 
00650 
00651 void ipc_confirm_usbconnect(gboolean show_mode)
00652 {
00653     LOGPRINTF("entry");
00654     eripc_error_t retval;
00655     
00656     retval = eripc_send_string(eripcClient->context,
00657                                 show_mode ? &on_confirm_usbconnect : NULL,
00658                                 NULL,
00659                                 ERIPC_BUS_SESSION,
00660                                 DBUS_SERVICE_MENU,
00661                                 "confirmUsbConnect",
00662                                 show_mode ? "show" : "hide");
00663 
00664     if (retval != ERIPC_ERROR_SUCCESS) 
00665     {
00666         ERRORPRINTF("Error launching eripc handler: %s", eripc_error_string(retval));
00667     }
00668 }
00669 
00670 
00671 void ipc_confirm_install_drz(gboolean show_mode)
00672 {
00673     LOGPRINTF("entry");
00674     eripc_error_t retval;
00675     
00676     retval = eripc_send_string(eripcClient->context,
00677                                 &on_confirm_install_drz,
00678                                 NULL,
00679                                 ERIPC_BUS_SESSION,
00680                                 DBUS_SERVICE_MENU,
00681                                 "confirmInstallDrz",
00682                                 show_mode ? "show" : "hide");
00683 
00684     if (retval != ERIPC_ERROR_SUCCESS) 
00685     {
00686         ERRORPRINTF("Error launching eripc handler: %s", eripc_error_string(retval));
00687     }
00688     
00689     return;
00690 }
00691 
00692 
00693 void ipc_confirm_install_update(gboolean show_mode)
00694 {
00695     LOGPRINTF("entry");
00696     eripc_error_t retval;
00697     
00698     retval = eripc_send_string(eripcClient->context,
00699                                 &on_confirm_install_update,
00700                                 NULL,
00701                                 ERIPC_BUS_SESSION,
00702                                 DBUS_SERVICE_MENU,
00703                                 "confirmInstallUpdate",
00704                                 show_mode ? "show" : "hide");
00705 
00706     if (retval != ERIPC_ERROR_SUCCESS) 
00707     {
00708         ERRORPRINTF("Error launching eripc handler: %s", eripc_error_string(retval));
00709     }
00710 }
00711 
00712 
00713 void ipc_ctb_goto(const char *location)
00714 {
00715     LOGPRINTF("entry");
00716     
00717     eripc_error_t retval;
00718         
00719     g_return_if_fail(location != NULL);
00720     
00721     retval = eripc_send_string(eripcClient->context,
00722                                NULL, // reply handler
00723                                NULL, // reply data
00724                                ERIPC_BUS_SESSION,
00725                                DBUS_SERVICE_CTB,
00726                                "gotoLocation",
00727                                location);
00728 
00729     if (retval != ERIPC_ERROR_SUCCESS) 
00730     {
00731         ERRORPRINTF("Error launching eripc handler: %s", eripc_error_string(retval));
00732     }
00733 }
00734 
00735 
00736 gboolean ipc_connect(const char *ipc_service, const char *medium, const char *profile)
00737 {
00738     LOGPRINTF("entry");
00739 
00740     eripc_error_t retval;
00741         
00742     g_return_val_if_fail(medium != NULL, FALSE);
00743     // profile may be NULL
00744     
00745     // NOTE: this call slightly differs from eripc_sysd_conn_connect()
00746     //       in that it uses the IPC SERVICE of the connection manager as
00747     //       destination for the message 
00748     retval = eripc_send_varargs(eripcClient->context,
00749                                NULL,            // no reply handler
00750                                NULL,            // no reply data
00751                                ERIPC_BUS_SESSION,
00752                                ipc_service,
00753                                "connConnect",
00754                                ERIPC_TYPE_STRING, ipc_service,
00755                                ERIPC_TYPE_STRING, medium,
00756                                ERIPC_TYPE_STRING, profile,
00757                                ERIPC_TYPE_INVALID);
00758     
00759     if (retval != ERIPC_ERROR_SUCCESS) 
00760     {
00761         ERRORPRINTF("Error launching eripc handler: %s", eripc_error_string(retval));
00762         return FALSE;
00763     }
00764     
00765     return TRUE;
00766 }
00767 
00768 
00769 gboolean ipc_disconnect(const char *ipc_service)
00770 {
00771     LOGPRINTF("entry");
00772 
00773     eripc_error_t retval;
00774         
00775     // NOTE: this call slightly differs from eripc_sysd_conn_connect()
00776     //       in that it uses the IPC SERVICE of the connection manager as
00777     //       destination for the message 
00778     retval = eripc_send_varargs(eripcClient->context,
00779                                NULL,            // no reply handler
00780                                NULL,            // no reply data
00781                                ERIPC_BUS_SESSION,
00782                                ipc_service,
00783                                "connDisconnect",
00784                                ERIPC_TYPE_STRING, ipc_service,
00785                                ERIPC_TYPE_INVALID);
00786     
00787     if (retval != ERIPC_ERROR_SUCCESS) 
00788     {
00789         ERRORPRINTF("Error launching eripc handler: %s", eripc_error_string(retval));
00790         return FALSE;
00791     }
00792     
00793     return TRUE;
00794 }
00795 
00796 
00797 gboolean ipc_send_conn_status( const char *ipc_service,
00798                                gboolean   is_connected,
00799                                const char *medium,
00800                                const char *profile,
00801                                const char *reason  )
00802 {
00803     LOGPRINTF("entry");
00804 
00805     eripc_error_t retval;
00806         
00807     // NOTE: status is send to a specific service when there was no change is in state (already connected/disconnected)
00808     retval = eripc_send_varargs(eripcClient->context,
00809                                NULL,            // no reply handler
00810                                NULL,            // no reply data
00811                                ERIPC_BUS_SESSION,
00812                                ipc_service,
00813                                "connConnectionStatus",
00814                                ERIPC_TYPE_BOOL,   is_connected,
00815                                ERIPC_TYPE_STRING, medium,
00816                                ERIPC_TYPE_STRING, profile,
00817                                ERIPC_TYPE_STRING, reason,
00818                                ERIPC_TYPE_INVALID);
00819     
00820     if (retval != ERIPC_ERROR_SUCCESS) 
00821     {
00822         ERRORPRINTF("Error launching eripc handler: %s", eripc_error_string(retval));
00823         return FALSE;
00824     }
00825     
00826     return TRUE;
00827 }
00828 
00829 
00830 gboolean ipc_broadcast_conn_status( gboolean   is_connected,
00831                                     const char *medium,
00832                                     const char *profile,
00833                                     const char *reason  )
00834 {
00835     LOGPRINTF("connected=%d", is_connected);
00836 
00837     // NOTE: status is broadcasted when it was changed
00838     eripc_send_signal_varargs(eripcClient->context, 
00839                               ERIPC_BUS_SESSION,
00840                               DBUS_PATH,
00841                               DBUS_INTERFACE,
00842                               "connConnectionStatus",
00843                               ERIPC_TYPE_BOOL,   is_connected,
00844                               ERIPC_TYPE_STRING, medium,
00845                               ERIPC_TYPE_STRING, profile,
00846                               ERIPC_TYPE_STRING, reason,
00847                               ERIPC_TYPE_INVALID);
00848     
00849     return TRUE;
00850 }
00851 
00852 
00853 gboolean ipc_broadcast_conn_signal( const char *medium,
00854                                     const int  signal )
00855 {
00856     LOGPRINTF("%s signal: %d", medium, signal);
00857 
00858     // NOTE: signal is broadcasted when it was changed
00859     eripc_send_signal_varargs(eripcClient->context, 
00860                               ERIPC_BUS_SESSION,
00861                               DBUS_PATH,
00862                               DBUS_INTERFACE,
00863                               "sysSignalStrength",
00864                               ERIPC_TYPE_INT,    signal,
00865                               ERIPC_TYPE_STRING, medium,
00866                               ERIPC_TYPE_INVALID);
00867     
00868     return TRUE;
00869 }
00870 
00871 
00872 gboolean ipc_add_profile(const char *medium)
00873 {
00874     LOGPRINTF("entry");
00875 
00876     eripc_error_t retval;
00877         
00878     g_return_val_if_fail(medium != NULL, FALSE);
00879     
00880     retval = eripc_send_varargs(eripcClient->context,
00881                                NULL,            // no reply handler
00882                                NULL,            // no reply data
00883                                ERIPC_BUS_SESSION,
00884                                medium_service(medium),
00885                                "connAddProfile",
00886                                ERIPC_TYPE_STRING, medium,
00887                                ERIPC_TYPE_INVALID);
00888     
00889     if (retval != ERIPC_ERROR_SUCCESS) 
00890     {
00891         ERRORPRINTF("Error launching eripc handler: %s", eripc_error_string(retval));
00892         return FALSE;
00893     }
00894     
00895     return TRUE;
00896 }
00897 
00898 
00899 gboolean ipc_edit_profile(const char *medium, const char *profile)
00900 {
00901     LOGPRINTF("entry");
00902 
00903     eripc_error_t retval;
00904         
00905     g_return_val_if_fail(medium  != NULL, FALSE);
00906     g_return_val_if_fail(profile != NULL, FALSE);
00907     
00908     retval = eripc_send_varargs(eripcClient->context,
00909                                NULL,            // no reply handler
00910                                NULL,            // no reply data
00911                                ERIPC_BUS_SESSION,
00912                                medium_service(medium),
00913                                "connEditProfile",
00914                                ERIPC_TYPE_STRING, medium,
00915                                ERIPC_TYPE_STRING, profile,
00916                                ERIPC_TYPE_INVALID);
00917     
00918     if (retval != ERIPC_ERROR_SUCCESS) 
00919     {
00920         ERRORPRINTF("Error launching eripc handler: %s", eripc_error_string(retval));
00921         return FALSE;
00922     }
00923     
00924     return TRUE;
00925 }
00926 
00927 
00928 gboolean ipc_send_open(const char *ipc_interface, 
00929                        const char *document, 
00930                        void *callback_handler, 
00931                        void *callback_data)
00932 {
00933     LOGPRINTF("entry");
00934     
00935     eripc_error_t retval;
00936         
00937     g_return_val_if_fail(ipc_interface != NULL, FALSE);
00938     g_return_val_if_fail(document != NULL, FALSE);
00939     
00940     retval = eripc_send_string(eripcClient->context,
00941                                callback_handler,
00942                                callback_data,
00943                                ERIPC_BUS_SESSION,
00944                                ipc_interface,
00945                                "openFile",
00946                                document);
00947 
00948     if (retval != ERIPC_ERROR_SUCCESS) 
00949     {
00950         ERRORPRINTF("Error launching eripc handler: %s", eripc_error_string(retval));
00951         return FALSE;
00952     }
00953     
00954     return TRUE;
00955 }
00956 
00957 
00958 gboolean ipc_send_close(const char *ipc_interface, 
00959                         const char *document, 
00960                         void *callback_handler, 
00961                         void *callback_data)
00962 {
00963     LOGPRINTF("entry");
00964     
00965     eripc_error_t retval;
00966         
00967     g_return_val_if_fail(ipc_interface != NULL, FALSE);
00968     g_return_val_if_fail(document != NULL, FALSE);
00969     
00970     retval = eripc_send_string(eripcClient->context,
00971                                callback_handler,
00972                                callback_data,
00973                                ERIPC_BUS_SESSION,
00974                                ipc_interface,
00975                                "closeFile",
00976                                document);
00977 
00978     if (retval != ERIPC_ERROR_SUCCESS) 
00979     {
00980         ERRORPRINTF("Error launching eripc handler: %s", eripc_error_string(retval));
00981         return FALSE;
00982     }
00983     
00984     return TRUE;
00985 }
00986 
00987 
00988 void ipc_send_reply(eripc_context_t *context, const char *message_id, gboolean result)
00989 {
00990     LOGPRINTF("entry");
00991     
00992     g_return_if_fail(context != NULL);
00993 
00994     if (message_id)
00995     {
00996         LOGPRINTF("Sending reply %s to: %s, context %p", (result == TRUE ? "TRUE":"FALSE"), message_id, context);
00997 
00998         eripc_error_t retval = eripc_reply_bool(context, message_id, result);
00999         if (retval != ERIPC_ERROR_SUCCESS) 
01000         {
01001             ERRORPRINTF("Error sending reply to message: %s", eripc_error_string(retval));
01002         }
01003     }
01004     else
01005     {
01006         LOGPRINTF("Result is %s but no reply was requested", (result == TRUE ? "TRUE":"FALSE"));
01007     }
01008 }
01009 
01010 
01011 void ipc_send_reply_task_start(eripc_context_t *context, const char *message_id, gint err_code, gchar *err_msg)
01012 {
01013     LOGPRINTF("entry");
01014     
01015 
01016     g_return_if_fail(context != NULL);
01017 
01018     if (message_id)
01019     {
01020         LOGPRINTF("Sending reply %d to: %s, context %p", err_code, message_id, context);
01021 
01022         eripc_error_t retval = eripc_reply_varargs(context, message_id, 
01023                                      ERIPC_TYPE_INT, err_code,
01024                                      ERIPC_TYPE_STRING, err_msg,
01025                                      ERIPC_TYPE_INVALID);
01026         if (retval != ERIPC_ERROR_SUCCESS) 
01027         {
01028             ERRORPRINTF("Error sending reply to message: %s", eripc_error_string(retval));
01029         }
01030     }
01031     else
01032     {
01033         LOGPRINTF("Sending reply %d but no reply was requested", err_code);
01034     }
01035 }
01036 
01037 
01038 //============================================================================
01039 // Local Function Implementation
01040 //============================================================================
01041 
01042 static void cb_sys_get_battery_state(eripc_context_t *context, const eripc_event_info_t *info, void *user_data)
01043 {
01044     LOGPRINTF("entry");
01045     
01046     gboolean result = FALSE;
01047 
01048     if (info->message_id)
01049     {
01050         enum state_charge charge_state = 0;
01051         gint battery_level = 0;
01052         gint time_left = 0;
01053         
01054         sys_get_battery(&battery_level, &charge_state, &time_left);
01055 
01056         LOGPRINTF("Sending battery %d, state %s to, time left %d: %s, context %p", 
01057                   battery_level, 
01058                   charge_text[charge_state], 
01059                   time_left, 
01060                   info->message_id, 
01061                   context);
01062 
01063         result = eripc_reply_varargs(context, info->message_id, 
01064                                       ERIPC_TYPE_INT, battery_level,
01065                                       ERIPC_TYPE_STRING, charge_text[charge_state], 
01066                                       ERIPC_TYPE_INT, -1,
01067                                       ERIPC_TYPE_INVALID);
01068 
01069         if (result != ERIPC_ERROR_SUCCESS) 
01070         {
01071             ERRORPRINTF("Error sending reply to message: %s", eripc_error_string(result));
01072         }
01073     }
01074 }
01075 
01076 
01077 static void cb_sys_get_orientation(eripc_context_t *context, const eripc_event_info_t *info, void *user_data)
01078 {
01079     LOGPRINTF("entry");
01080     
01081     gboolean result = FALSE;
01082 
01083     if (info->message_id)
01084     {
01085         guint orientation = sys_get_orientation();
01086         
01087         if (orientation >= sizeof(orientation_text))
01088         {
01089             ERRORPRINTF("Orientation %d unknown, signal not sent.", orientation);
01090             return;
01091         }
01092 
01093         LOGPRINTF("Sending orientation %s", orientation_text[orientation]);
01094 
01095         result = eripc_reply_varargs(context, info->message_id, 
01096                                       ERIPC_TYPE_STRING, orientation_text[orientation], 
01097                                       ERIPC_TYPE_INVALID);
01098 
01099         if (result != ERIPC_ERROR_SUCCESS) 
01100         {
01101             ERRORPRINTF("Error sending reply to message: %s", eripc_error_string(result));
01102         }
01103     }
01104 }
01105 
01106 
01107 static void cb_sys_get_pageturn_inverted(eripc_context_t *context, const eripc_event_info_t *info, void *user_data)
01108 {
01109     LOGPRINTF("entry");
01110     
01111     gboolean result = FALSE;
01112 
01113     if (info->message_id)
01114     {
01115         gboolean  is_inverted = sys_get_pageturn_inverted();
01116         
01117         LOGPRINTF("Sending pageturn_inverted %d", (gint) is_inverted);
01118 
01119         result = eripc_reply_varargs(context, info->message_id, 
01120                                       ERIPC_TYPE_BOOL, is_inverted, 
01121                                       ERIPC_TYPE_INVALID);
01122 
01123         if (result != ERIPC_ERROR_SUCCESS) 
01124         {
01125             ERRORPRINTF("Error sending reply to message: %s", eripc_error_string(result));
01126         }
01127     }
01128 }
01129 
01130 
01131 static void cb_sys_get_card_mountpoint(eripc_context_t *context, const eripc_event_info_t *info, void *user_data)
01132 {
01133     LOGPRINTF("entry");
01134     
01135     if (info->message_id)
01136     {
01137         const char* mountpoint = NULL;
01138         if (sys_get_card() == STATE_CARD_MOUNTED) mountpoint = MOUNTPOINT_CARD;
01139 
01140         LOGPRINTF("Sending card mountpoint '%s'", mountpoint ? mountpoint : "NULL");
01141 
01142         gboolean result = eripc_reply_string(context, info->message_id, mountpoint);
01143         if (result != ERIPC_ERROR_SUCCESS) 
01144         {
01145             ERRORPRINTF("Error sending reply to message: %s", eripc_error_string(result));
01146         }
01147     }
01148 }
01149 
01150 
01151 static void cb_sys_get_device_capabilities(eripc_context_t *context, const eripc_event_info_t *info, void *user_data)
01152 {
01153     LOGPRINTF("entry");
01154     
01155     gboolean result = FALSE;
01156 
01157     if (info->message_id)
01158     {
01159         gboolean has_stylus     = FALSE;
01160         gboolean has_wifi       = FALSE;
01161         gboolean has_bluetooth  = FALSE;
01162         gboolean has_3g         = FALSE;
01163         
01164         sys_get_device_capabilities(&has_stylus, &has_wifi, &has_bluetooth, &has_3g);
01165 
01166         LOGPRINTF("Sending device capabilities: stylus %d, wifi %d, bluetooth %d, 3g %d", 
01167                   has_stylus, has_wifi, has_bluetooth, has_3g);
01168 
01169         result = eripc_reply_varargs(context, info->message_id, 
01170                                       ERIPC_TYPE_BOOL, has_stylus,
01171                                       ERIPC_TYPE_BOOL, has_wifi,
01172                                       ERIPC_TYPE_BOOL, has_bluetooth,
01173                                       ERIPC_TYPE_BOOL, has_3g,
01174                                       ERIPC_TYPE_INVALID);
01175 
01176         if (result != ERIPC_ERROR_SUCCESS) 
01177         {
01178             ERRORPRINTF("Error sending reply to message: %s", eripc_error_string(result));
01179         }
01180     }
01181 }
01182 
01183 
01184 /* NOTE:
01185  * sysSetBusyLed is deprecated but currently supported for backward compatibility
01186  * Use sysSetBgBusy/sysResetBgBusy and sysSetBusy/sysResetBusy instead
01187  */
01188 static void cb_sys_set_busy_led(eripc_context_t *context,  const eripc_event_info_t *info, void *user_data)
01189 {
01190     LOGPRINTF("entry");
01191     const eripc_arg_t *arg_array = info->args;
01192 
01193     CHECK_ARG_STRING(0);
01194     gchar *busy_mode = arg_array[0].value.s;
01195     gint sender = sender_from_service(info->service);
01196 
01197     gboolean result = FALSE;
01198     if (g_ascii_strcasecmp(busy_mode, "on") == 0)
01199     {
01200         result = busy_add_foreground(sender, BUSY_DIALOG_NONE, NULL);
01201     }
01202     else if (g_ascii_strcasecmp(busy_mode, "off") == 0)
01203     {
01204         result = busy_remove_foreground(sender);
01205     }
01206     else
01207     {
01208         WARNPRINTF("Unknown busy mode: %s", busy_mode);
01209     }
01210 
01211     ipc_send_reply(context, info->message_id, result);
01212 }
01213 
01214 
01215 static void cb_sys_set_fg_busy(eripc_context_t *context,  const eripc_event_info_t *info, void *user_data)
01216 {
01217     LOGPRINTF("entry");
01218     const eripc_arg_t *arg_array = info->args;
01219 
01220     CHECK_ARG_STRING(0);
01221     gint sender = sender_from_service(info->service);
01222     gchar *busy_mode = arg_array[0].value.s;
01223     gchar *busy_msg  = NULL;
01224     if ((arg_array[1].type == ERIPC_TYPE_STRING) && (arg_array[1].value.s != NULL))
01225     {
01226         busy_msg = arg_array[1].value.s;
01227     }
01228     
01229     gboolean result = FALSE;
01230     if (g_ascii_strcasecmp(busy_mode, "nodialog") == 0)
01231     {
01232         result = busy_add_foreground(sender, BUSY_DIALOG_NONE, NULL);
01233     }
01234     else if (g_ascii_strcasecmp(busy_mode, "delaydialog") == 0)
01235     {
01236         result = busy_add_foreground(sender, BUSY_DIALOG_DELAYED, busy_msg);
01237     }
01238     else if (g_ascii_strcasecmp(busy_mode, "directdialog") == 0)
01239     {
01240         result = busy_add_foreground(sender, BUSY_DIALOG_DIRECT, busy_msg);
01241     }
01242     else
01243     {
01244         WARNPRINTF("Unknown busy mode: %s", busy_mode);
01245     }
01246 
01247     ipc_send_reply(context, info->message_id, result);
01248 }
01249 
01250 
01251 static void cb_sys_reset_fg_busy(eripc_context_t *context,  const eripc_event_info_t *info, void *user_data)
01252 {
01253     LOGPRINTF("entry");
01254     
01255     gboolean result = FALSE;
01256     gint sender = sender_from_service(info->service);
01257 
01258     result = busy_remove_foreground(sender);
01259 
01260     // send message result back to caller
01261     ipc_send_reply(context, info->message_id, result);
01262 }
01263 
01264 
01265 
01266 static void cb_sys_set_bg_busy(eripc_context_t *context,  const eripc_event_info_t *info, void *user_data)
01267 {
01268     LOGPRINTF("entry");
01269     
01270     gboolean result = FALSE;
01271     gint sender = sender_from_service(info->service);
01272 
01273     result = busy_add_background(sender);
01274 
01275     // send message result back to caller
01276     ipc_send_reply(context, info->message_id, result);
01277 }
01278 
01279 
01280 static void cb_sys_reset_bg_busy(eripc_context_t *context,  const eripc_event_info_t *info, void *user_data)
01281 {
01282     LOGPRINTF("entry");
01283     
01284     gboolean result = FALSE;
01285     gint sender = sender_from_service(info->service);
01286 
01287     result = busy_remove_background(sender);
01288 
01289     // send message result back to caller
01290     ipc_send_reply(context, info->message_id, result);
01291 }
01292 
01293 
01294 static void cb_sys_beep(eripc_context_t *context,  const eripc_event_info_t *info, void *user_data)
01295 {
01296     LOGPRINTF("entry");
01297     const eripc_arg_t *arg_array = info->args;
01298 
01299     CHECK_ARG_INT(0);
01300     CHECK_ARG_STRING(1);
01301     gboolean result = sys_set_beeper(arg_array[0].value.i, arg_array[1].value.s);
01302     ipc_send_reply(context, info->message_id, result);
01303 }
01304 
01305 
01306 static void cb_sys_rotate(eripc_context_t *context,  const eripc_event_info_t *info, void *user_data)
01307 {
01308     LOGPRINTF("entry");
01309     const eripc_arg_t *arg_array = info->args;
01310 
01311     CHECK_ARG_STRING(0);
01312     gboolean result = sys_set_orientation(arg_array[0].value.s);
01313     ipc_send_reply(context, info->message_id, result);
01314 }
01315 
01316 
01317 static void cb_sys_lock_sensors(eripc_context_t *context,  const eripc_event_info_t *info, void *user_data)
01318 {
01319     LOGPRINTF("entry");
01320     const eripc_arg_t *arg_array = info->args;
01321 
01322     CHECK_ARG_STRING(0);
01323     gboolean result = sys_set_sensor_lock(arg_array[0].value.s);
01324     ipc_send_reply(context, info->message_id, result);
01325 }
01326 
01327 
01328 static void cb_sys_set_stylus(eripc_context_t *context,  const eripc_event_info_t *info, void *user_data)
01329 {
01330     LOGPRINTF("entry");
01331     const eripc_arg_t *arg_array = info->args;
01332 
01333     CHECK_ARG_STRING(0);
01334     char *stylus_mode = arg_array[0].value.s;
01335     gboolean result = TRUE;
01336     if (g_ascii_strcasecmp(stylus_mode, "enable") == 0)
01337     {
01338         wacom_enable();
01339     }
01340     else if (g_ascii_strcasecmp(stylus_mode, "disable") == 0)
01341     {
01342         wacom_disable();
01343     }
01344     else if (g_ascii_strcasecmp(stylus_mode, "suspend") == 0)
01345     {
01346         wacom_suspend();
01347     }
01348     else if (g_ascii_strcasecmp(stylus_mode, "resume") == 0)
01349     {
01350         wacom_resume();
01351     }
01352     else if (g_ascii_strcasecmp(stylus_mode, "high") == 0)
01353     {
01354         wacom_scan_high();
01355     }
01356     else if (g_ascii_strcasecmp(stylus_mode, "normal") == 0)
01357     {
01358         wacom_scan_normal();
01359     }
01360     else
01361     {
01362         WARNPRINTF("Unknown stylus mode: %s", stylus_mode);
01363         result = FALSE;
01364     }
01365 
01366     ipc_send_reply(context, info->message_id, result);
01367 }
01368 
01369 
01370 static void cb_sys_get_stylus(eripc_context_t *context,  const eripc_event_info_t *info, void *user_data)
01371 {
01372     LOGPRINTF("entry");
01373     
01374     gboolean result = FALSE;
01375 
01376     if (info->message_id)
01377     {
01378         gboolean stylus_enabled = wacom_is_enabled();
01379 
01380         result = eripc_reply_varargs(context, info->message_id, 
01381                                      ERIPC_TYPE_BOOL, stylus_enabled,
01382                                      ERIPC_TYPE_INVALID);
01383 
01384         if (result != ERIPC_ERROR_SUCCESS) 
01385         {
01386             ERRORPRINTF("Error sending reply to message: %s", eripc_error_string(result));
01387         }
01388     }
01389 }
01390 
01391 
01392 static void cb_sys_card_mount(eripc_context_t *context,  const eripc_event_info_t *info, void *user_data)
01393 {
01394     LOGPRINTF("entry");
01395    
01396     const eripc_arg_t *arg_array = NULL;
01397     
01398     gboolean enable_splash = FALSE;
01399     arg_array = info->args;
01400 
01401     g_return_if_fail(arg_array[0].type == ERIPC_TYPE_BOOL);   // is_connected
01402     enable_splash = arg_array[0].value.b ; 
01403 
01404     if ( enable_splash )
01405     {
01406         sys_set_enable_index_splash(TRUE);
01407     }
01408     else 
01409     {
01410         sys_set_enable_index_splash(FALSE);
01411     }
01412 
01413     hal_remount_all_volumes(NULL, NULL);
01414 
01415     // send message result back to caller
01416     ipc_send_reply(context, info->message_id, TRUE);
01417 }
01418 
01419 
01420 static void cb_sys_card_unmount(eripc_context_t *context,  const eripc_event_info_t *info, void *user_data)
01421 {
01422     LOGPRINTF("entry");
01423     
01424     // eject silently
01425     sys_eject_card(TRUE);
01426 
01427     ipc_send_reply(context, info->message_id, TRUE);
01428 }
01429 
01430 
01431 static void cb_sys_standby(eripc_context_t *context,  const eripc_event_info_t *info, void *user_data)
01432 {
01433     LOGPRINTF("entry");
01434 
01435     // send message result back to caller immediately
01436     ipc_send_reply(context, info->message_id, TRUE);
01437     
01438     sys_standby();
01439 }
01440 
01441 
01442 static void cb_sys_shutdown(eripc_context_t *context,  const eripc_event_info_t *info, void *user_data)
01443 {
01444     LOGPRINTF("entry");
01445     
01446     // send message result back to caller immediately
01447     ipc_send_reply(context, info->message_id, TRUE);
01448 
01449     sys_standby();
01450 }
01451 
01452 
01453 static void cb_sys_set_keyboard(eripc_context_t *context,  const eripc_event_info_t *info, void *user_data)
01454 {
01455     LOGPRINTF("entry");
01456     const eripc_arg_t *arg_array = info->args;
01457 
01458     CHECK_ARG_STRING(0);
01459     char *keyboard_mode = arg_array[0].value.s;
01460     
01461     gboolean result = TRUE;
01462     if (g_ascii_strcasecmp(keyboard_mode, "show") == 0)
01463     {
01464         erkeyb_client_show();
01465     }
01466     else if (g_ascii_strcasecmp(keyboard_mode, "hide") == 0)
01467     {
01468         erkeyb_client_hide();
01469     }
01470     else
01471     {
01472         WARNPRINTF("Unknown keyboard mode: %s", keyboard_mode);
01473         result = FALSE;
01474     }
01475 
01476     // send message result back to caller
01477     ipc_send_reply(context, info->message_id, result);
01478 }
01479 
01480 
01481 static void cb_task_start(eripc_context_t *context, const eripc_event_info_t *info, void *user_data)
01482 {
01483     LOGPRINTF("entry");
01484     const eripc_arg_t *arg_array = info->args;
01485 
01486     CHECK_ARG_STRING(0);    // command_line  string, full path to application with arguments
01487     CHECK_ARG_STRING(1);    // working_dir   string, current working directory, or NULL to inherit from sysd
01488     CHECK_ARG_STRING(2);    // label         string, text label shown under icon in popup menu
01489     CHECK_ARG_STRING(3);    // image         string, full path to icon shown in popup menu
01490     gboolean result = task_start(arg_array[0].value.s, 
01491                             arg_array[1].value.s, 
01492                             arg_array[2].value.s,
01493                             arg_array[3].value.s,
01494                             context,
01495                             info->message_id);
01496     // send failure to start task back to caller immediately
01497     // otherwise result is returned asynchronously
01498     if (result == FALSE)
01499     {
01500         ipc_send_reply_task_start(context, info->message_id, 1, NULL);
01501     }
01502 }
01503 
01504 
01505 static void cb_task_stop(eripc_context_t *context, const eripc_event_info_t *info, void *user_data)
01506 {
01507     LOGPRINTF("entry");
01508     const eripc_arg_t *arg_array = info->args;
01509 
01510     CHECK_ARG_STRING(0);    // cmdline, full path to application with arguments
01511     gboolean result = task_stop(arg_array[0].value.s, 
01512                            context,
01513                            info->message_id);
01514     // send failure to start task back to caller immediately
01515     // otherwise result is returned asynchronously
01516     if (result == FALSE)
01517     {
01518         ipc_send_reply(context, info->message_id, FALSE);
01519     }
01520 }
01521 
01522 
01523 static void cb_task_rename(eripc_context_t *context, const eripc_event_info_t *info, void *user_data)
01524 {
01525     LOGPRINTF("entry");
01526     const eripc_arg_t *arg_array = info->args;
01527 
01528     CHECK_ARG_INT(0);       // xid of task
01529     CHECK_ARG_STRING(1);    // new document name
01530     CHECK_ARG_STRING(2);    // new label
01531     gboolean result = task_rename(arg_array[0].value.i, arg_array[1].value.s, arg_array[2].value.s);
01532     ipc_send_reply(context, info->message_id, result);
01533 }
01534 
01535 
01536 static void cb_task_activate(eripc_context_t *context, const eripc_event_info_t *info, void *user_data)
01537 {
01538     LOGPRINTF("entry");
01539     const eripc_arg_t *arg_array = info->args;
01540 
01541     CHECK_ARG_INT(0);
01542     int xid = arg_array[0].value.i;
01543     task_activate_by_xid(xid);
01544     ipc_send_reply(context, info->message_id, TRUE);
01545 }
01546 
01547 
01548 static void cb_open_url(eripc_context_t *context,  const eripc_event_info_t *info, void *user_data)
01549 {
01550     LOGPRINTF("entry");
01551     const eripc_arg_t *arg_array = info->args;
01552 
01553     if (!sys_has_network())
01554     {
01555         LOGPRINTF("Device does not have networking capabilities, browser not started");
01556         ipc_send_reply_task_start(context, info->message_id, 5, NULL);
01557         return;
01558     }
01559 
01560     // [0] url          string, URL to open
01561     // [1] name         string, text label shown under icon in popup menu
01562     // [2] application  string, application name shown in "Back" bar of browser, or NULL to omit this bar
01563     
01564     gboolean result = FALSE;
01565     if ( (arg_array[0].type == ERIPC_TYPE_STRING) && (arg_array[0].value.s != NULL) )
01566     {
01567         const gchar *url = arg_array[0].value.s;
01568         gchar *name = NULL;
01569         gchar *command_line = NULL;
01570 
01571         if (arg_array[1].type == ERIPC_TYPE_STRING)
01572         {
01573             name = arg_array[1].value.s;
01574         }
01575         
01576         if ( (arg_array[2].type == ERIPC_TYPE_STRING) && (arg_array[2].value.s != NULL) )
01577         {
01578             // use embedded flag to pass application name in "Back" bar
01579             command_line = g_strdup_printf("%s %s -e \"%s\" \"%s\"", browser_path, browser_options, arg_array[2].value.s, url);
01580         }
01581         else
01582         {
01583             command_line = g_strdup_printf("%s %s \"%s\"", browser_path, browser_options, url);
01584         }
01585         
01586         if ((name == NULL) || (name[0] == '\0'))
01587         {
01588             // no name given, use URL without protocol
01589             const gchar *seperator = "://";
01590             name = strstr(url, "://");
01591             if (name)
01592             {
01593                 name += strlen(seperator);
01594             }
01595             else
01596             {
01597                 name = (gchar *)url;
01598             }
01599         }
01600 
01601         // TODO: get thumbnail icon to popupmenu folder
01602         result = task_start(command_line, 
01603                             NULL, 
01604                             name,
01605                             "/usr/share/ctb/icon-html-small.png",
01606                             context,
01607                             info->message_id);
01608         
01609         g_free(command_line);
01610     }
01611 
01612     // send failure to start task back to caller immediately
01613     // otherwise result is returned asynchronously
01614     if (result == FALSE)
01615     {
01616         ipc_send_reply_task_start(context, info->message_id, 1, NULL);
01617     }
01618 }
01619 
01620 
01621 static void cb_opened_window(eripc_context_t *context, const eripc_event_info_t *info, void *user_data)
01622 {
01623     LOGPRINTF("entry");
01624     const eripc_arg_t *arg_array = info->args;
01625 
01626     CHECK_ARG_STRING(0);    // application   string, name of the application
01627     CHECK_ARG_STRING(1);    // document      string, document (should be unqiue)
01628     CHECK_ARG_STRING(2);    // label         string, text label shown under icon in popup menu
01629     CHECK_ARG_STRING(3);    // image         string, full path to icon shown in popup menu (png, 60x60 pixels)
01630     CHECK_ARG_STRING(4);    // service       string, IPC service name of the application
01631     CHECK_ARG_INT(5);       // pid           integer, process id
01632     CHECK_ARG_INT(6);       // window        integer, window ID (XID)
01633     gboolean result = task_add(arg_array[0].value.s, 
01634                           arg_array[1].value.s, 
01635                           arg_array[2].value.s,
01636                           arg_array[3].value.s,
01637                           arg_array[4].value.s,
01638                           arg_array[5].value.i,
01639                           arg_array[6].value.i);
01640     ipc_send_reply(context, info->message_id, result);
01641 }
01642 
01643 
01644 static void cb_menu_request_popup(eripc_context_t *context, const eripc_event_info_t *info, void *user_data)
01645 {
01646     LOGPRINTF("entry");
01647     const eripc_arg_t *arg_array = info->args;
01648 
01649     CHECK_ARG_STRING(0);
01650     gboolean result = sys_request_popup(arg_array[0].value.s);
01651     ipc_send_reply(context, info->message_id, result);
01652 }
01653 
01654 
01655 
01656 static void cb_menu_item_activated(eripc_context_t *context, const eripc_event_info_t *info, void *user_data)
01657 {
01658     LOGPRINTF("entry");
01659     const eripc_arg_t *arg_array = info->args;
01660 
01661     CHECK_ARG_STRING(0);
01662     CHECK_ARG_STRING(1);
01663     CHECK_ARG_STRING(2);
01664     CHECK_ARG_STRING(3);
01665     const char *item  = arg_array[0].value.s;
01666     const char *group = arg_array[1].value.s;
01667     //const char *menu  = arg_array[2].value.s;
01668     const char *state = arg_array[3].value.s;
01669 
01670     gboolean result = FALSE;
01671     if (g_ascii_strcasecmp(group, "general") == 0)
01672     {
01673         if (g_ascii_strcasecmp(item, "desktop") == 0)
01674         {
01675             LOGPRINTF("gotoLocation desktop");
01676             ipc_ctb_goto("desktop");
01677             process_activate("ctb");
01678             result = TRUE;
01679         }
01680         else if (g_ascii_strcasecmp(item, "rotate_screen") == 0)
01681         {
01682             LOGPRINTF("rotate_screen");
01683             result = sys_set_orientation("toggle");
01684         }
01685         else if (g_ascii_strcasecmp(item, "lock") == 0)
01686         {
01687             LOGPRINTF("lock");
01688             if (g_ascii_strcasecmp(state, "normal") == 0)
01689             {
01690                 result = sys_set_sensor_lock("lock");
01691             }
01692             else if (g_ascii_strcasecmp(state, "selected") == 0)
01693             {
01694                 result = sys_set_sensor_lock("unlock");
01695             }
01696         }
01697         else if (g_ascii_strcasecmp(item, "eject_card") == 0)
01698         {
01699             LOGPRINTF("eject_card");
01700             sys_eject_card(FALSE);
01701             result = TRUE;
01702         }
01703         else if (g_ascii_strcasecmp(item, "shutdown") == 0)
01704         {
01705             LOGPRINTF("shutdown");
01706             sys_standby();
01707             result = TRUE;
01708         }
01709         else
01710         {
01711             WARNPRINTF("Unknown general item: %s", item);
01712         }
01713     }
01714     else if (g_ascii_strcasecmp(group, "tasks") == 0)
01715     {
01716         LOGPRINTF("tasks");
01717         
01718         if (g_ascii_strcasecmp(item, "back_to_library") == 0)
01719         {
01720             process_activate("ctb");
01721             result = TRUE;
01722         }
01723         else 
01724         {
01725             // activate task and return result immediately
01726             result = task_activate(item);
01727         }
01728     }
01729 
01730     ipc_send_reply(context, info->message_id, result);
01731 }
01732 
01733 
01734 static void cb_status_item_activated(eripc_context_t *context, const eripc_event_info_t *info, void *user_data)
01735 {
01736     LOGPRINTF("entry");
01737     const eripc_arg_t *arg_array = info->args;
01738 
01739     CHECK_ARG_STRING(0);    // name of activated status item
01740     CHECK_ARG_STRING(1);    // state of activated status item
01741 
01742     const gchar *name = arg_array[0].value.s;
01743     // const gchar *status = arg_array[1].value.s;
01744     LOGPRINTF("name [%s] status [%s]", name, arg_array[1].value.s);
01745     
01746     if (strcmp(name, "statusbar_downloadmgr") == 0)
01747     {
01748         LOGPRINTF("downloadmgr clicked, try to activate Adobe fulfillment");
01749         
01750         // When adobe-fulfill is running, activate it
01751         // Otherwise, start downloadmgr or activate it when it is running
01752         if (task_activate(ade_fulfill_path))
01753         {
01754             LOGPRINTF("ADE fulfillment activated");
01755         }
01756         else
01757         {
01758             LOGPRINTF("ADE fulfillment is not activated, try to activate downloadmgr");
01759             
01760             if (task_activate(downloadmgr_path))
01761             {
01762                 // special call to unhide dowloadmgr window
01763                 ipc_send_window_show("com.irexnet.downloadmgr", 0);
01764                 
01765                 LOGPRINTF("downloadmgr activated");
01766             }
01767             else 
01768             {
01769                 if (task_start(downloadmgr_path, NULL, "DownloadMgr", NULL, NULL, NULL))
01770                 {
01771                     LOGPRINTF("downloadmgr started");
01772                 }
01773                 else
01774                 {
01775                     WARNPRINTF("failed to start downloadmgr");
01776                 }
01777             }
01778         }
01779     }
01780     else if (   strcmp(name, "statusbar_wifi"     ) == 0
01781              || strcmp(name, "statusbar_bluetooth") == 0
01782              || strcmp(name, "statusbar_3g"       ) == 0 )
01783     {
01784         conn_on_statusitem_activated();
01785     }
01786     
01787     // don't return reply for signals
01788 }
01789 
01790 
01791 static void cb_startup_complete(eripc_context_t *context, const eripc_event_info_t *info, void *user_data)
01792 {
01793     LOGPRINTF("entry");
01794     const eripc_arg_t *arg_array = info->args;
01795 
01796     CHECK_ARG_STRING(0);    // name           string, name of application
01797     CHECK_ARG_INT(1);       // pid            integer, process id
01798     CHECK_ARG_BOOL(2);      // is_multidoc    boolean, application can open/close documents over IPC
01799     CHECK_ARG_STRING(3);    // ipc_service    string, IPC service name (may be NULL when is_multidoc is false)
01800                             // xid            integer, window id
01801     gint xid = 0;
01802     if (arg_array[4].type == ERIPC_TYPE_INT)
01803     {
01804         xid =  arg_array[4].value.i;
01805     }
01806     LOGPRINTF("name [%s] pid [%d] is_multidoc [%d] ipc_service [%s], window [%d]",
01807                 arg_array[0].value.s,
01808                 arg_array[1].value.i,
01809                 arg_array[2].value.b,
01810                 arg_array[3].value.s,
01811                 xid);
01812 
01813     // save sender's pid
01814     busy_set_pid(sender_from_service(info->service), arg_array[1].value.i);
01815     process_startup_complete(arg_array[0].value.s, arg_array[1].value.i, arg_array[2].value.b, arg_array[3].value.s, xid);
01816     // don't return reply for signals
01817 }
01818 
01819 
01820 static void cb_closed_window(eripc_context_t *context, const eripc_event_info_t *info, void *user_data)
01821 {
01822     LOGPRINTF("entry");
01823     const eripc_arg_t *arg_array = info->args;
01824 
01825     gboolean result = FALSE;
01826 
01827     CHECK_ARG_INT(0);
01828     if (arg_array[0].value.i > 0)
01829     {
01830         result = task_cleanup_window(arg_array[0].value.i);
01831     }
01832 
01833     ipc_send_reply(context, info->message_id, result);
01834 }
01835 
01836 
01837 static void cb_conn_connect(eripc_context_t *context, const eripc_event_info_t *info, void *user_data)
01838 {
01839     LOGPRINTF("entry");
01840     const eripc_arg_t *arg_array = info->args;
01841     
01842     CHECK_ARG_STRING(0);    // ipc service
01843     CHECK_ARG_STRING(1);    // medium
01844     CHECK_ARG_STRING(2);    // profile
01845 
01846     gchar *service = arg_array[0].value.s;
01847     gchar *medium  = arg_array[1].value.s;
01848     gchar *profile = arg_array[2].value.s;
01849     
01850     LOGPRINTF("MACHINE_NAME [" MACHINE_NAME "] medium [%s]", medium);
01851     if (!medium || (medium[0]==0))
01852     {
01853 #if MACHINE_IS_DR1000SW
01854         medium = "wifi";
01855 #elif MACHINE_IS_DR800SG
01856         medium = "3g";
01857 #else
01858         WARNPRINTF("no connectivity for MACHINE_NAME [" MACHINE_NAME "]");
01859         ipc_send_reply(context, info->message_id, FALSE);
01860         return;
01861 #endif
01862     }    
01863 
01864     gboolean result = conn_connect(service, medium, profile);
01865     ipc_send_reply(context, info->message_id, result);
01866 }
01867 
01868 
01869 static void cb_conn_disconnect(eripc_context_t *context, const eripc_event_info_t *info, void *user_data)
01870 {
01871     LOGPRINTF("entry");
01872     const eripc_arg_t *arg_array = info->args;
01873 
01874     CHECK_ARG_STRING(0);
01875     gboolean result = conn_disconnect(arg_array[0].value.s);
01876     ipc_send_reply(context, info->message_id, result);
01877 }
01878 
01879 
01880 static void cb_conn_status(eripc_context_t *context, const eripc_event_info_t *info, void *user_data)
01881 {
01882     LOGPRINTF("entry");
01883     const eripc_arg_t *arg_array = info->args;
01884 
01885     CHECK_ARG_BOOL(0);      // is_connected
01886     CHECK_ARG_STRING(1);    // medium
01887     CHECK_ARG_STRING(2);    // profile
01888     CHECK_ARG_STRING(2);    // reason (disconnect only)
01889 
01890     gboolean result = conn_set_status( arg_array[0].value.b,
01891                               arg_array[1].value.s,
01892                               arg_array[2].value.s,
01893                               arg_array[3].value.s );
01894     ipc_send_reply(context, info->message_id, result);
01895 }
01896 
01897 
01898 static void cb_conn_status_request(eripc_context_t *context, const eripc_event_info_t *info, void *user_data)
01899 {
01900     LOGPRINTF("entry");
01901     const eripc_arg_t *arg_array = info->args;
01902 
01903     CHECK_ARG_STRING(0);
01904     gboolean result = conn_status_request(arg_array[0].value.s);
01905     ipc_send_reply(context, info->message_id, result);
01906 }
01907 
01908 
01909 static void cb_conn_signal(eripc_context_t *context, const eripc_event_info_t *info, void *user_data)
01910 {
01911     LOGPRINTF("entry");
01912     const eripc_arg_t *arg_array = info->args;
01913 
01914     CHECK_ARG_INT(0);       // strength
01915     CHECK_ARG_STRING(1);    // medium
01916 
01917     ipc_broadcast_conn_signal(arg_array[1].value.s, arg_array[0].value.i);
01918     ipc_send_reply(context, info->message_id, TRUE);
01919 }
01920 
01921 
01922 static void cb_conn_add_profile(eripc_context_t *context, const eripc_event_info_t *info, void *user_data)
01923 {
01924     LOGPRINTF("entry");
01925     const eripc_arg_t *arg_array = info->args;
01926 
01927     CHECK_ARG_STRING(0); 
01928     gboolean result = conn_add_profile(arg_array[0].value.s);
01929     ipc_send_reply(context, info->message_id, result);
01930 }
01931 
01932 
01933 static void cb_conn_edit_profile(eripc_context_t *context, const eripc_event_info_t *info, void *user_data)
01934 {
01935     LOGPRINTF("entry");
01936     const eripc_arg_t *arg_array = info->args;
01937 
01938     CHECK_ARG_STRING(0);    // connection medium
01939     CHECK_ARG_STRING(1);    // network profile
01940     gboolean result = conn_edit_profile(arg_array[0].value.s, arg_array[1].value.s);
01941     ipc_send_reply(context, info->message_id, result);
01942 }
01943 
01944 
01945 static void on_confirm_usbconnect(eripc_context_t *context,
01946                                   const eripc_event_info_t *info,
01947                                   void *user_data)
01948 {
01949     LOGPRINTF("entry");
01950     const eripc_arg_t *arg_array = info->args;
01951 
01952     if (info->event_type != ERIPC_EVENT_REPLY)
01953     {
01954         WARNPRINTF("invalid event: %d", info->event_type);
01955     }
01956     else if ((arg_array == NULL) || (arg_array[0].type != ERIPC_TYPE_BOOL))
01957     {
01958         WARNPRINTF("invalid arguments in reply");
01959     }
01960     else if (arg_array[0].value.b == TRUE)
01961     {
01962         LOGPRINTF("User confirmed connect");
01963         // handle connect
01964         sys_usb_connect();
01965     }
01966     else
01967     {
01968         sys_usb_no_connect();
01969     }
01970 }
01971 
01972 
01973 static void on_confirm_install_update(eripc_context_t *context,
01974                                       const eripc_event_info_t *info,
01975                                       void *user_data)
01976 {
01977     LOGPRINTF("entry");
01978     const eripc_arg_t *arg_array = info->args;
01979 
01980     if (info->event_type != ERIPC_EVENT_REPLY)
01981     {
01982         WARNPRINTF("invalid event: %d", info->event_type);
01983     }
01984     else if ((arg_array == NULL) || (arg_array[0].type != ERIPC_TYPE_BOOL))
01985     {
01986         WARNPRINTF("invalid arguments in reply");
01987     }
01988     else if (arg_array[0].value.b == TRUE)
01989     {
01990         LOGPRINTF("User confirmed restart to install firmware update");
01991 
01992         // handle shutdown and cold restart to trigger install procedure
01993         sys_restart();
01994     }
01995 }
01996 
01997 
01998 static void on_confirm_install_drz(eripc_context_t *context,
01999                                    const eripc_event_info_t *info,
02000                                    void *user_data)
02001 {
02002     LOGPRINTF("entry");
02003     
02004     const eripc_arg_t *arg_array = info->args;
02005     
02006     if (info->event_type != ERIPC_EVENT_REPLY)
02007     {
02008         WARNPRINTF("invalid event: %d", info->event_type);
02009     }
02010     else if ((arg_array == NULL) || (arg_array[0].type != ERIPC_TYPE_BOOL))
02011     {
02012         WARNPRINTF("invalid arguments in reply");
02013     }
02014     else if (arg_array[0].value.b == TRUE)
02015     {
02016         LOGPRINTF("User confirmed to install drz");
02017         sys_install_drz();
02018     }
02019 }
02020 
02021 
02022 static void testing_list_tasks(eripc_context_t *context,
02023                                const eripc_event_info_t *info,
02024                                void *user_data)
02025 {
02026 #if (TESTING_ON)
02027     print_window_list();
02028     print_process_list();
02029     print_task_list();
02030 #endif
02031     char* list = testing_task_get_list();
02032     eripc_reply_string(context, info->message_id, list);
02033     g_free(list);
02034 }
02035 
02036 
02037 static const gchar *medium_service(const char *medium)
02038 {
02039     if (medium)
02040     {
02041         if (strcmp(medium, "wifi") == 0)
02042         {
02043             return DBUS_SERVICE_CONN_WIFI;
02044         }
02045         else if (strcmp(medium, "bluetooth") == 0)
02046         {
02047             return DBUS_SERVICE_CONN_BLUE;
02048         }
02049         else if (strcmp(medium, "3g") == 0)
02050         {
02051             return DBUS_SERVICE_CONN_3G;
02052         }
02053     }
02054     return NULL;
02055 }
02056 
02057 
02058 static gint sender_from_service(const char *service)
02059 {
02060     gint sender = 0;
02061     gchar *dot = strchr(service, '.');
02062     if (dot) 
02063     {
02064        sender = atoi(dot + 1);
02065     }
02066     return sender;
02067 }
02068 
02069 
02070 void ipc_send_window_deactivated(const char *ipc_interface,  gint window)
02071 {
02072     LOGPRINTF("entry");
02073 
02074     eripc_error_t retval;
02075     retval = eripc_send_int(eripcClient->context,
02076                             NULL,
02077                             NULL,
02078                             ERIPC_BUS_SESSION,
02079                             ipc_interface,
02080                             "deactivatedWindow",
02081                             window);
02082 
02083     if (retval != ERIPC_ERROR_SUCCESS)
02084     {
02085         ERRORPRINTF("Error launching eripc handler: %s", eripc_error_string(retval));
02086     }
02087 }
02088 
02089 
02090 void ipc_send_window_activated(const char *ipc_interface, gint window)
02091 {
02092     LOGPRINTF("entry");
02093 
02094     eripc_error_t retval;
02095     retval = eripc_send_int(eripcClient->context,
02096                             NULL,
02097                             NULL,
02098                             ERIPC_BUS_SESSION,
02099                             ipc_interface,
02100                             "activatedWindow",
02101                             window);
02102 
02103     if (retval != ERIPC_ERROR_SUCCESS)
02104     {
02105         ERRORPRINTF("Error launching eripc handler: %s", eripc_error_string(retval));
02106     }
02107 }
02108 
Generated by  doxygen 1.6.2-20100208