settings/src/main.c File Reference

#include <signal.h>
#include <sys/wait.h>
#include <unistd.h>
#include <string.h>
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
#include <liberdm/display.h>
#include <libergtk/ergtk.h>
#include <liberregxml/erregapi.h>
#include "config.h"
#include "displayStatus.h"
#include "setupLog.h"
#include "background.h"
#include "settings.h"
#include "settingsData.h"
#include "iLiadUserData.h"
#include "iLiadConfigData.h"
#include "iLiadBgConnectData.h"
#include "iLiadPCConnectData.h"
#include "iLiadArcLocData.h"
#include "iLiadStartUpData.h"
#include "iLiadStartUpScreen.h"
#include "iLiadTimediDSData.h"
#include "system.h"
#include "iLiadPincodeData.h"
#include "iLiadLanguageData.h"
#include "iLiadLanguageScreen.h"
#include "erbusy.h"
#include "pagebar.h"
#include "toolbar.h"
#include "languages.h"

Go to the source code of this file.

Functions

static void on_sigterm (int signo)
static void on_sigchld (int signo)
static void on_main_window_destroy (GtkWidget *widget, gpointer data)
static gboolean on_main_window_expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer p)
static gboolean on_main_window_focus_out_event (GtkWidget *widget, GdkEventFocus *event, gpointer p)
static void parse_arguments (int argc, char **argv)
static void load_registry (void)
static void release_registry (void)
void prepare_registry_write (void)
void do_registry_write (void)
int main (int argc, char **argv)

Variables

static gboolean g_select_language_only = FALSE


Function Documentation

void do_registry_write ( void   ) 

Definition at line 200 of file main.c.

00201 {
00202     gboolean       b;
00203     
00204     // verify write lock
00205     g_assert(lock_write == erRegGetLockState());
00206     
00207     // save registry
00208     b = erRegStore();
00209     if (b == FALSE)
00210     {
00211         ST_ERRORPRINTF("erRegStore fails with return code [%d]", b);
00212     }
00213 
00214     // release lock
00215     erRegUnlock();
00216 }

Here is the call graph for this function:

static void load_registry ( void   )  [static]

Definition at line 114 of file main.c.

00115 {
00116     gboolean       b;
00117     regLoad_t      regLoad;
00118     
00119     // init registry locking
00120     b = erRegRWLockInit();
00121     if (b == FALSE)
00122     {
00123         ST_ERRORPRINTF("erRegRWLockInit fails with return code [%d]", b);
00124         g_assert_not_reached();
00125     }
00126     
00127     // acquire read-only lock
00128     b = erRegReadLock();
00129     if (b == FALSE)
00130     {
00131         ST_ERRORPRINTF("erRegReadLock fails with return code [%d]", b);
00132         g_assert_not_reached();
00133     }
00134     
00135     // load registry sections used
00136     regLoad = erRegLoad(regBasis_t);
00137     if (regLoad == loadError_t)
00138     {
00139         ST_ERRORPRINTF("erRegLoad(regBasis_t) fails with return code [%d]", regLoad);
00140         g_assert_not_reached();
00141     }
00142    
00143     regLoad = erRegLoad(regNWProfiles_t);
00144     if (regLoad == loadError_t)
00145     {
00146         ST_ERRORPRINTF("erRegLoad(regNWProfiles_t_t) fails with return code [%d]", regLoad);
00147         g_assert_not_reached();
00148     }
00149 
00150     // release lock, all data now in memory
00151     erRegUnlock();
00152 }

Here is the call graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 218 of file main.c.

