hello-world/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 hello-world.
00007  *
00008  * hello-world 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  * hello-world 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) 2009 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 <stdio.h>
00035 #include <stdlib.h>
00036 #include <gdk/gdkx.h>
00037 #include <sys/types.h>
00038 #include <unistd.h>
00039 
00040 // ereader include files, between < >
00041 #include <liberipc/eripc.h>
00042 #include <liberipc/eripc_support.h>
00043 
00044 // local include files, between " "
00045 #include "log.h"
00046 #include "i18n.h"
00047 #include "ipc.h"
00048 #include "main.h"
00049 #include "menu.h"
00050 
00051 
00052 //----------------------------------------------------------------------------
00053 // Type Declarations
00054 //----------------------------------------------------------------------------
00055 
00056 //----------------------------------------------------------------------------
00057 // Constants
00058 //----------------------------------------------------------------------------
00059 
00060 // IPC application
00061 // TODO: set DBUS_APPL_NAME to your application name, use lower-case and digits only
00062 //       or set to PACKAGENAME when this is lower-case and digits only
00063 #define DBUS_APPL_NAME                  "helloworld"            // lower-case and digits only
00064 #define DBUS_SERVICE                     "com.irexnet." DBUS_APPL_NAME
00065 #define DBUS_PATH                       "/com/irexnet/" DBUS_APPL_NAME
00066 #define DBUS_INTERFACE                   "com.irexnet." DBUS_APPL_NAME
00067 
00068 // IPC system control
00069 #define DBUS_SERVICE_SYSTEM_CONTROL     "com.irexnet.sysd"
00070 
00071 // IPC popup menu
00072 #define DBUS_SERVICE_POPUP_MENU         "com.irexnet.popupmenu"
00073 
00074 
00075 //----------------------------------------------------------------------------
00076 // Static Variables
00077 //----------------------------------------------------------------------------
00078 
00079 static eripc_client_context_t *eripcClient = NULL;
00080 
00081 //============================================================================
00082 // Local Function Definitions
00083 //============================================================================
00084 
00085 static void on_menu_item         ( eripc_context_t          *context,
00086                                    const eripc_event_info_t *info,
00087                                    void                     *user_data );
00088                                  
00089 static void on_mounted           ( eripc_context_t          *context,
00090                                    const eripc_event_info_t *info,
00091                                    void                     *user_data );
00092                                  
00093 static void on_file_open         ( eripc_context_t          *context,
00094                                    const eripc_event_info_t *info,
00095                                    void                     *user_data );
00096                                  
00097 static void on_file_close        ( eripc_context_t          *context,
00098                                    const eripc_event_info_t *info,
00099                                    void                     *user_data );
00100                                  
00101 static void on_window_activated  ( eripc_context_t          *context,
00102                                    const eripc_event_info_t *info,
00103                                    void                     *user_data );
00104                                  
00105 static void on_window_deactivated( eripc_context_t          *context,
00106                                    const eripc_event_info_t *info,
00107                                    void                     *user_data );
00108                                  
00109 static void on_prepare_unmount   ( eripc_context_t          *context,
00110                                    const eripc_event_info_t *info,
00111                                    void                     *user_data );
00112                                  
00113 static void on_unmounted         ( eripc_context_t          *context,
00114                                    const eripc_event_info_t *info,
00115                                    void                     *user_data );
00116 
00117 static void on_prepare_standby   ( eripc_context_t          *context,
00118                                    const eripc_event_info_t *info,
00119                                    void                     *user_data );
00120 
00121 static void on_changed_locale    ( eripc_context_t          *context,
00122                                    const eripc_event_info_t *info,
00123                                    void                     *user_data );
00124 
00125 static void on_changed_orientation(eripc_context_t          *context,
00126                                    const eripc_event_info_t *info,
00127                                    void                     *user_data );
00128 
00129 static void on_page_change               (eripc_context_t *context,
00130                                           const eripc_event_info_t *info,
00131                                           void *user_data);
00132 
00133 static void on_sys_changed_pageturn_inverted (eripc_context_t *context,
00134                                           const eripc_event_info_t *info,
00135                                           void *user_data);
00136 
00137 
00138 // Exported DBUS API list
00139 static eripc_callback_function_t service_functions[] = {
00140     // message handlers (method calls to this service)
00141     { on_menu_item,           "menuItemActivated",      NULL                       , 0 },
00142     { on_mounted,             "sysVolumeMounted",       NULL                       , 0 },
00143     { on_file_open,           "openFile",               NULL                       , 0 },
00144     { on_file_close,          "closeFile",              NULL                       , 0 },
00145     { on_window_activated,    "activatedWindow",        NULL                       , 0 },
00146     { on_window_deactivated,  "deactivatedWindow",      NULL                       , 0 },
00147     // signal handlers (broadcasted from given service)
00148     { on_mounted,             "sysVolumeMounted",       DBUS_SERVICE_SYSTEM_CONTROL, 0 },
00149     { on_prepare_unmount,     "sysPrepareUnmount",      DBUS_SERVICE_SYSTEM_CONTROL, 0 },
00150     { on_unmounted,           "sysVolumeUnmounted",     DBUS_SERVICE_SYSTEM_CONTROL, 0 },
00151     { on_prepare_standby,     "sysPrepareStandby",      DBUS_SERVICE_SYSTEM_CONTROL, 0 },
00152     { on_changed_locale,      "sysChangedLocale",       DBUS_SERVICE_SYSTEM_CONTROL, 0 },
00153     { on_changed_orientation, "sysChangedOrientation",  DBUS_SERVICE_SYSTEM_CONTROL, 0 },
00154     { on_page_change,         "pageChange",             NULL                       , 0 },
00155     { on_sys_changed_pageturn_inverted, "sysChangedPageturnInverted", DBUS_SERVICE_SYSTEM_CONTROL , 0},
00156     { NULL, NULL, NULL, 0 }
00157 };
00158 
00159 
00160 //============================================================================
00161 // Functions Implementation
00162 //============================================================================
00163 
00164 
00165 //----------------------------------------------------------------------------
00166 // Generic
00167 //----------------------------------------------------------------------------
00168 
00169 // initialise
00170 void ipc_set_services (void)
00171 {
00172     eripcClient = eripc_client_context_new(
00173                     DBUS_APPL_NAME, 
00174                     "1.0",
00175                     DBUS_SERVICE, 
00176                     DBUS_PATH,
00177                     DBUS_INTERFACE,
00178                     service_functions);
00179 }
00180 
00181 
00182 // un-initialise
00183 void ipc_unset_services (void)
00184 {
00185     eripc_client_context_free(eripcClient, service_functions);
00186 }
00187 
00188 
00189 //----------------------------------------------------------------------------
00190 // System control
00191 //----------------------------------------------------------------------------
00192 
00193 // report "application started"
00194 void ipc_sys_startup_complete ( void )
00195 {
00196     const int xid = GDK_WINDOW_XID(g_main_window->window);
00197     eripc_sysd_startup_complete( eripcClient, getpid(), TRUE, xid);
00198 }
00199 
00200 
00201 // start task (application)
00202 gint ipc_sys_start_task ( const gchar  *cmd_line,
00203                           const gchar  *work_dir,
00204                           const gchar  *label,
00205                           const gchar  *thumbnail_path,
00206                           gchar        **err_message )
00207 {
00208     LOGPRINTF("entry: cmd_line [%s] work_dir [%s] label [%s] thumbnail_path [%s]",
00209                        cmd_line,     work_dir,     label,     thumbnail_path       );
00210     g_assert( cmd_line && *cmd_line );
00211     return eripc_sysd_start_task( eripcClient, 
00212                                   cmd_line, 
00213                                   work_dir, 
00214                                   label, 
00215                                   thumbnail_path, 
00216                                   err_message);
00217 }
00218 
00219 
00220 // stop task (application)
00221 gboolean ipc_sys_stop_task ( const gchar  *cmd_line )
00222 {
00223     LOGPRINTF("entry: cmd_line [%s]", cmd_line );
00224     g_assert( cmd_line && *cmd_line );
00225     return eripc_sysd_stop_task( eripcClient, cmd_line );
00226 }
00227 
00228 
00229 //----------------------------------------------------------------------------
00230 // Popup menu
00231 //----------------------------------------------------------------------------
00232 
00233 // add a menu set
00234 gboolean ipc_menu_add_menu( const char *name,
00235                             const char *group1,
00236                             const char *group2,
00237                             const char *group3 )
00238 {
00239     return eripc_menu_add_menu(eripcClient, name, group1, group2, group3, "");
00240 }
00241 
00242 
00243 // add a menu group
00244 gboolean ipc_menu_add_group( const char *name,
00245                              const char *parent, 
00246                              const char *image )
00247 {
00248     return eripc_menu_add_group(eripcClient, name, parent, image);
00249 }
00250 
00251 
00252 // add a menu item
00253 gboolean ipc_menu_add_item( const char *name,
00254                             const char *parent, 
00255                             const char *image  )
00256 {
00257     return eripc_menu_add_item(eripcClient, name, parent, image);
00258 }
00259 
00260 
00261 // set text for a menu set
00262 gboolean ipc_menu_set_menu_label ( const char *name,
00263                                    const char *label )
00264 {
00265     return eripc_menu_set_menu_label(eripcClient, name, label);
00266 }
00267 
00268 
00269 // set text for a menu group
00270 gboolean ipc_menu_set_group_label ( const char *name,
00271                                     const char *label )
00272 {
00273     return eripc_menu_set_group_label(eripcClient, name, label);
00274 }
00275 
00276 
00277 // set text for an menu item
00278 gboolean ipc_menu_set_item_label ( const char *name,
00279                                    const char *parent, 
00280                                    const char *label )
00281 {
00282     return eripc_menu_set_item_label(eripcClient, name, parent, label);
00283 }
00284 
00285 
00286 // show the given menu set
00287 gboolean ipc_menu_show_menu( const char *name )
00288 {
00289     return eripc_menu_show_menu(eripcClient, name);
00290 }
00291 
00292 
00293 // remove the given menu set
00294 gboolean ipc_remove_menu( const char *name )
00295 {
00296     return eripc_menu_remove_menu(eripcClient, name);
00297 }
00298 
00299 
00300 // set the state of a menu group
00301 gboolean ipc_menu_set_group_state( const char *name,
00302                                    const char *state )
00303 {
00304     return eripc_menu_set_group_state(eripcClient, name, state);
00305 }
00306 
00307 
00308 // set the state of a menu item
00309 gboolean ipc_menu_set_item_state( const char *name,
00310                                   const char *parent,
00311                                   const char *state  )
00312 {
00313     return eripc_menu_set_item_state(eripcClient, name, parent, state);
00314 }
00315 
00316 
00317 // set busy indication
00318 gboolean ipc_sys_busy( gboolean look_busy )
00319 {
00320     if (look_busy)
00321         return eripc_sysd_set_busy(eripcClient, "delaydialog", NULL);
00322     else
00323         return eripc_sysd_reset_busy(eripcClient);
00324 }
00325 
00326 
00327 //============================================================================
00328 // Local Function Implementation
00329 //============================================================================
00330 
00331 //----------------------------------------------------------------------------
00332 // Signal/message handlers
00333 //----------------------------------------------------------------------------
00334 
00335 /* @brief Called when a menu items is activated in Popup menu
00336  *
00337  * Application (callee) should handle the item depending on the current state.
00338  */
00339 static void on_menu_item ( eripc_context_t          *context,
00340                            const eripc_event_info_t *info,
00341                            void                     *user_data )
00342 {
00343     LOGPRINTF("entry");
00344     const eripc_arg_t *arg_array = info->args;
00345 
00346     if ((arg_array[0].type == ERIPC_TYPE_STRING) && 
00347         (arg_array[1].type == ERIPC_TYPE_STRING) && 
00348         (arg_array[2].type == ERIPC_TYPE_STRING) && 
00349         (arg_array[3].type == ERIPC_TYPE_STRING))
00350     {
00351         const char        *item      = arg_array[0].value.s;
00352         const char        *group     = arg_array[1].value.s;
00353         const char        *menu      = arg_array[2].value.s;
00354         const char        *state     = arg_array[3].value.s;
00355         
00356         if (item && group && menu && state)
00357         {
00358             menu_on_item_activated( item, group, menu, state );
00359         }
00360     }
00361 }
00362 
00363 
00364 /* @brief Called after a window was activated (set to the foreground)
00365  *
00366  * Application (callee) should set its context for the given window and set the 
00367  * Popupmenu menu context.
00368  */
00369 static void on_window_activated( eripc_context_t          *context,
00370                                  const eripc_event_info_t *info,
00371                                  void                     *user_data )
00372 {
00373     LOGPRINTF("entry");
00374     gchar             *msg        = NULL;
00375     gboolean          result      = FALSE; 
00376     const eripc_arg_t *arg_array  = info->args;
00377 
00378     if (arg_array[0].type == ERIPC_TYPE_INT)
00379     {
00380         // TODO: Replace implementation
00381 
00382         gint window = arg_array[0].value.i;
00383         
00384         menu_show();
00385 
00386         msg = g_strdup_printf("Window activated: %d", window);
00387         gtk_label_set_text( GTK_LABEL(g_action), msg);
00388         LOGPRINTF("%s", msg);
00389         g_free(msg);
00390         
00391         result = TRUE;
00392     }
00393 
00394     // return result to caller
00395     eripc_reply_bool(context, info->message_id, result);
00396 }
00397 
00398 
00399 /* @brief Called after a window was deactivated (set to the background)
00400  *
00401  * Application (callee) may adapt its context and free resources.
00402  */  
00403 static void on_window_deactivated( eripc_context_t          *context,
00404                                    const eripc_event_info_t *info,
00405                                    void                     *user_data )
00406 {
00407     LOGPRINTF("entry");
00408     gchar             *msg        = NULL;
00409     gboolean          result      = FALSE; 
00410     const eripc_arg_t *arg_array  = info->args;
00411 
00412     if (arg_array[0].type == ERIPC_TYPE_INT)
00413     {
00414         // TODO: Replace implementation
00415 
00416         gint window = arg_array[0].value.i;
00417         
00418         msg = g_strdup_printf("Window deactivated: %d", window);
00419         gtk_label_set_text( GTK_LABEL(g_action), msg);
00420         LOGPRINTF("%s", msg);
00421         g_free(msg);
00422         
00423         result = TRUE;
00424     }
00425     
00426     // return result to caller
00427     eripc_reply_bool(context, info->message_id, result);
00428 
00429     // and close application
00430     main_quit();
00431 }
00432 
00433 
00434 /* @brief Called when a file, document or url is to be opened by the application
00435  *
00436  * Application (callee) should create and realise, or reuse an existing window 
00437  * for the given file and return the X window id in the method reply. The X window 
00438  * can be obtained using GDK_WINDOW_XID(widget->window). When the file is already 
00439  * opened by the callee, it may just return its X window id. This call implies that
00440  * the window is activated (set to the foreground) so callee should also set its 
00441  * context for the given window and set the Popupmenu menu context. 
00442  * System Daemon adds a task to Task Manager of Popupmenu, or replaces the task 
00443  * when an existing window is returned.
00444  */
00445 static void on_file_open ( eripc_context_t          *context,
00446                            const eripc_event_info_t *info,
00447                            void                     *user_data )
00448 {
00449     LOGPRINTF("entry");
00450     gchar             *msg        = NULL;
00451     gchar             *error_msg  = NULL;
00452     gint              my_xid      = -1; 
00453 
00454     const eripc_arg_t *arg_array  = info->args;
00455     
00456     if (arg_array[0].type == ERIPC_TYPE_STRING)
00457     {
00458         const char *file = arg_array[0].value.s;
00459         if (file)
00460         {
00461             // TODO: Replace implementation
00462 
00463             msg = g_strdup_printf("File to open: %s", file);
00464             gtk_label_set_text( GTK_LABEL(g_action), msg);
00465             LOGPRINTF("%s", msg);
00466             g_free(msg);
00467             
00468             // TODO: Replace implementation
00469 
00470             gboolean success = TRUE;
00471             
00472             if (success) 
00473             {
00474                 my_xid = GDK_WINDOW_XID(g_main_window->window);
00475                 menu_show();
00476             }
00477             else
00478             {
00479                 error_msg = g_strdup_printf(_("Error opening '%s'"), file);
00480             }
00481         }
00482     }
00483     
00484     // return result to caller
00485     eripc_reply_varargs(context, info->message_id, 
00486                         ERIPC_TYPE_INT, my_xid,
00487                         ERIPC_TYPE_STRING, error_msg,
00488                         ERIPC_TYPE_INVALID);
00489     g_free(error_msg);
00490 }
00491 
00492 
00493 /* @brief Called when a file, document or url is to be closed by the application
00494  *
00495  * Application (callee) should close the file and may destroy its window and free 
00496  * other resources. System Daemon removes the task from the Task Manager of Popupmenu.
00497  */
00498 static void on_file_close ( eripc_context_t          *context,
00499                             const eripc_event_info_t *info,
00500                             void                     *user_data )
00501 {
00502     LOGPRINTF("entry");
00503     gchar             *msg        = NULL;
00504     gboolean          result      = FALSE; 
00505     const eripc_arg_t *arg_array  = info->args;
00506     
00507     if (arg_array[0].type == ERIPC_TYPE_STRING)
00508     {
00509         const char *file = arg_array[0].value.s;
00510         if (file)
00511         {
00512             // TODO: Replace implementation
00513 
00514             msg = g_strdup_printf("File to close: %s", file);
00515             gtk_label_set_text( GTK_LABEL(g_action), msg);
00516             LOGPRINTF("%s", msg);
00517             g_free(msg);
00518             
00519             result = TRUE;
00520         }
00521     }
00522     
00523     // return result to caller
00524     eripc_reply_bool(context, info->message_id, result);
00525 }
00526 
00527 
00528 /* @brief Called just after a volume is mounted
00529  *
00530  * Application may use this to add/open the new volume.
00531  */
00532 static void on_mounted ( eripc_context_t          *context,
00533                          const eripc_event_info_t *info,
00534                          void                     *user_data )
00535 {
00536     LOGPRINTF("entry");
00537     gchar             *msg        = NULL;
00538     const eripc_arg_t *arg_array  = info->args;
00539 
00540     if (arg_array[0].type == ERIPC_TYPE_STRING)
00541     {
00542         const char *mountpoint = arg_array[0].value.s;
00543         if (mountpoint)
00544         {
00545             // TODO: Replace implementation
00546             
00547             g_free(g_mountpoint);
00548             g_mountpoint = g_strdup(mountpoint);
00549             
00550             msg = g_strdup_printf("Device mounted: %s", mountpoint);
00551             gtk_label_set_text( GTK_LABEL(g_volume), msg);
00552             LOGPRINTF("%s", msg);
00553             g_free(msg);
00554         }
00555     }
00556 }
00557 
00558 
00559 /* @brief Called just before unmounting the volume
00560  *
00561  * Application must close all its open files on the given volume. Failing to 
00562  * this signal may result in unsaved data or currupt files.
00563  */
00564 static void on_prepare_unmount ( eripc_context_t          *context,
00565                                  const eripc_event_info_t *info,
00566                                  void                     *user_data )
00567 {
00568     LOGPRINTF("entry");
00569     gchar             *msg        = NULL;
00570     const eripc_arg_t *arg_array  = info->args;
00571 
00572     if (arg_array[0].type == ERIPC_TYPE_STRING)
00573     {
00574         const char *mountpoint = arg_array[0].value.s;
00575         if (mountpoint)
00576         {
00577             // TODO: Replace implementation
00578 
00579             msg = g_strdup_printf("Device to unmount: %s", mountpoint);
00580             gtk_label_set_text( GTK_LABEL(g_volume), msg);
00581             LOGPRINTF("%s", msg);
00582             g_free(msg);
00583         }
00584     }
00585 }
00586 
00587 
00588 /* @brief Called just after unmounting the volume
00589  *
00590  * Typically an application should have responded to a prior sysPrepareUnmount 
00591  * signal, but when a device with volumes was removed unexpectedly it may need 
00592  * to act on this signal.
00593  */  
00594 static void on_unmounted ( eripc_context_t          *context,
00595                            const eripc_event_info_t *info,
00596                            void                     *user_data )
00597 {
00598     LOGPRINTF("entry");
00599     gchar             *msg        = NULL;
00600     const eripc_arg_t *arg_array  = info->args;
00601 
00602     if (arg_array[0].type == ERIPC_TYPE_STRING)
00603     {
00604         const char  *mountpoint = arg_array[0].value.s;
00605         if (mountpoint)
00606         {
00607             // TODO: Replace implementation
00608             
00609             if (g_mountpoint && (strcmp(mountpoint, g_mountpoint) == 0))
00610             {
00611                 g_free(g_mountpoint);
00612                 g_mountpoint = NULL;
00613             }
00614             
00615             msg = g_strdup_printf("Device unmounted: %s", mountpoint);
00616             gtk_label_set_text( GTK_LABEL(g_volume), msg);
00617             LOGPRINTF("%s", msg);
00618             g_free(msg);
00619         }
00620     }
00621 }
00622 
00623 
00624 /* @brief Called just before the system enters standby mode
00625  * 
00626  * Application must commit changes (flush) of all its open files. Failing to 
00627  * handle this signal may result in unsaved data or currupt files.
00628  */
00629 static void on_prepare_standby ( eripc_context_t          *context,
00630                                  const eripc_event_info_t *info,
00631                                  void                     *user_data )
00632 {
00633     LOGPRINTF("entry");
00634 
00635     // TODO: Add implementation here
00636 }
00637 
00638 
00639 /* @brief Called when the system's locale has changed
00640  *
00641  * Application should load language dependent screen texts and probably set new 
00642  * labels for its menu items; to activate a new locale application should call:
00643  *             g_setenv("LANG", new_locale, TRUE);
00644  *             setlocale(LC_ALL, "");
00645  */
00646 static void on_changed_locale ( eripc_context_t          *context,
00647                                 const eripc_event_info_t *info,
00648                                 void                     *user_data )
00649 {
00650     LOGPRINTF("entry");
00651     const eripc_arg_t *arg_array = info->args;
00652 
00653     if (arg_array[0].type == ERIPC_TYPE_STRING)
00654     {
00655         const char *locale = arg_array[0].value.s;
00656         if (locale)
00657         {
00658             const char *old_locale = g_getenv("LANG");
00659             if (!old_locale || (strcmp(old_locale, locale) != 0))
00660             {
00661                 main_set_locale(locale);
00662             }
00663         }
00664     }
00665 }
00666 
00667 
00668 /* @brief Called when the display's orientation has changed
00669  *
00670  * Application may need to adapt its screen size, coordinates and/or origin.
00671  * Possible values: "portrait", "landscape_clockwise", "landscape_anticlockwise"
00672  */
00673 static void on_changed_orientation ( eripc_context_t          *context,
00674                                      const eripc_event_info_t *info,
00675                                      void                     *user_data )
00676 {
00677     LOGPRINTF("entry");
00678     gchar             *msg        = NULL;
00679     const eripc_arg_t *arg_array = info->args;
00680     
00681     if (arg_array[0].type == ERIPC_TYPE_STRING)
00682     {
00683         const char *orientation = arg_array[0].value.s;
00684         if (orientation)
00685         {
00686             // TODO: Replace implementation
00687             
00688             msg = g_strdup_printf("Orientation changed: %s", orientation);
00689             gtk_label_set_text( GTK_LABEL(g_action), msg);
00690             LOGPRINTF("%s", msg);
00691             g_free(msg);
00692         }
00693     }
00694 }
00695 
00696 //---------------------
00697 // new ipc callbacks
00698 //---------------------
00699 
00700 
00701 static void on_sys_changed_pageturn_inverted(  eripc_context_t *context, 
00702                                             const eripc_event_info_t *info, 
00703                                             void *user_data)
00704 {
00705     LOGPRINTF("entry");
00706 
00707     gchar             *msg        = NULL;
00708     const eripc_arg_t *arg_array = info->args;
00709 
00710     if (arg_array[0].type == ERIPC_TYPE_BOOL)
00711     {
00712         gboolean is_inverted = arg_array[0].value.b;
00713 
00714         // TODO: Replace implementation
00715         msg = g_strdup_printf("page turning setting from from flipbar change, is_inverted = %d", is_inverted);
00716         gtk_label_set_text( GTK_LABEL(g_action), msg);
00717         LOGPRINTF("%s", msg);
00718         g_free(msg);
00719     }
00720 
00721 }
00722 
00723 
00724 static void on_page_change( eripc_context_t *context, 
00725                             const eripc_event_info_t *info, 
00726                             void *user_data)
00727 {
00728     LOGPRINTF("entry");
00729 
00730     gchar             *msg        = NULL;
00731     const eripc_arg_t *arg_array = info->args;
00732 
00733     g_return_if_fail(arg_array[0].type == ERIPC_TYPE_STRING);
00734 
00735     const gchar* direction = arg_array[0].value.s;
00736 
00737     if (direction)
00738     {
00739         // TODO: Replace implementation
00740         msg = g_strdup_printf("page change from menubar, direction:  %s", direction);
00741         gtk_label_set_text( GTK_LABEL(g_action), msg);
00742         LOGPRINTF("%s", msg);
00743         g_free(msg);
00744     }
00745 
00746 }
00747 
00748 
00749 
00750 //--------------------------------------------------
00751 // Queries over ipc
00752 //-------------------------------------------------
00753 
00754 // the following functions queries sysd about the
00755 // custom setting of the flipbar.
00756 
00757 // Function: ipc_sys_is_pageturn_inverted()
00758 //
00759 // Return value: False -> pageturning is not inverted i.e. left to right gives next page
00760 //               True  -> pageturning is     inverted i.e. left to right gives previous page
00761 // Intended use: during application initialisation and only useful in portrait reading mode
00762 
00763 gboolean ipc_sys_is_pageturn_inverted()
00764 {
00765     gboolean result = FALSE;
00766 
00767     eripc_error_t retval;
00768     eripc_event_info_t* info = NULL;
00769 
00770     LOGPRINTF("entry");
00771 
00772     retval = eripc_send_varargs_and_wait(eripcClient->context,
00773             &info,
00774             ERIPC_BUS_SESSION,
00775             DBUS_SERVICE_SYSTEM_CONTROL,
00776             "sysGetPageturnInverted",
00777             ERIPC_TYPE_INVALID);
00778 
00779     if (retval != ERIPC_ERROR_SUCCESS)
00780     {
00781         ERRORPRINTF("Error launching eripc handler");
00782     }
00783     else if (info == NULL || info->args == NULL)
00784     {
00785         ERRORPRINTF("sysd returns OK but no reply structure");
00786     }
00787     else
00788     {
00789         const eripc_arg_t *arg_array = info->args;
00790 
00791         if (arg_array[0].type == ERIPC_TYPE_BOOL)
00792         {
00793             result = (gboolean) arg_array[0].value.b;
00794         }
00795         else 
00796         {
00797             result = FALSE ;
00798         }
00799     }
00800 
00801     eripc_event_info_free(eripcClient->context, info);
00802     return result; 
00803 }
00804 
00805 
00806 
00807 // Function: ipc_sys_is_in_portrait_mode()
00808 //
00809 // Return value: False -> the device is in landscape mode i.e. flipbar up should be interpreted as previous page.
00810 //               True  ->  the device is in portrait mode i.e. flipbar interpretation should depend on sys_is_pageturn_inverted result.
00811 // Intended use: during application initialisation
00812 
00813 gboolean ipc_sys_is_in_portrait_mode(void)
00814 {
00815 
00816     gboolean result = TRUE;
00817 
00818     eripc_error_t retval;
00819     eripc_event_info_t* info = NULL;
00820 
00821     LOGPRINTF("entry");
00822 
00823     retval = eripc_send_varargs_and_wait(eripcClient->context,
00824             &info,
00825             ERIPC_BUS_SESSION,
00826             DBUS_SERVICE_SYSTEM_CONTROL,
00827             "sysGetOrientation",
00828             ERIPC_TYPE_INVALID);
00829 
00830     if (retval != ERIPC_ERROR_SUCCESS)
00831     {
00832         ERRORPRINTF("Error launching eripc handler");
00833     }
00834     else if (info == NULL || info->args == NULL)
00835     {
00836         ERRORPRINTF("sysd returns OK but no reply structure");
00837     }
00838     else
00839     {
00840         const eripc_arg_t *arg_array = info->args;
00841 
00842         if (arg_array[0].type == ERIPC_TYPE_STRING)
00843         {
00844             if ( strcmp("portrait", arg_array[0].value.s) == 0 )
00845             {
00846                 result = TRUE;
00847             }
00848             else
00849             {
00850                 result = FALSE;
00851             }
00852         }
00853         else
00854         {
00855             result = FALSE ;
00856         }
00857     }
00858     eripc_event_info_free(eripcClient->context, info);
00859     return result;
00860 }
00861 
00862 
Generated by  doxygen 1.6.2-20100208