int main(int argc, char **argv) { bool retVal; gboolean debug = FALSE; gboolean fake_battery = FALSE; gboolean visual_leds_suspend = FALSE; gboolean verbose = FALSE; gboolean err_on_crit = FALSE; gboolean fasthalt = FALSE; gint maxtemp = 0; gint temprate = 0; GOptionEntry entries[] = { {"debug", 'd', 0, G_OPTION_ARG_NONE, &debug, "turn debug logging on", NULL}, {"use-fake-battery", 'b', 0, G_OPTION_ARG_NONE, &fake_battery, "Use fake battery", NULL}, {"visual-leds-suspend", 'l', 0, G_OPTION_ARG_NONE, &visual_leds_suspend, "Use LEDs to show wake/suspend state", NULL}, {"verbose-syslog", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Use Verbose syslog output", NULL}, {"error-on-critical", 'e', 0, G_OPTION_ARG_NONE, &err_on_crit, "Crash on critical error", NULL}, {"maxtemp", 'M', 0, G_OPTION_ARG_INT, &maxtemp, "Set maximum temperature before shutdown (default 60)", NULL}, {"temprate", 'T', 0, G_OPTION_ARG_INT, &temprate, "Expected maxiumum temperature slew rate (default 12)", NULL}, {"fasthalt", 'F', 0, G_OPTION_ARG_NONE, &fasthalt, "On overtemp, shut down quickly not cleanly", NULL}, { NULL } }; GError *error = NULL; GOptionContext *ctx; ctx = g_option_context_new(" - power daemon"); g_option_context_add_main_entries(ctx, entries, NULL); if (!g_option_context_parse(ctx, &argc, &argv, &error)) { g_critical("option parsing failed: %s", error->message); exit(1); } // FIXME integrate this into TheOneInit() LOGInit(); LOGSetHandler(LOGSyslog); if (debug) { powerd_debug = true; LOGSetLevel(G_LOG_LEVEL_DEBUG); LOGSetHandler(LOGGlibLog); } signal(SIGTERM, term_handler); signal(SIGINT, term_handler); if (!g_thread_supported ()) g_thread_init (NULL); mainloop = g_main_loop_new(NULL, FALSE); /** * initialize the lunaservice and we want it before all the init * stuff happening. */ LSError lserror; LSErrorInit(&lserror); retVal = LSRegisterPalmService("com.palm.power", &psh, &lserror); if (!retVal) { goto ls_error; } retVal = LSGmainAttachPalmService(psh, mainloop, &lserror); if (!retVal) { goto ls_error; } private_sh = LSPalmServiceGetPrivateConnection(psh); /** * Calls the init functions of all the modules in priority order. */ TheOneInit(); g_main_loop_run(mainloop); end: g_main_loop_unref(mainloop); // save time before quitting... timesaver_save(); return 0; ls_error: g_critical("Fatal - Could not initialize powerd. Is LunaService Down?. %s", lserror.message); LSErrorFree(&lserror); goto end; }
/** * Main entry point for sleepd - runs the initialization hooks installed at program load time * * A bit counter-intuitively, this is not the first part of this program which * is run. * * First, everything which uses the {@link INIT_FUNC} macro in init.h are run, * which registers a bunch of hooks with the initialization system so that * individual modules can be registered without touching the main sleepd * initialization code. Then, once all of those hooks are installed, execution * proceeds to this function which actually runs those hooks. * * - Initializes sleepd. * - Attaches as a Luna service under com.palm.sleep. * - Attaches to Nyx. * - Subscribes to events related to the charger being plugged and unplugged from the com.palm.power service. * - Calls {@link TheOneInit()} to finish initialization of the service. * - Issues a request to the com.palm.power service to check on the plugged/unplugged status of the charger. * * @param argc Number of command-line arguments. * @param argv List of command-line arguments. * * @todo Move the logging initialization functionality into {@link TheOneInit()}. */ int main(int argc, char **argv) { bool retVal; /* * Register a function to be able to gracefully handle termination signals * from the OS or other processes. */ signal(SIGTERM, term_handler); signal(SIGINT, term_handler); #if !GLIB_CHECK_VERSION(2,32,0) if (!g_thread_supported()) { g_thread_init(NULL); } #endif mainloop = g_main_loop_new(NULL, FALSE); /* * initialize the lunaservice and we want it before all the init * stuff happening. */ LSError lserror; LSErrorInit(&lserror); /* * Register ourselves as the com.palm.sleep service. */ retVal = LSRegisterPalmService("com.palm.sleep", &psh, &lserror); if (retVal) { /* * Attach our main loop to the service so we can process IPC messages addressed to us. */ retVal = LSGmainAttachPalmService(psh, mainloop, &lserror); if (retVal) { /* * Get our private bus for our service so we can pass a message to com.palm.power. */ private_sh = LSPalmServiceGetPrivateConnection(psh); /* * Register with com.palm.power for events regarding changes in status * to the plug/unplug state of any chargers which may be attached to our * device. */ retVal = LSCall(private_sh, "luna://com.palm.lunabus/signal/addmatch", "{\"category\":\"/com/palm/power\"," "\"method\":\"USBDockStatus\"}", ChargerStatus, NULL, NULL, &lserror); if (retVal) { /* * Connect to Nyx so we can use it later. */ int ret = nyx_device_open(NYX_DEVICE_SYSTEM, "Main", &nyxSystem); if (ret != NYX_ERROR_NONE) { SLEEPDLOG_CRITICAL(MSGID_NYX_DEVICE_OPEN_FAIL, 1, PMLOGKS(CAUSE, "Unable to open the nyx device system"), ""); abort(); } /* * Call our main initialization function - this is the function which * is supposed to handle initializing pretty much everything for us. */ TheOneInit(); /* * Now that we've got something listening for charger status changes, * request the current state of the charger from com.palm.power. */ LSCall(private_sh, "luna://com.palm.power/com/palm/power/chargerStatusQuery", "{}", ChargerStatus, NULL, NULL, &lserror); SLEEPDLOG_DEBUG("Sleepd daemon started"); g_main_loop_run(mainloop); } } } else { SLEEPDLOG_CRITICAL(MSGID_SRVC_REGISTER_FAIL, 1, PMLOGKS(ERRTEXT, lserror.message), "Could not initialize sleepd"); LSErrorFree(&lserror); } g_main_loop_unref(mainloop); return 0; }
int main(int argc, char **argv) { bool retVal; // FIXME integrate this into TheOneInit() LOGInit(); LOGSetHandler(LOGSyslog); signal(SIGTERM, term_handler); signal(SIGINT, term_handler); if (!g_thread_supported ()) g_thread_init (NULL); mainloop = g_main_loop_new(NULL, FALSE); /** * initialize the lunaservice and we want it before all the init * stuff happening. */ LSError lserror; LSErrorInit(&lserror); retVal = LSRegisterPalmService("com.palm.sleep", &psh, &lserror); if (!retVal) { goto ls_error; } retVal = LSGmainAttachPalmService(psh, mainloop, &lserror); if (!retVal) { goto ls_error; } private_sh = LSPalmServiceGetPrivateConnection(psh); retVal = LSCall(private_sh,"luna://com.palm.lunabus/signal/addmatch","{\"category\":\"/com/palm/power\"," "\"method\":\"USBDockStatus\"}", ChargerStatus, NULL, NULL, &lserror); if (!retVal) { SLEEPDLOG(LOG_CRIT,"Error in registering for luna-signal \"chargerStatus\""); goto ls_error; } int ret = nyx_device_open(NYX_DEVICE_SYSTEM, "Main", &nyxSystem); if(ret != NYX_ERROR_NONE) { SLEEPDLOG(LOG_CRIT,"Sleepd: Unable to open the nyx device system"); abort(); } TheOneInit(); LSCall(private_sh,"luna://com.palm.power/com/palm/power/chargerStatusQuery","{}",ChargerStatus,NULL,NULL,&lserror); SLEEPDLOG(LOG_INFO,"Sleepd daemon started\n"); g_main_loop_run(mainloop); end: g_main_loop_unref(mainloop); return 0; ls_error: SLEEPDLOG(LOG_CRIT,"Fatal - Could not initialize sleepd. Is LunaService Down?. %s", lserror.message); LSErrorFree(&lserror); goto end; }