contentLister/src/main.c File Reference

#include <config.h>
#include <gtk/gtk.h>
#include <libermanifest/ermanifest.h>
#include <liberregxml/erregapi.h>
#include <liberdm/display.h>
#include "contentListerLog.h"
#include "erConnect.h"
#include "system.h"
#include "gtkPincodeScreen.h"
#include "control.h"
#include "erbusy.h"
#include "languages.h"
#include "click.h"

Go to the source code of this file.

Functions

static void load_registry (void)
static void release_registry (void)
void reload_registry (void)
void prepare_registry_write (void)
static void usage (const char *argv_0)
static void parse_arguments (int argc, char **argv)
startup_behaviour_t main_get_startup_behaviour (void)
void do_registry_write (void)
static void on_destroy (GtkWidget *widget, gpointer data)
int main (int argc, char *argv[])

Variables

static startup_behaviour_t g_startup_behaviour = behaviourUndefined_t
struct {
   const char *   argv
   const startup_behaviour_t   behaviour
g_startup_locations []


Function Documentation

void do_registry_write ( void   ) 

Definition at line 279 of file main.c.

00280 {
00281     gboolean       b;
00282     
00283     // verify write lock
00284     g_assert(lock_write == erRegGetLockState());
00285     
00286     // save registry
00287     b = erRegStore();
00288     if (b == FALSE)
00289     {
00290         CL_ERRORPRINTF("erRegStore fails with return code [%d]", b);
00291     }
00292 
00293     // release lock
00294     erRegUnlock();
00295 }

Here is the call graph for this function:

static void load_registry ( void   )  [static]

Definition at line 77 of file main.c.

00078 {
00079     static gboolean firsttime = TRUE;
00080 
00081     gboolean       b;
00082     regLoad_t      regLoad;
00083     
00084     // init registry locking
00085     b = erRegRWLockInit();
00086     if (b == FALSE)
00087     {
00088         CL_ERRORPRINTF("erRegRWLockInit fails with return code [%d]", b);
00089         g_assert_not_reached();
00090     }
00091 
00092     if (firsttime)
00093     {
00094         // acquire write lock to force recovery, if needed
00095         b = erRegWriteLock();
00096         if (b == FALSE)
00097         {
00098             CL_ERRORPRINTF("erRegWriteLock fails with return code [%d]", b);
00099             g_assert_not_reached();
00100         }
00101 
00102         // load network profiles, so these will be recovered if needed
00103         regLoad = erRegLoad(regNWProfiles_t);
00104         if (regLoad != loadOk_t)
00105         {
00106             CL_WARNPRINTF("erRegLoad(regNWProfiles_t) returns [%d]", regLoad);
00107             if (regLoad == loadError_t)
00108             {
00109                 CL_ERRORPRINTF("erRegLoad(regNWProfiles_t) fails with return code [%d]", regLoad);
00110                 g_assert_not_reached();
00111             }
00112         }
00113         // release network profiles, contentLister does not use them
00114         erRegUnload(regNWProfiles_t);
00115     }
00116     else
00117     {
00118         // acquire read-only lock
00119         b = erRegReadLock();
00120         if (b == FALSE)
00121         {
00122             CL_ERRORPRINTF("erRegReadLock fails with return code [%d]", b);
00123             g_assert_not_reached();
00124         }
00125     }
00126     
00127     // load registry sections used
00128     regLoad = erRegLoad(regBasis_t);
00129     if (regLoad == loadError_t)
00130     {
00131         CL_ERRORPRINTF("erRegLoad(regBasis_t) fails with return code [%d]", regLoad);
00132         g_assert_not_reached();
00133     }
00134     
00135     // release lock, all data now in memory
00136     erRegUnlock();
00137 
00138     firsttime = FALSE;
00139 }

Here is the call graph for this function:

int main ( int  argc,
char *  argv[] 
)

Definition at line 312 of file main.c.

00313 {
00314     GtkWidget *window;
00315     ContentLister *theContentLister;
00316 
00317     parse_arguments(argc, argv);
00318 
00319     /* init threads */
00320     g_thread_init(NULL);
00321     gdk_threads_init();
00322     gdk_threads_enter();
00323 
00324     // open the RC file associate with this program
00325     gtk_rc_parse(DATA_DIR "/contentLister.rc");
00326     CL_LOGPRINTF("rc file %s", DATA_DIR "/contentLister.rc");
00327 
00328     gtk_init(&argc, &argv);
00329 
00330     gchar** files = gtk_rc_get_default_files();
00331     while( *files )
00332     {
00333         CL_WARNPRINTF("gtk_rc_get_default_files [%s]", *files);
00334         files++;
00335     }
00336 
00337     
00338 #ifdef ENABLE_LOGGING
00339     erlog_write_start();
00340     erlog_event_system(power_on);
00341 #endif /* ENABLE_LOGGING */
00342 
00343 //#ifdef COMMAND_LINE_INPUT
00344 //    erRegInitSystemAccess();
00345 //#endif /* COMMAND_LINE_INPUT */
00346 
00347     load_registry();
00348 
00349     languagesInit();
00350     click_init();
00351 
00352     // create the main, top level, window 
00353     window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
00354     gtk_window_set_title(GTK_WINDOW(window), PACKAGE " " VERSION);
00355     gtk_window_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
00356     gtk_container_set_border_width(GTK_CONTAINER(window), 0);
00357     gtk_widget_set_size_request(GTK_WIDGET(window), SCREEN_WIDTH, SCREEN_HEIGHT - TOOLBAR_HEIGHT - PAGEBAR_HEIGHT);
00358     gtk_window_set_modal(GTK_WINDOW(window), TRUE);
00359     gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
00360 
00361     theContentLister = ctrlInit(window);
00362 
00363     if (theContentLister)
00364     {
00365         CL_LOGPRINTF("Inside if (theContentLister)");
00366 
00367         // Connect the destroy event of the window with our on_destroy function
00368         // When the window is about to be destroyed we get a notificaton and
00369         // stop the main GTK loop
00370         g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(on_destroy), theContentLister);
00371 
00372         // make sure that everything, window and label, are visible 
00373         gtk_widget_show(window);
00374     }
00375 
00376     // start the main loop //
00377     CL_LOGPRINTF("Before gtk_main");
00378 
00379     gtk_main();
00380     gdk_threads_leave();
00381 
00382     release_registry();
00383 
00384     return 0;
00385 }

