#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <signal.h>#include <sys/wait.h>#include <gtk/gtk.h>#include <liberipc/eripcbusyd.h>#include <liberipc/eripccontentlister.h>#include <liberregxml/erregapi.h>#include "config.h"#include "languages.h"#include "control.h"#include "systemcalls.h"#include "logging.h"#include "displayUpdate.h"#include "sharethread.h"#include "main.h"Go to the source code of this file.
Functions | |
| static void | parse_arguments (int argc, char **argv) |
| static void | on_sigterm (int signo) |
| gboolean | main_get_background () |
| void | main_report_new_content () |
| static void | load_registry (void) |
| static void | release_registry (void) |
| static void | on_destroy (GtkWidget *widget, gpointer data) |
| int | main (int argc, char *argv[]) |
Variables | |
| static erClientChannel_t | contentListerChannel = NULL |
| static gboolean | g_background = FALSE |
| static void load_registry | ( | void | ) | [static] |
Definition at line 119 of file main.c.
00120 { 00121 gboolean b; 00122 regLoad_t regLoad; 00123 00124 b = erRegRWLockInit(); 00125 if (b == FALSE) 00126 { 00127 DL_ERRORPRINTF("erRegRWLockInit fails with return code [%d]", b); 00128 g_assert_not_reached(); 00129 } 00130 00131 b = erRegReadLock(); 00132 if (b == FALSE) 00133 { 00134 DL_ERRORPRINTF("erRegReadLock fails with return code [%d]", b); 00135 g_assert_not_reached(); 00136 } 00137 00138 regLoad = erRegLoad(regBasis_t); 00139 if (regLoad == loadError_t) 00140 { 00141 DL_ERRORPRINTF("erRegLoad(regBasis_t) fails with return code [%d]", regLoad); 00142 g_assert_not_reached(); 00143 } 00144 00145 // release lock, all data now in memory 00146 erRegUnlock(); 00147 }

| int main | ( | int | argc, | |
| char * | argv[] | |||
| ) |
Definition at line 165 of file main.c.
00166 { 00167 GtkWidget* window; 00168 shareMgr_t* theShareMgr; 00169 int nRet; 00170 gboolean ok; 00171 00172 // catch the SIGTERM signal 00173 struct sigaction on_term; 00174 memset(&on_term, 0x00, sizeof(on_term)); 00175 on_term.sa_handler = on_sigterm; 00176 sigaction(SIGTERM, &on_term, NULL); 00177 00178 DL_WARNPRINTF(PACKAGE_STRING); 00179 00180 parse_arguments(argc, argv); 00181 00182 // minimum battery charge required for background mode 00183 if (g_background) 00184 { 00185 if (get_battery_charge() <= BATTERY_MINCHARGE_BACKGROUND) 00186 { 00187 DL_ERRORPRINTF("Insufficient battery [%d] for background PC connect -> quit", get_battery_charge()); 00188 return NO_ERROR; 00189 } 00190 } 00191 00192 /* init threads */ 00193 g_thread_init(NULL); 00194 gdk_threads_init(); 00195 00196 // open the RC file associated with this program (re-use the downloadMgr one) 00197 gtk_rc_parse(DATA_DIR "/downloadMgr.rc"); 00198 DL_LOGPRINTF("rc file %s", DATA_DIR "/downloadMgr.rc"); 00199 00200 gtk_init(&argc, &argv); 00201 00202 load_registry(); 00203 languagesInit(); 00204 00205 // create/init the channel to communicate with the content lister 00206 nRet = erIpcStartClient(ER_CONTENTLISTER_CHANNEL, &contentListerChannel); 00207 if (nRet != 0) 00208 { 00209 DL_ERRORPRINTF("erIpcStartClient returned %d", nRet); 00210 contentListerChannel = NULL; 00211 } 00212 00213 // create the main, top level, window 00214 window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 00215 gtk_window_set_title(GTK_WINDOW(window), PACKAGE " " VERSION); 00216 gtk_window_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); 00217 gtk_container_set_border_width(GTK_CONTAINER(window), 0); 00218 // gtk_widget_set_size_request(GTK_WIDGET(window), SCREEN_WIDTH, SCREEN_HEIGHT); 00219 gtk_window_set_modal(GTK_WINDOW(window), FALSE); 00220 gtk_window_set_resizable(GTK_WINDOW(window), FALSE); 00221 gtk_window_fullscreen(GTK_WINDOW(window)); // Fullscreen overlap taskbars 00222 00223 theShareMgr = ctrlInit(window); 00224 00225 if (theShareMgr) 00226 { 00227 // Connect the destroy event of the window with our on_destroy function 00228 // When the window is about to be destroyed we get a notification and 00229 // stop the main GTK loop 00230 g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(on_destroy), NULL); 00231 00232 // make sure that everything, window and label, are visible 00233 if ( !g_background ) 00234 { 00235 gtk_widget_show(window); 00236 } 00237 } 00238 00239 // Start the download thread 00240 ok = shareThread_start((gpointer)theShareMgr); 00241 if (!ok) 00242 { 00243 printf("%s %s: ", __FILE__, __FUNCTION__); 00244 perror("Could not create thread\n"); 00245 } 00246 00247 // run the GTK main loop 00248 DL_LOGPRINTF("Before gtk_main"); 00249 gdk_threads_enter(); 00250 gtk_main(); 00251 gdk_threads_leave(); 00252 nRet = theShareMgr->returnVal; 00253 DL_LOGPRINTF("exitValue after gtk_main [%d]", nRet); 00254 00255 // GTK done, abort any copying that might be running 00256 shareThread_stop(); 00257 shareThread_wait(15); 00258 00259 DL_WARNPRINTF("PC Share Manager quitting with return value \"%d\"", nRet); 00260 ctrlDestroy(theShareMgr); 00261 00262 release_registry(); 00263 00264 return nRet; 00265 }

| gboolean main_get_background | ( | void | ) |
Definition at line 106 of file main.c.
00107 { 00108 DL_LOGPRINTF("entry"); 00109 return g_background; 00110 }
| void main_report_new_content | ( | ) |
Definition at line 112 of file main.c.
00113 { 00114 DL_LOGPRINTF("entry"); 00115 clNewContent(contentListerChannel); 00116 }

| static void on_destroy | ( | GtkWidget * | widget, | |
| gpointer | data | |||
| ) | [static] |
| static void on_sigterm | ( | int | signo | ) | [static] |
Definition at line 268 of file main.c.
00269 { 00270 DL_WARNPRINTF("entry pcshareMgr"); 00271 00272 if (gtk_main_level() > 0) 00273 { 00274 // stop main process 00275 gdk_threads_enter(); 00276 DL_WARNPRINTF("stop GTK main"); 00277 gtk_main_quit(); 00278 gdk_threads_leave(); 00279 } 00280 else 00281 { 00282 // not in gtk_main, probably in initialisation phase 00283 // just quit 00284 DL_WARNPRINTF("_exit(1)"); 00285 _exit(1); 00286 } 00287 }
| static void parse_arguments | ( | int | argc, | |
| char ** | argv | |||
| ) | [static] |
Definition at line 71 of file main.c.
00072 { 00073 static const char *usage_text = 00074 "\n" 00075 "usage: %s [options]\n" 00076 "\n" 00077 "options:\n" 00078 " --help\n" 00079 " Print help text and quit\n" 00080 " --background\n" 00081 " Operate in background, no GUI\n" 00082 "\n"; 00083 int i; 00084 00085 // parse connectionMgr options 00086 for (i = 0 ; i < argc ; i++) 00087 { 00088 if (strcmp(argv[i], "--help") == 0) 00089 { 00090 printf(usage_text, argv[0]); 00091 _exit(0); 00092 } 00093 else if(strcmp(argv[i], "--background") == 0) 00094 { 00095 g_background = TRUE; 00096 } 00097 else if (strncmp(argv[i], "--", 2) == 0) 00098 { 00099 printf("\nInvalid option: %s\n", argv[i]); 00100 printf(usage_text, argv[0]); 00101 _exit(1); 00102 } 00103 } 00104 }
| static void release_registry | ( | void | ) | [static] |
Definition at line 150 of file main.c.
00151 { 00152 erRegUnload(regBasis_t); 00153 erRegRWLockDestroy(); 00154 }

erClientChannel_t contentListerChannel = NULL [static] |
gboolean g_background = FALSE [static] |
1.5.6