00219 {
00220     GtkWidget *window=NULL;
00221     GtkWidget *settingsArea=NULL;
00222     GtkWidget *settingsScreens=NULL;
00223 
00224     parse_arguments(argc, argv);
00225 
00226     // init threads - needed for screen refresh idle handling 
00227     g_thread_init(NULL);
00228     gdk_threads_init();
00229 
00230     // open the RC file associate with this program
00231     gtk_rc_parse(DATA_DIR "/setup.rc");
00232     ST_LOGPRINTF("rc file %s", DATA_DIR "/setup.rc");
00233 
00234     gtk_init(&argc, &argv);
00235 
00236     load_registry();
00237     erbusy_init();
00238     erbusy_blink();
00239  
00240     if (g_select_language_only)
00241     {
00242         iLiad_language_data_init();
00243     }
00244     else
00245     {
00246         settings_data_init();
00247         languagesInit();
00248         pagebar_init();
00249         toolbar_init();
00250         setupInstallIpcServer();
00251     }
00252 
00253     // => only request a refresh on the main window expose event
00254     display_update_increase_level(MAIN_WINDOW_EXPOSE_LEVEL);
00255 
00256     if (g_select_language_only)
00257     {
00258         window = iLiad_language_screen_create();
00259         iLiad_language_screen_display_data();
00260         gtk_widget_show(window);
00261     }
00262     else
00263     {
00264         // create the main, top level, window 
00265         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
00266         gtk_window_set_title(GTK_WINDOW(window), PACKAGE " " VERSION);
00267         gtk_window_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
00268         gtk_container_set_border_width(GTK_CONTAINER(window), 0);
00269         gtk_widget_set_size_request(GTK_WIDGET(window), SCREEN_WIDTH, SCREEN_HEIGHT - TOOLBAR_HEIGTH - PAGEBAR_HEIGHT);
00270         gtk_window_set_modal(GTK_WINDOW(window), TRUE);
00271         gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
00272 
00273         g_signal_connect(      G_OBJECT(window), "destroy",         G_CALLBACK(on_main_window_destroy),         NULL);
00274         g_signal_connect_after(G_OBJECT(window), "expose-event",    G_CALLBACK(on_main_window_expose_event),    NULL);
00275         g_signal_connect(      G_OBJECT(window), "key-press-event", G_CALLBACK(on_settings_keypress),           NULL);
00276         g_signal_connect(      G_OBJECT(window), "focus-out-event", G_CALLBACK(on_main_window_focus_out_event), NULL);
00277         
00278         // create and display the application background and screens
00279         settingsArea = bg_create(window);
00280         bg_set_text();
00281         settingsScreens = settings_create();
00282         gtk_container_add(GTK_CONTAINER(settingsArea), settingsScreens);
00283       
00284         gtk_widget_show(window);
00285         display_update_request_screen_refresh(MAIN_WINDOW_EXPOSE_LEVEL, WAVEFORM_FULLSCREEN);
00286     }
00287 
00288     // catch the TERM signal
00289     signal(SIGTERM, on_sigterm);
00290     if (!g_select_language_only) 
00291     {
00292         signal(SIGCHLD, on_sigchld); 
00293     }
00294 
00295     gdk_threads_enter();
00296     gtk_main();
00297    
00298     display_update_increase_level(NO_DISPLAY_UPDATE_LEVEL); // no more screen updates
00299    
00300     if (!g_select_language_only)
00301     {
00302         gtk_widget_hide(settingsArea);  // force a focus-out event on all objects
00303     }
00304     
00305     gdk_threads_leave();
00306 
00307     if (!g_select_language_only)
00308     {
00309         // store settings when changed
00310         iLiad_user_data_store();
00311         iLiad_config_data_store();
00312         iLiad_autoconnect_data_store();
00313         iLiad_pc_connect_data_store();
00314         iLiad_pincode_data_store();
00315         iLiad_archive_location_data_store();
00316         iLiad_startup_data_store();
00317         iLiad_timedids_data_store();
00318     }
00319 
00320     release_registry();
00321 
00322     return 0;
00323 }

Here is the call graph for this function:

static void on_main_window_destroy ( GtkWidget *  widget,
gpointer  data 
) [static]

Definition at line 357 of file main.c.

00358 {
00359     ST_LOGPRINTF("entry");
00360     
00361     gtk_main_quit();
00362 }

static gboolean on_main_window_expose_event ( GtkWidget *  widget,
GdkEventExpose *  event,
gpointer  p 
) [static]

Definition at line 364 of file main.c.

00365 {
00366     ST_LOGPRINTF("entry");
00367 
00368     display_update_request_screen_refresh(MAIN_WINDOW_EXPOSE_LEVEL, WAVEFORM_FULLSCREEN);
00369     return FALSE;
00370 }

Here is the call graph for this function:

