sysd/src/main.c File Reference

#include "config.h"
#include <glib.h>
#include <gtk/gtk.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#include <time.h>
#include <liberipc/eripc.h>
#include <liberutils/display_utils.h>
#include "log.h"
#include "busy.h"
#include "conf.h"
#include "display.h"
#include "connections.h"
#include "hal.h"
#include "ipc.h"
#include "process.h"
#include "system.h"
#include "tasks.h"
#include "xwindow.h"
Include dependency graph for sysd/src/main.c:

Go to the source code of this file.

Functions

static void usage (const char *argv_0)
static void parse_arguments (int argc, char **argv)
static void on_sigterm (int signo)
static long int read_timestamp (const char *path)
static gboolean check_set_datetime (void)
static void on_phase_3_complete (void)
static void start_phase_3 (void)
static void on_phase_2_complete (void)
static void start_phase_2 (void)
static void on_phase_1_complete (void)
int main (int argc, char *argv[])

Variables

static gboolean do_detach = FALSE

Function Documentation

static gboolean check_set_datetime ( void   )  [static]

Definition at line 200 of file sysd/src/main.c.

References LOGPRINTF, and read_timestamp().

Referenced by start_phase_2().

00201 {
00202     gboolean need_set = FALSE; 
00203     struct timeval tod; 
00204     long int ts = 0;
00205 
00206     ts = read_timestamp("/etc/timestamp");  
00207 
00208     // now get the current time
00209     gettimeofday(&tod, NULL); 
00210     LOGPRINTF("timeofday = %ld", tod.tv_sec);
00211 
00212     if (ts < tod.tv_sec) 
00213     {
00214         LOGPRINTF("timestamp < timeofday"); 
00215         // do nothing
00216     }
00217     else  
00218     {
00219         need_set = TRUE;
00220     }
00221 
00222     return need_set;
00223 }

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 343 of file sysd/src/main.c.

References busy_add_foreground(), BUSY_DIALOG_NONE, conf_set_services(), display_gain_control(), display_set_services(), do_detach, hal_set_services(), ipc_set_services(), LOGPRINTF, on_phase_1_complete(), on_sigterm(), parse_arguments(), process_add(), PS_RESPAWN, PS_WAIT_STARTED, sys_set_services(), and window_set_services().

00344 {
00345     struct sigaction on_term;
00346     
00347     // parse command-line arguments
00348     parse_arguments(argc, argv);
00349 
00350     // catch the SIGTERM signal
00351     memset(&on_term, 0x00, sizeof(on_term));
00352     on_term.sa_handler = on_sigterm;
00353     sigaction(SIGTERM, &on_term, NULL);
00354 
00355     if (do_detach)
00356     {
00357         if (daemon(0, 0) !=0)
00358         {
00359             LOGPRINTF("Daemonize error: %s", strerror(errno));
00360             exit (1);
00361         }
00362     }
00363 
00364     // init gdk (for windowing)
00365     g_type_init();
00366     gtk_init(&argc, &argv);
00367     
00368     // prepare IPC, system (micro) and display
00369     ipc_set_services();
00370     window_set_services(); 
00371     sys_set_services();     /* relies on ipc */
00372     display_set_services(); /* relies on system/micro and window*/
00373     busy_add_foreground(0, BUSY_DIALOG_NONE, NULL);
00374     
00375     // prepare GConf
00376     conf_set_services();
00377 
00378     // prepare HAL and mountpoints
00379     hal_set_services();
00380     display_gain_control();
00381 
00382     // spawn applications 
00383     process_add("/usr/bin/popupmenu", NULL, NULL, NULL, PS_WAIT_STARTED | PS_RESPAWN);
00384     process_add("/usr/bin/uds",       NULL, G_CALLBACK(on_phase_1_complete), NULL, PS_WAIT_STARTED | PS_RESPAWN);
00385     
00386     // run the main loop
00387     LOGPRINTF("before gtk_main");
00388     gtk_main();
00389     LOGPRINTF("after gtk_main");
00390 
00391     return 0;
00392 }

Here is the call graph for this function:

static void on_phase_1_complete ( void   )  [static]

Definition at line 325 of file sysd/src/main.c.

References conf_disabled_sensor_lock(), conn_update_statusbar(), ipc_send_volume_mounted(), LOGPRINTF, MOUNTPOINT_CARD, start_phase_2(), and sys_is_emulator().

Referenced by main().

