#include "config.h"
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <string.h>
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
#include <liberipc/eripctoolbar.h>
#include <liberdm/connectionMgrConstants.h>
#include <liberdm/display.h>
#include "connectionMgrLog.h"
#include "displayStatus.h"
#include "background.h"
#include "connectScreenData.h"
#include "connectionMgr.h"
#include "connectionMgrData.h"
#include "connectScreen.h"
#include "editScreen.h"
#include "connectBackground.h"
#include "connectScan.h"
#include "pingThread.h"
#include "scanThread.h"
#include "languages.h"
#include "erbusy.h"
#include "pagebar.h"
#include "system.h"
#include "toolbar.h"
Go to the source code of this file.
Functions | |
static void | parse_arguments (int argc, char **argv) |
static gboolean | delayed_start_child_process (gpointer user_data) |
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 | load_registry (void) |
static void | release_registry (void) |
void | prepare_registry_write (void) |
void | do_registry_write (void) |
void | get_wifi_and_dialup_status (void) |
int | main (int argc, char **argv) |
void | main_quit (void) |
void | main_start_child_process (void) |
gboolean | main_get_background () |
cmgrConnectType_t | main_get_connect_type () |
gboolean | main_get_edit_only () |
gboolean | main_get_use_last_connected () |
gboolean | main_get_connect_after_reboot (void) |
gboolean | main_get_wifi_disabled (void) |
gboolean | main_get_dialup_disabled (void) |
char * | main_get_screen_title () |
Variables | |
static gboolean | g_connect_after_reboot = FALSE |
static gboolean | g_stay_connected = FALSE |
static gboolean | g_edit_only = FALSE |
static gboolean | g_background = FALSE |
static gboolean | g_content_only = FALSE |
static gchar * | g_content_uuid = NULL |
static gboolean | g_use_last_connected = FALSE |
static gboolean | g_wifi_disabled = FALSE |
static gboolean | g_dialup_disabled = TRUE |
static char * | g_screen_title = NULL |
static int | g_exitValue = CONNECT_ERROR |
static GtkWidget * | g_main_window = NULL |
static cmgrConnectType_t | g_connect_type = cmgrConnectUnknown_e |
static int | exec_argc = 0 |
static char * | exec_argv [10] |
static pid_t | g_exec_pid = 0 |
static gboolean delayed_start_child_process | ( | gpointer | user_data | ) | [static] |
Definition at line 527 of file main.c.
00528 { 00529 int i; 00530 pid_t pid; 00531 00532 CN_LOGPRINTF("entry"); 00533 00534 // execute command, when specified 00535 if (exec_argc == 0) 00536 { 00537 // no command yet: determine command to execute 00538 if (connect_data_get_connect_type() == cmgrConnectIDS_e) 00539 { 00540 exec_argv[exec_argc++] = DOWNLOADMGR_EXECUTABLE; 00541 if (g_background) 00542 { 00543 exec_argv[exec_argc++] = "--background"; 00544 } 00545 if (g_content_only) 00546 { 00547 exec_argv[exec_argc++] = "--content-only"; 00548 } 00549 if (g_content_uuid) 00550 { 00551 exec_argv[exec_argc++] = "--content-uuid"; 00552 exec_argv[exec_argc++] = g_content_uuid; 00553 } 00554 } 00555 else if (connect_data_get_connect_type() == cmgrConnectPCShare_e) 00556 { 00557 exec_argv[exec_argc++] = PCSHAREMGR_EXECUTABLE; 00558 if (g_background) 00559 { 00560 exec_argv[exec_argc++] = "--background"; 00561 } 00562 } 00563 } 00564 00565 // execute command 00566 if (exec_argc > 0) 00567 { 00568 exec_argv[exec_argc] = NULL; 00569 g_assert( exec_argc < (sizeof(exec_argv)/sizeof(exec_argv[0])) ); 00570 00571 CN_WARNPRINTF("execute command [%s]", exec_argv[0]); 00572 for (i = 0 ; i < exec_argc ; i++) 00573 { 00574 CN_WARNPRINTF(" argv[%d] = [%s]", i, exec_argv[i]); 00575 } 00576 00577 pid = fork_exec_no_wait(exec_argc, exec_argv); 00578 if (pid > 0) 00579 { 00580 g_exec_pid = pid; 00581 } 00582 else 00583 { 00584 CN_ERRORPRINTF("Execute [%s] failed " 00585 "- fork_exec_no_wait returns [%d]", 00586 exec_argv[0], pid); 00587 g_exitValue = CONNECT_ERROR; 00588 } 00589 } 00590 00591 return FALSE; // don't call me again 00592 }
void do_registry_write | ( | void | ) |
Definition at line 303 of file main.c.
00304 { 00305 gboolean b; 00306 00307 // verify write lock 00308 g_assert(lock_write == erRegGetLockState()); 00309 00310 // save registry 00311 b = erRegStore(); 00312 if (b == FALSE) 00313 { 00314 CN_ERRORPRINTF("erRegStore fails with return code [%d]", b); 00315 } 00316 00317 // release lock 00318 erRegUnlock(); 00319 }
void get_wifi_and_dialup_status | ( | void | ) |
Definition at line 321 of file main.c.
00322 { 00323 int status; 00324 00325 CN_LOGPRINTF("Checking status of WiFi..."); 00326 status = system(COMMAND_STATUS_WIRELESS); 00327 if (WEXITSTATUS(status) == 0) 00328 { 00329 g_wifi_disabled = FALSE; 00330 } 00331 else 00332 { 00333 g_wifi_disabled = TRUE; 00334 } 00335 CN_LOGPRINTF("WiFi present? [%d]", g_wifi_disabled); 00336 00337 CN_LOGPRINTF("Checking status of Dialup..."); 00338 status = system(COMMAND_STATUS_DIALUP); 00339 if (WEXITSTATUS(status) == 0) 00340 { 00341 g_dialup_disabled = FALSE; 00342 } 00343 else 00344 { 00345 g_dialup_disabled = TRUE; 00346 } 00347 CN_LOGPRINTF("Dialup present? [%d]", g_dialup_disabled); 00348 }
static void load_registry | ( | void | ) | [static] |
Definition at line 223 of file main.c.
00224 { 00225 gboolean b; 00226 regLoad_t regLoad; 00227 00228 // init registry locking 00229 b = erRegRWLockInit(); 00230 if (b == FALSE) 00231 { 00232 CN_ERRORPRINTF("erRegRWLockInit fails with return code [%d]", b); 00233 g_assert_not_reached(); 00234 } 00235 00236 // acquire read-only lock 00237 b = erRegReadLock(); 00238 if (b == FALSE) 00239 { 00240 CN_ERRORPRINTF("erRegReadLock fails with return code [%d]", b); 00241 g_assert_not_reached(); 00242 } 00243 00244 // load registry sections used 00245 regLoad = erRegLoad(regBasis_t); 00246 if (regLoad == loadError_t) 00247 { 00248 CN_ERRORPRINTF("erRegLoad(regBasis_t) fails with return code [%d]", 00249 regLoad); 00250 g_assert_not_reached(); 00251 } 00252 regLoad = erRegLoad(regNWProfiles_t); 00253 if (regLoad == loadError_t) 00254 { 00255 CN_ERRORPRINTF("erRegLoad(regNWProfiles_t) " 00256 "fails with return code [%d]", 00257 regLoad); 00258 g_assert_not_reached(); 00259 } 00260 00261 // release lock, all data now in memory 00262 erRegUnlock(); 00263 }
int main | ( | int | argc, | |
char ** | argv | |||
) |
Definition at line 350 of file main.c.
00351 { 00352 GtkWidget* clientArea = NULL; 00353 GtkWidget* screens = NULL; 00354 GtkWidget* widget; 00355 00356 scanContext_t *ctxt; 00357 00358 parse_arguments(argc, argv); 00359 00360 // catch the SIGTERM signal 00361 struct sigaction on_term; 00362 memset(&on_term, 0x00, sizeof(on_term)); 00363 on_term.sa_handler = on_sigterm; 00364 sigaction(SIGTERM, &on_term, NULL); 00365 00366 // catch the SIGCHLD signal 00367 struct sigaction on_chld; 00368 memset(&on_chld, 0x00, sizeof(on_chld)); 00369 on_chld.sa_handler = on_sigchld; 00370 on_chld.sa_flags = SA_NOCLDSTOP; 00371 sigaction(SIGCHLD, &on_chld, NULL); 00372 00373 // init threads - needed for screen refresh idle handling 00374 g_thread_init(NULL); 00375 gdk_threads_init(); 00376 00377 // open the RC file associate with this program 00378 gtk_rc_parse(DATA_DIR "/connectionMgr.rc"); 00379 CN_LOGPRINTF("rc file %s", DATA_DIR "/connectionMgr.rc"); 00380 00381 gtk_init(&argc, &argv); 00382 00383 // check for WiFi and Dialup hardware status 00384 get_wifi_and_dialup_status(); 00385 00386 load_registry(); 00387 cmgr_data_init(); 00388 languagesInit(); 00389 00390 // note: set connect type only 00391 // after connection mgr data has been initialized 00392 if (g_connect_type != cmgrConnectUnknown_e) 00393 { 00394 CN_WARNPRINTF("g_connect_type [%d]", g_connect_type); 00395 connect_data_set_connect_type(g_connect_type); 00396 } 00397 00398 // init the context for scan and ping 00399 cmgr_scan_ctxt_init(); 00400 cmgr_ping_ctxt_init(); 00401 00402 if (!g_background) 00403 { 00404 erbusy_init(); 00405 pagebar_init(); 00406 toolbar_init(); 00407 cmgrInstallIpcServer(); 00408 00409 // => only request a refresh on the main window expose event 00410 display_update_increase_level(MAIN_WINDOW_EXPOSE_LEVEL); 00411 00412 // create the main, top level, window 00413 widget = gtk_window_new(GTK_WINDOW_TOPLEVEL); 00414 gtk_window_set_title(GTK_WINDOW(widget), PACKAGE " " VERSION); 00415 gtk_window_position(GTK_WINDOW(widget), GTK_WIN_POS_CENTER); 00416 gtk_container_set_border_width(GTK_CONTAINER(widget), 0); 00417 gtk_widget_set_size_request(GTK_WIDGET(widget), 00418 SCREEN_WIDTH, CLIENT_AREA); 00419 gtk_window_set_modal(GTK_WINDOW(widget), TRUE); 00420 gtk_window_set_resizable(GTK_WINDOW(widget), FALSE); 00421 g_signal_connect(G_OBJECT(widget), "destroy", 00422 G_CALLBACK(on_main_window_destroy), NULL); 00423 g_signal_connect_after(G_OBJECT(widget), "expose-event", 00424 G_CALLBACK(on_main_window_expose_event), NULL); 00425 g_signal_connect(G_OBJECT(widget), "focus-out-event", 00426 G_CALLBACK(on_main_window_focus_out_event), NULL); 00427 g_signal_connect(G_OBJECT(widget), "key-press-event", 00428 G_CALLBACK(on_cmgr_keypress), NULL); 00429 gtk_widget_show(widget); 00430 g_main_window = widget; 00431 00432 // create and display the application background and screens 00433 clientArea = bg_create(g_main_window); 00434 screens = cmgr_screens_create(); 00435 gtk_container_add(GTK_CONTAINER(clientArea), screens); 00436 00437 // show the correct screen 00438 if (main_get_edit_only()) 00439 { 00440 cmgr_set_screen_mode(cmgrScreenEdit_e); 00441 edit_set_mode(editModeNormal_e); 00442 } 00443 else 00444 { 00445 cmgr_set_screen_mode(cmgrScreenConnect_e); 00446 } 00447 } 00448 else 00449 { 00450 connect_background_restore_scan_ctxt(); 00451 ctxt = cmgr_get_scan_ctxt(); 00452 connect_scan(ctxt, FALSE); 00453 } 00454 00455 gdk_threads_enter(); 00456 gtk_main(); 00457 gdk_threads_leave(); 00458 00459 CN_WARNPRINTF("exitValue after gtk_main [%d]", g_exitValue); 00460 00461 // save connection manager settings 00462 connect_data_store(); 00463 00464 // wait for pingThread and scanThread to end 00465 pingThread_stop(); 00466 pingThread_wait(30); 00467 scanThread_stop(); 00468 scanThread_wait(30); 00469 00470 cmgr_scan_ctxt_destory(); 00471 cmgr_ping_ctxt_destory(); 00472 00473 // disconnect, unless requested otherwise 00474 if (!g_stay_connected) 00475 { 00476 connect_disable_network(); 00477 } 00478 00479 release_registry(); 00480 00481 CN_WARNPRINTF("exit connectionMgr [%d]", g_exitValue); 00482 return g_exitValue; 00483 }
gboolean main_get_background | ( | void | ) |
Definition at line 595 of file main.c.
00596 { 00597 CN_LOGPRINTF("entry"); 00598 return g_background; 00599 }
gboolean main_get_connect_after_reboot | ( | void | ) |
Definition at line 619 of file main.c.
00620 { 00621 CN_LOGPRINTF("return [%d]", g_connect_after_reboot); 00622 return g_connect_after_reboot; 00623 }
cmgrConnectType_t main_get_connect_type | ( | void | ) |
Definition at line 601 of file main.c.
00602 { 00603 CN_LOGPRINTF("return [%d]", g_connect_type); 00604 return g_connect_type; 00605 }
gboolean main_get_dialup_disabled | ( | void | ) |
Definition at line 631 of file main.c.
00632 { 00633 CN_LOGPRINTF("return [%d]", g_dialup_disabled); 00634 return g_dialup_disabled; 00635 }
gboolean main_get_edit_only | ( | void | ) |
Definition at line 607 of file main.c.
00608 { 00609 CN_LOGPRINTF("return [%d]", g_edit_only); 00610 return g_edit_only; 00611 }
char* main_get_screen_title | ( | void | ) |
Definition at line 637 of file main.c.
00638 { 00639 CN_LOGPRINTF("return [%s]", g_screen_title); 00640 return g_screen_title; 00641 }
gboolean main_get_use_last_connected | ( | void | ) |
Definition at line 613 of file main.c.
00614 { 00615 CN_LOGPRINTF("return [%d]", g_use_last_connected); 00616 return g_use_last_connected; 00617 }
gboolean main_get_wifi_disabled | ( | void | ) |
Definition at line 625 of file main.c.
00626 { 00627 CN_LOGPRINTF("return [%d]", g_wifi_disabled); 00628 return g_wifi_disabled; 00629 }
void main_quit | ( | void | ) |
Definition at line 485 of file main.c.
00486 { 00487 CN_LOGPRINTF("entry"); 00488 00489 if (g_exec_pid > 0) 00490 { 00491 // stop child process 00492 CN_WARNPRINTF("stop child process [%d]", g_exec_pid); 00493 kill(g_exec_pid, SIGTERM); 00494 } 00495 else if (gtk_main_level() > 0) 00496 { 00497 // no child process: stop gtk engine 00498 CN_WARNPRINTF("stop GTK main"); 00499 gtk_main_quit(); 00500 } 00501 else 00502 { 00503 // no child process, no in gtk_main, 00504 // probably in initialisation phase: just quit 00505 CN_WARNPRINTF("_exit(1)"); 00506 _exit(1); 00507 } 00508 }
void main_start_child_process | ( | void | ) |
Definition at line 514 of file main.c.
00515 { 00516 if (!g_background) 00517 { 00518 // no more screen updates from connection manager 00519 display_update_increase_level(NO_DISPLAY_UPDATE_LEVEL); 00520 // show_keyboard(FALSE); 00521 toolbar_setIconState(iconID_keyboard, iconState_grey); 00522 } 00523 00524 g_idle_add(delayed_start_child_process, NULL); 00525 }
static void on_main_window_destroy | ( | GtkWidget * | widget, | |
gpointer | data | |||
) | [static] |
Definition at line 684 of file main.c.
00685 { 00686 CN_WARNPRINTF("entry"); 00687 00688 //clean up or store stuff before the app ends 00689 gtk_main_quit(); 00690 }
static gboolean on_main_window_expose_event | ( | GtkWidget * | widget, | |
GdkEventExpose * | event, | |||
gpointer | p | |||
) | [static] |
Definition at line 692 of file main.c.
00695 { 00696 CN_LOGPRINTF("entry"); 00697 display_update_request_screen_refresh(MAIN_WINDOW_EXPOSE_LEVEL, 00698 WAVEFORM_FULLSCREEN); 00699 00700 if (!main_get_edit_only()) 00701 { 00702 gtk_idle_add(delay_erbusy_blink, NULL); 00703 } 00704 00705 return FALSE; 00706 }
static gboolean on_main_window_focus_out_event | ( | GtkWidget * | widget, | |
GdkEventFocus * | event, | |||
gpointer | p | |||
) | [static] |
Definition at line 708 of file main.c.
00711 { 00712 CN_LOGPRINTF("entry"); 00713 00714 return FALSE; 00715 }
static void on_sigchld | ( | int | signo | ) | [static] |
Definition at line 660 of file main.c.
00661 { 00662 CN_WARNPRINTF(" -- entry connectionMgr"); 00663 00664 // check which process has died and free resources 00665 pid_t pid; 00666 int status; 00667 while ( (pid = waitpid(-1, &status, WNOHANG)) > 0) 00668 { 00669 CN_WARNPRINTF("pid [%d]", pid); 00670 if (pid == g_exec_pid) 00671 { 00672 g_exec_pid = 0; 00673 if ( WIFEXITED(status) ) 00674 { 00675 g_exitValue = WEXITSTATUS(status); 00676 } 00677 main_quit(); 00678 } 00679 } 00680 00681 CN_WARNPRINTF(" -- leave connectionMgr"); 00682 }
static void on_sigterm | ( | int | signo | ) | [static] |
Definition at line 645 of file main.c.
00646 { 00647 CN_WARNPRINTF(" -- entry connectionMgr, my pid [%d]", getpid()); 00648 00649 // stop main process, prepare to quit application 00650 gdk_threads_enter(); 00651 main_quit(); 00652 gdk_threads_leave(); 00653 00654 show_keyboard(FALSE); 00655 g_stay_connected = FALSE; 00656 00657 CN_WARNPRINTF(" -- leave connectionMgr"); 00658 }
static void parse_arguments | ( | int | argc, | |
char ** | argv | |||
) | [static] |
Definition at line 100 of file main.c.
00101 { 00102 static const char *usage_text = 00103 "\n" 00104 "usage: %s [options]\n" 00105 "\n" 00106 "options:\n" 00107 " --help\n" 00108 " Print help text and quit\n" 00109 " --background\n" 00110 " Operate in background, no GUI\n" 00111 " --connect-ids\n" 00112 " Connect to iDS\n" 00113 " --connect-pc\n" 00114 " Connect to PC share\n" 00115 " --content-only\n" 00116 " Download content items, skip software upgrades\n" 00117 " --content-uuid <uuid>\n" 00118 " Together with --content-only, download only this content item\n" 00119 " --edit-only\n" 00120 " Edit profiles only, do connect automatically\n" 00121 " --use-last-connected\n" 00122 " Use last connected profile first\n" 00123 " --stay-connected\n" 00124 " Keep network enabled when exiting connection manager\n" 00125 " --connect-after-reboot\n" 00126 " Connect automatically after rebooting\n" 00127 " --title <text>\n" 00128 " <text> = screen title\n" 00129 " --execute\n" 00130 " When connected to IDS, execute rest of the arguments as a new command\n" 00131 "\n"; 00132 int i; 00133 00134 // parse connectionMgr options 00135 for (i = 0 ; i < argc ; i++) 00136 { 00137 if (strcmp(argv[i], "--help") == 0) 00138 { 00139 printf(usage_text, argv[0]); 00140 _exit(0); 00141 } 00142 else if(strcmp(argv[i], "--background") == 0) 00143 { 00144 g_background = TRUE; 00145 } 00146 else if(strcmp(argv[i], "--connect-ids") == 0) 00147 { 00148 g_connect_type = cmgrConnectIDS_e; 00149 } 00150 else if(strcmp(argv[i], "--connect-pc") == 0) 00151 { 00152 g_connect_type = cmgrConnectPCShare_e; 00153 } 00154 else if(strcmp(argv[i], "--content-only") == 0) 00155 { 00156 g_content_only = TRUE; 00157 } 00158 else if(strcmp(argv[i], "--content-uuid") == 0) 00159 { 00160 if (++i < argc) 00161 { 00162 g_content_uuid = argv[i]; 00163 } 00164 else 00165 { 00166 i--; // oops 00167 } 00168 } 00169 else if(strcmp(argv[i], "--edit-only") == 0) 00170 { 00171 g_edit_only = TRUE; 00172 } 00173 else if(strcmp(argv[i], "--use-last-connected") == 0) 00174 { 00175 g_use_last_connected = TRUE; 00176 } 00177 else if(strcmp(argv[i], "--stay-connected") == 0) 00178 { 00179 g_stay_connected = TRUE; 00180 } 00181 else if (strcmp(argv[i], "--connect-after-reboot") == 0) 00182 { 00183 g_connect_after_reboot = TRUE; 00184 } 00185 else if (strcmp(argv[i], "--title") == 0) 00186 { 00187 if (++i < argc) 00188 { 00189 g_screen_title = argv[i]; 00190 } 00191 else 00192 { 00193 i--; // oops 00194 } 00195 } 00196 else if (strcmp(argv[i], "--execute") == 0) 00197 { 00198 i++; 00199 if ( argc - i >= sizeof(exec_argv)/sizeof(exec_argv[0]) ) 00200 { 00201 printf("\nToo many arguments for option [%s]\n", argv[i]); 00202 printf(usage_text, argv[0]); 00203 _exit(1); 00204 } 00205 00206 exec_argc = 0; 00207 while (i < argc) 00208 { 00209 exec_argv[exec_argc++] = argv[i++]; 00210 } 00211 exec_argv[exec_argc] = NULL; 00212 } 00213 else if (strncmp(argv[i], "--", 2) == 0) 00214 { 00215 printf("\nInvalid option: %s\n", argv[i]); 00216 printf(usage_text, argv[0]); 00217 _exit(1); 00218 } 00219 } 00220 }
void prepare_registry_write | ( | void | ) |
Definition at line 277 of file main.c.
00278 { 00279 gboolean b; 00280 regLoad_t regLoad; 00281 00282 // acquire write lock 00283 b = erRegWriteLock(); 00284 if (b == FALSE) 00285 { 00286 CN_ERRORPRINTF("erRegWriteLock fails with return code [%d]", b); 00287 g_assert_not_reached(); 00288 } 00289 00290 // reload section(s) that may be written 00291 erRegUnload(regNWProfiles_t); 00292 regLoad = erRegLoad(regNWProfiles_t); 00293 if (regLoad == loadError_t) 00294 { 00295 CN_ERRORPRINTF("erRegLoad(regNWProfiles_t) fails " 00296 "with return code [%d]", 00297 regLoad); 00298 g_assert_not_reached(); 00299 } 00300 }
static void release_registry | ( | void | ) | [static] |
Definition at line 266 of file main.c.
00267 { 00268 // unload registry sections 00269 erRegUnload(regNWProfiles_t); 00270 erRegUnload(regBasis_t); 00271 00272 // discard registry locking 00273 erRegRWLockDestroy(); 00274 }
gboolean g_background = FALSE [static] |
gboolean g_connect_after_reboot = FALSE [static] |
cmgrConnectType_t g_connect_type = cmgrConnectUnknown_e [static] |
gboolean g_content_only = FALSE [static] |
gchar* g_content_uuid = NULL [static] |
gboolean g_dialup_disabled = TRUE [static] |
gboolean g_edit_only = FALSE [static] |
pid_t g_exec_pid = 0 [static] |
int g_exitValue = CONNECT_ERROR [static] |
GtkWidget* g_main_window = NULL [static] |
char* g_screen_title = NULL [static] |
gboolean g_stay_connected = FALSE [static] |
gboolean g_use_last_connected = FALSE [static] |
gboolean g_wifi_disabled = FALSE [static] |