Here is the call graph for this function:

startup_behaviour_t main_get_startup_behaviour ( void   ) 

Definition at line 273 of file main.c.

00274 {
00275     return g_startup_behaviour;
00276 }

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

Definition at line 301 of file main.c.

00302 {
00303     ContentLister *theContentLister = (ContentLister *) data;
00304 
00305     CL_WARNPRINTF("entry");
00306 
00307     ctrlDestroy(theContentLister);
00308 
00309     gtk_main_quit();
00310 }

Here is the call graph for this function:

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

Definition at line 231 of file main.c.

00232 {
00233     int  i;
00234     int  j;
00235     gboolean found = FALSE;
00236 
00237     // parse contentLister options
00238     for (i = 1 ; i < argc ; i++)
00239     {
00240         if (strcmp(argv[i], "--help") == 0)
00241         {
00242             usage(argv[0]);
00243         }
00244         else if(strcmp(argv[i], "--location") == 0)
00245         {
00246             i++;
00247             if (i >= argc)
00248             {
00249                 usage(argv[0]);
00250             }
00251             else
00252             {
00253                 // get startup location (behaviour)
00254                 for (j = 0 ; g_startup_locations[j].argv ; j++)
00255                 {
00256                     if (strcmp(argv[i],  g_startup_locations[j].argv) == 0)
00257                     {
00258                         g_startup_behaviour = g_startup_locations[j].behaviour;
00259                         found = TRUE;
00260                     }
00261                 }
00262                 if (!found)
00263                 {
00264                     // invalid location specified
00265                     usage(argv[0]);
00266                 }
00267             }
00268         }
00269     }
00270 }

Here is the call graph for this function:

void prepare_registry_write ( void   ) 

Definition at line 179 of file main.c.

00180 {
00181     gboolean       b;
00182     regLoad_t      regLoad;
00183     
00184     // acquire write lock
00185     b = erRegWriteLock();
00186     if (b == FALSE)
00187     {
00188         CL_ERRORPRINTF("erRegWriteLock fails with return code [%d]", b);
00189         g_assert_not_reached();
00190     }
00191     
00192     // reload section(s) that may be written
00193     erRegUnload(regBasis_t);
00194     regLoad = erRegLoad(regBasis_t);
00195     if (regLoad == loadError_t)
00196     {
00197         CL_ERRORPRINTF("erRegLoad(regBasis_t) fails with return code [%d]", regLoad);
00198         g_assert_not_reached();
00199     }
00200 }

Here is the call graph for this function:

static void release_registry ( void   )  [static]

Definition at line 142 of file main.c.

00143 {
00144     // unload registry sections
00145     erRegUnload(regBasis_t);
00146 
00147     // discard registry locking
00148     erRegRWLockDestroy();
00149 }

Here is the call graph for this function:

void reload_registry ( void   ) 

Definition at line 152 of file main.c.

00153 {
00154     gboolean       b;
00155     regLoad_t      regLoad;
00156     
00157     // acquire read lock
00158     b = erRegReadLock();
00159     if (b == FALSE)
00160     {
00161         CL_ERRORPRINTF("erRegReadLock fails with return code [%d]", b);
00162         g_assert_not_reached();
00163     }
00164     
00165     // reload registry sections used
00166     erRegUnload(regBasis_t);
00167     regLoad = erRegLoad(regBasis_t);
00168     if (regLoad == loadError_t)
00169     {
00170         CL_ERRORPRINTF("erRegLoad(regBasis_t) fails with return code [%d]", regLoad);
00171         g_assert_not_reached();
00172     }
00173 
00174     // release lock, all data now in memory
00175     erRegUnlock();
00176 }

Here is the call graph for this function:

static void usage ( const char *  argv_0  )  [static]

Definition at line 203 of file main.c.

00204 {
00205     int i;
00206 
00207     static const char *usage_text = 
00208                         "\n"
00209                         "usage: %s [options]\n"
00210                         "\n"
00211                         "options:\n"
00212                         "    --help\n"
00213                         "        Print help text and quit\n"
00214                         "    --location <location>\n"
00215                         "        Start contentLister in <location>\n"
00216                         "\n"
00217                         "<location>:\n";
00218 
00219     printf(usage_text, argv_0);
00220 
00221     for (i = 0 ; g_startup_locations[i].argv ; i++)
00222     {
00223         printf("    %s\n", g_startup_locations[i].argv);
00224     }
00225     printf("\n");
00226 
00227     exit(1);
00228 }


Variable Documentation

const char* argv

Definition at line 60 of file main.c.

Definition at line 61 of file main.c.

startup_behaviour_t g_startup_behaviour = behaviourUndefined_t [static]

Definition at line 56 of file main.c.

struct { ... } g_startup_locations[] [static]


Generated on Sun Dec 14 17:13:36 2008 by  doxygen 1.5.6