00326 {
00327     LOGPRINTF("entry");
00328 
00329 #if MACHINE_IS_DR1000S || MACHINE_IS_DR1000SW    
00330     conf_disabled_sensor_lock();
00331 #endif
00332     conn_update_statusbar();
00333     
00334     if (!sys_is_emulator())
00335     {
00336         ipc_send_volume_mounted(MOUNTPOINT_CARD);
00337     }
00338 
00339     start_phase_2();
00340 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void on_phase_2_complete ( void   )  [static]

Definition at line 249 of file sysd/src/main.c.

References busy_add_foreground(), BUSY_DIALOG_NONE, display_gain_control(), LOGPRINTF, start_phase_3(), STATE_DEVICE_STARTED, sys_request_popup(), and sys_set_device_state().

Referenced by start_phase_2().

00250 {
00251     LOGPRINTF("entry");
00252 
00253     busy_add_foreground(0, BUSY_DIALOG_NONE, NULL);
00254     display_gain_control();
00255     sys_request_popup("localunblock");
00256     
00257     sys_set_device_state(STATE_DEVICE_STARTED);
00258     
00259     start_phase_3();
00260 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void on_phase_3_complete ( void   )  [static]

Definition at line 226 of file sysd/src/main.c.

References busy_remove_foreground(), display_return_control(), LOGPRINTF, and sys_starting_finished().

Referenced by start_phase_3().

00227 {
00228     LOGPRINTF("entry");
00229 
00230     // all apps started, stop busy and allow display updates again
00231     busy_remove_foreground(0);
00232     display_return_control();
00233     
00234     sys_starting_finished();
00235 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void on_sigterm ( int  signo  )  [static]

Definition at line 128 of file sysd/src/main.c.

References WARNPRINTF.

Referenced by main().

00129 {
00130     WARNPRINTF("    -- entry " PACKAGE_NAME ", my pid [%d]", getpid());
00131 
00132     // stop main process, prepare to quit application
00133     gtk_main_quit();
00134 
00135     WARNPRINTF("    -- leave " PACKAGE_NAME);
00136 }

Here is the caller graph for this function:

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

Definition at line 109 of file sysd/src/main.c.

References do_detach, and usage().

Referenced by main().

00110 {
00111     int  i;
00112 
00113     // parse contentLister options
00114     for (i = 1 ; i < argc ; i++)
00115     {
00116         if (strcmp(argv[i], "--help") == 0)
00117         {
00118             usage(argv[0]);
00119         }
00120         if (strcmp(argv[i], "--detach") == 0)
00121         {
00122             do_detach = TRUE;
00123         }
00124     }
00125 }

Here is the call graph for this function:

Here is the caller graph for this function:

static long int read_timestamp ( const char *  path  )  [static]

Definition at line 139 of file sysd/src/main.c.

References LOGPRINTF.

Referenced by check_set_datetime().

00140 {
00141     FILE* thefile = NULL; 
00142     size_t result;
00143     char tbuffer[20];
00144     char buf[20];
00145     const char* timeformat = "%m%d%H%M%Y" ; // current timestamp format
00146     struct tm mytime;
00147 
00148     long int ts = -1 ; // 0 = epoch 
00149 
00150     thefile = fopen(path, "r");
00151     if (NULL == thefile)
00152     {
00153         // only allow positive time, 0 = 1970-01-01 00:00
00154         goto error_fopen; 
00155     }
00156     bzero(tbuffer, sizeof(tbuffer));
00157     bzero(buf, sizeof(buf));
00158     bzero(&mytime, sizeof(struct tm));
00159     result = fread((void*) tbuffer,  sizeof(char), 20, thefile);
00160     if ( result > 0 && result <= sizeof(tbuffer) )
00161     {
00162         // transform to epoch time
00163         LOGPRINTF("Read timestamp from file: [%s]", tbuffer);
00164         
00165         // timestamp string to time struct
00166         strptime(tbuffer, timeformat, &mytime);
00167         
00168         // time is seconds since epoch
00169         result = strftime(buf, sizeof(buf), "%s", &mytime);  
00170         
00171         if ( result > 0 && result < sizeof(buf) )
00172         {
00173             LOGPRINTF("Old time stamp: [%s], New timestamp (secs since epoch) [%s]", tbuffer, buf);
00174         }
00175 
00176         // buf now holds a time stamp, compare to
00177         // translate to int
00178         ts = strtol(buf, NULL, 10);
00179         goto exit;
00180     }
00181     else 
00182     {
00183         goto error;
00184     }
00185         
00186 error: 
00187     ts = -1;
00188 exit:
00189     if (NULL != thefile)
00190     {
00191         fclose(thefile);
00192     }
00193     return ts;
00194 
00195 error_fopen:
00196     return -1;
00197 }

Here is the caller graph for this function:

static void start_phase_2 ( void   )  [static]

Definition at line 263 of file sysd/src/main.c.

References busy_add_background(), busy_remove_background(), busy_remove_foreground(), check_set_datetime(), conf_get_first_boot(), conf_is_multi_language(), display_return_control(), LOGPRINTF, on_phase_2_complete(), process_add(), PS_WAIT_EXIT, start_phase_3(), sys_has_stylus(), sys_is_emulator(), sys_request_popup(), and sys_spawn_sync().

Referenced by on_phase_1_complete().

00264 {
00265     LOGPRINTF("entry");
00266 
00267     // complex solution to make sure the menu is blocked before the 
00268     // first app starts and unblocked after the last app exists
00269     gboolean run_firstboot = FALSE;
00270     gboolean run_gtktscal  = FALSE;
00271     gboolean run_datetime  = FALSE;
00272     
00273     if (conf_get_first_boot())
00274     {
00275         if (conf_is_multi_language())
00276         {
00277             run_firstboot = TRUE;
00278         }
00279         
00280         if (sys_has_stylus() && !sys_is_emulator())
00281         {
00282             run_gtktscal = TRUE;
00283         }
00284     }
00285 
00286     if (check_set_datetime())
00287     {
00288         run_datetime = TRUE;
00289     }
00290 
00291     if (run_firstboot || run_gtktscal || run_datetime)
00292     {
00293         sys_request_popup("localblock");
00294         busy_remove_foreground(0);
00295         display_return_control();
00296 
00297         if (run_firstboot)
00298         {
00299             process_add("/usr/bin/settings --firstboot", NULL, NULL, run_gtktscal || run_datetime ? NULL : G_CALLBACK(on_phase_2_complete), PS_WAIT_EXIT);
00300         }
00301         
00302         if (run_gtktscal)
00303         {
00304             process_add("/usr/bin/gtktscal -firstboot", NULL, NULL, run_datetime ? NULL : G_CALLBACK(on_phase_2_complete), PS_WAIT_EXIT);
00305         }
00306         
00307         if (run_datetime)
00308         {
00309             // set busy to make sure the system does not suspend
00310             busy_add_background(0);
00311             sys_spawn_sync("date `cat /etc/timestamp` && /sbin/hwclock --systohc --utc");
00312             busy_remove_background(0);
00313             
00314             // show time/date settings dialog
00315             process_add("/usr/bin/settings --fdatetime", NULL, NULL, G_CALLBACK(on_phase_2_complete), PS_WAIT_EXIT);
00316         }
00317     }
00318     else
00319     {
00320         start_phase_3();
00321     }
00322 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void start_phase_3 ( void   )  [static]

Definition at line 238 of file sysd/src/main.c.

References hal_add_devices(), LOGPRINTF, on_phase_3_complete(), process_add(), PS_RESPAWN, and PS_WAIT_STARTED.

Referenced by on_phase_2_complete(), and start_phase_2().

00239 {
00240     LOGPRINTF("entry");
00241 
00242     // detect hardware, mount volumes
00243     hal_add_devices();
00244      
00245     process_add("/usr/bin/ctb", NULL, G_CALLBACK(on_phase_3_complete), NULL, PS_WAIT_STARTED | PS_RESPAWN);
00246 }

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 92 of file sysd/src/main.c.

00093 {
00094     static const char *usage_text = 
00095                         "\n"
00096                         "usage: %s [options]\n"
00097                         "\n"
00098                         "options:\n"
00099                         "    --help\n"
00100                         "        Print help text and quit\n"
00101                         "    --detach\n"
00102                         "        Detach from console to run as daemon\n";
00103     printf(usage_text, argv_0);
00104 
00105     exit(1);
00106 }


Variable Documentation

gboolean do_detach = FALSE [static]

Copyright (C) 2008 iRex Technologies B.V. All rights reserved.

Definition at line 79 of file sysd/src/main.c.

Referenced by main(), and parse_arguments().

Generated by  doxygen 1.6.2-20100208