static gboolean on_main_window_focus_out_event ( GtkWidget *  widget,
GdkEventFocus *  event,
gpointer  p 
) [static]

Definition at line 373 of file main.c.

00374 {
00375     ST_LOGPRINTF("entry");
00376 
00377     settings_data_store_currentpage();
00378     return FALSE;
00379 }

Here is the call graph for this function:

static void on_sigchld ( int  signo  )  [static]

Definition at line 339 of file main.c.

00340 {
00341     pid_t pid;
00342     int status;
00343 
00344     signal(SIGCHLD, on_sigchld);
00345     if ((pid = wait(&status)) < 0)
00346     {
00347         ST_ERRORPRINTF("wait failed!");
00348         return;
00349     }
00350     if (pid == get_xtscal_pid())
00351     {
00352         // xtscal quits
00353         handle_xtscal_quit();
00354     }
00355 }

Here is the call graph for this function:

static void on_sigterm ( int  signo  )  [static]

Definition at line 326 of file main.c.

00327 {
00328     ST_WARNPRINTF("entry settings: signo [%d]", signo);
00329 
00330     // stop calibration process
00331     stop_xtscal();
00332 
00333     // stop main process
00334     gdk_threads_enter();
00335     gtk_main_quit();
00336     gdk_threads_leave();
00337 }

Here is the call graph for this function:

static void parse_arguments ( int  argc,
char **  argv 
) [static]

Definition at line 78 of file main.c.

00079 {
00080     static const char *usage_text =
00081                         "\n"
00082                         "usage: %s [options]\n"
00083                         "\n"
00084                         "options:\n"
00085                         "    --help\n"
00086                         "        Print help text and quit\n"
00087                         "    --select-language-only\n"
00088                         "       Show language settings screen only\n"
00089                         "\n";
00090     int i;
00091 
00092     for (i = 0 ; i < argc ; i++)
00093     {
00094         if (strcmp(argv[i], "--help") == 0)
00095         {
00096             printf(usage_text, argv[0]);
00097             _exit(0);
00098         }
00099         else if(strcmp(argv[i], "--select-language-only") == 0)
00100         {
00101             ST_LOGPRINTF("%s is only for language selection", argv[0]);
00102             g_select_language_only = TRUE;
00103         }
00104         else if (strncmp(argv[i], "--", 2) == 0)
00105         {
00106             printf("\nInvalid option: %s\n", argv[i]);
00107             printf(usage_text, argv[0]);
00108             _exit(1);
00109         }
00110     }
00111 }

void prepare_registry_write ( void   ) 

Definition at line 166 of file main.c.

00167 {
00168     gboolean       b;
00169     regLoad_t      regLoad;
00170     
00171     // acquire write lock
00172     b = erRegWriteLock();
00173     if (b == FALSE)
00174     {
00175         ST_ERRORPRINTF("erRegWriteLock fails with return code [%d]", b);
00176         g_assert_not_reached();
00177     }
00178     
00179     // reload section(s) that may be written
00180     erRegUnload(regBasis_t);
00181     regLoad = erRegLoad(regBasis_t);
00182     if (regLoad == loadError_t)
00183     {
00184         ST_ERRORPRINTF("erRegLoad(regBasis_t) fails with return code [%d]", regLoad);
00185         g_assert_not_reached();
00186     }
00187 
00188     erRegUnload(regNWProfiles_t);
00189     regLoad = erRegLoad(regNWProfiles_t);
00190     if (regLoad == loadError_t)
00191     {
00192         ST_ERRORPRINTF("erRegLoad(regNWProfiles_t) fails with return code [%d]", regLoad);
00193         g_assert_not_reached();
00194     }
00195 
00196 
00197 }

Here is the call graph for this function:

static void release_registry ( void   )  [static]

Definition at line 155 of file main.c.

00156 {
00157     // unload registry sections
00158     erRegUnload(regBasis_t);
00159     erRegUnload(regNWProfiles_t);
00160 
00161     // discard registry locking
00162     erRegRWLockDestroy();
00163 }

Here is the call graph for this function:


Variable Documentation

gboolean g_select_language_only = FALSE [static]

Definition at line 76 of file main.c.


Generated on Sun Dec 14 17:17:27 2008 by  doxygen 1.5.6