Beispiel #1
0
MojErr MojLunaService::open(const MojChar* serviceName)
{
    LOG_TRACE("Entering function %s", __FUNCTION__);

	MojErr err =  MojService::open(serviceName);
	MojErrCheck(err);

	bool retVal;
	MojLunaErr lserr;

	// create service handle
	if (m_allowPublicMethods) {
		retVal = LSRegisterPalmService(serviceName, &m_service, lserr);
		MojLsErrCheck(retVal, lserr);

		LSHandle* handle = LSPalmServiceGetPublicConnection(m_service);
		retVal = LSSubscriptionSetCancelFunction(handle, handleCancel, this, lserr);
		MojLsErrCheck(retVal, lserr);

		handle = LSPalmServiceGetPrivateConnection(m_service);
		retVal = LSSubscriptionSetCancelFunction(handle, handleCancel, this, lserr);
		MojLsErrCheck(retVal, lserr);
	} else {
		retVal = LSRegister(serviceName, &m_handle, lserr);
		MojLsErrCheck(retVal, lserr);
		retVal = LSSubscriptionSetCancelFunction(m_handle, handleCancel, this, lserr);
		MojLsErrCheck(retVal, lserr);
	}
	return MojErrNone;
}
bool service_register(const char *name)
{
	bool rc;
	LSError err;
	LSErrorInit(&err);

	loop = g_main_loop_new(NULL, FALSE);

	if(loop == NULL)
		goto end;

	rc = LSRegisterPalmService(name, &handle, &err);
	if(rc)
	{
		pub = LSPalmServiceGetPublicConnection(handle);
		prv = LSPalmServiceGetPrivateConnection(handle);
	}
	else
		goto end;

	rc = LSPalmServiceRegisterCategory(handle, "/", methods, NULL, NULL,
					   NULL, &err);
	LSGmainAttachPalmService(handle, loop, &err);
	if(!rc)
		goto end;
end:
	if(LSErrorIsSet(&err))
	{
		LSErrorPrint(&err, stderr);
		LSErrorFree(&err);
		puts("servece startup error...");
	}
	return rc;
}
bool luna_service_initialize(const char *dbusAddress) {

  bool returnVal = FALSE;

  LSError lserror;
  LSErrorInit(&lserror);

  loop = g_main_loop_new(NULL, FALSE);
  if (loop==NULL)
    goto end;

  returnVal = LSRegisterPalmService(dbusAddress, &serviceHandle, &lserror);
  if (returnVal) {
    pub_serviceHandle = LSPalmServiceGetPublicConnection(serviceHandle);
    priv_serviceHandle = LSPalmServiceGetPrivateConnection(serviceHandle);
  } else
    goto end;

  returnVal =  register_methods(serviceHandle, lserror);
  if (returnVal) {
    LSGmainAttachPalmService(serviceHandle, loop, &lserror);
  }

 end:
  if (LSErrorIsSet(&lserror)) {
    LSErrorPrint(&lserror, stderr);
    LSErrorFree(&lserror);
  }

  return returnVal;
}
Beispiel #4
0
void InputManager::startService()
{
	LSError lserror;
	LSErrorInit(&lserror);
	bool result;
	
	GMainLoop* mainLoop = HostBase::instance()->mainLoop();

	g_debug ("%s starting", __PRETTY_FUNCTION__);

	result = LSRegisterPalmService(LUNA_KEYS, &m_palmService, &lserror);
	if (!result) goto Error;

	// Save off public and private bus handles
	m_publicService = LSPalmServiceGetPublicConnection(m_palmService);
	if (NULL == m_publicService) {
		g_message("unable to get public handle");
	}

	
	m_service = LSPalmServiceGetPrivateConnection(m_palmService);
	if (NULL == m_service) {
		g_message("unable to get private handle");
	}

	// We're providing the notion of "key categories" that you can
	// subscribe to in order to get notifications when a key is pressed
	result = LSPalmServiceRegisterCategory(m_palmService, CATEGORY_AUDIO, s_audioMethods, NULL, NULL, this, &lserror);
	if (!result) goto Error;

	// For now the media keys are the only ones that have been requested
	// to be put on the public bus -- the calling syntax is a little
	// strange, but when using this call everything on the public bus
	// is also put on the private bus
	result = LSPalmServiceRegisterCategory(m_palmService, CATEGORY_MEDIA, s_mediaMethods, NULL, NULL, this, &lserror);
	if (!result) goto Error;
	
	result = LSPalmServiceRegisterCategory(m_palmService, CATEGORY_SWITCHES, s_switchesMethods, NULL, NULL, this, &lserror);
	if (!result) goto Error;

	result = LSPalmServiceRegisterCategory(m_palmService, CATEGORY_HEADSET, s_headsetMethods, NULL, NULL, this, &lserror);
	if (!result) goto Error;

	result = LSGmainAttachPalmService(m_palmService, mainLoop, &lserror);
	if (!result) goto Error;
	
	g_debug ("%s service started", LUNA_KEYS);

	return;

Error:
	if (LSErrorIsSet(&lserror)) {
		LSErrorPrint(&lserror, stderr);
		LSErrorFree(&lserror);
	}

	g_debug(":%s: Unable to start service", __PRETTY_FUNCTION__);
}
bool ImageServices::init(MainLoopProvider * p)
{
	if (p == NULL)
		return false;
	
	//grab the main loop ptr from the provider
	m_p_mainloop = p->getMainLoopPtr();
	if (m_p_mainloop == NULL)
		return false;
	
	//register the service
	LSError lsError;
	bool result;

	LSErrorInit(&lsError);

	// Register the service
	result = LSRegisterPalmService("com.palm.image", &m_service, &lsError);
	if (!result) {
		g_warning("Failed to register service: com.palm.image");
		return false;
	}

	m_serviceHandlePublic = LSPalmServiceGetPublicConnection(m_service);
	m_serviceHandlePrivate = LSPalmServiceGetPrivateConnection(m_service);
	result = LSGmainAttachPalmService(m_service, m_p_mainloop, &lsError);
	if (!result) {
		g_warning("Failed to attach service handle to main loop");
		LSErrorFree(&lsError);
		LSErrorInit(&lsError);
		result = LSUnregisterPalmService(m_service,&lsError);
		if (!result)
			LSErrorFree(&lsError);
		return false;
	}
	
	//register methods
	result = LSPalmServiceRegisterCategory( m_service, "/", s_methods_public, s_methods_private,
			NULL, this, &lsError);
	if (!result) {
		g_warning("Failed in registering handler methods on /: %s", lsError.message);
		LSErrorFree(&lsError);
		result = LSUnregisterPalmService(m_service,&lsError);
		if (!result)
			LSErrorFree(&lsError);
		return false;
	}

	return true;

}
int main(int argc, char **argv)
{
	LSError lserror;

	g_type_init();

	g_log_set_handler (NULL, G_LOG_LEVEL_MASK, log_handler, NULL);

	signal(SIGTERM, signal_term_handler);
	signal(SIGINT, signal_term_handler);

	mainloop = g_main_loop_new(NULL, FALSE);

	LSErrorInit(&lserror);

	if (!LSRegisterPalmService("org.webosinternals.service.update", &palm_service_handle, &lserror)) {
		g_error("Failed to initialize the Luna Palm service: %s", lserror.message);
		LSErrorFree(&lserror);
		goto cleanup;
	}

	if (!LSGmainAttachPalmService(palm_service_handle, mainloop, &lserror)) {
		g_error("Failed to attach to glib mainloop for palm service: %s", lserror.message);
		LSErrorFree(&lserror);
		goto cleanup;
	}

	private_service_handle = LSPalmServiceGetPrivateConnection(palm_service_handle);

	initialize_luna_service();

	g_main_loop_run(mainloop);

cleanup:
	shutdown_luna_service();

	if (palm_service_handle != NULL && LSUnregisterPalmService(palm_service_handle, &lserror) < 0) {
		g_error("Could not unregister palm service: %s", lserror.message);
		LSErrorFree(&lserror);
	}

	g_source_remove(signal);

	g_main_loop_unref(mainloop);

	return 0;
}
bool SysmgrDebuggerService::startup()
{
	LSError lserror;
	LSErrorInit(&lserror);
	bool result;

	if (m_p_service)
	{
		qWarning() << __FUNCTION__ << " will exit since it seems the service handle is already active; shutdown first" ;
		return true;
	}

	GMainLoop *mainLoop = HostBase::instance()->mainLoop();

	result = LSRegisterPalmService("com.palm.sysmgrdebugger", &m_p_service, &lserror);
	if (!result)
	{
		qWarning() << __FUNCTION__ << " failed" ;
		LSErrorFree(&lserror);
		m_p_service = 0;
		return false;
	}

	result = LSPalmServiceRegisterCategory( m_p_service, "/", s_public_methods, s_private_methods,
			NULL, NULL, &lserror);
	if (!result)
	{
		qWarning() << __FUNCTION__ << " failed" ;
		LSErrorFree(&lserror);
		(void)shutdown();
		return false;
	}

	result = LSGmainAttachPalmService(m_p_service, mainLoop, &lserror);
	if (!result)
	{
		qWarning() << __FUNCTION__ << " failed" ;
		LSErrorFree(&lserror);
		(void)shutdown();
		return false;
	}

	//qDebug() << __FUNCTION__ << " Ok" ;
	return true;
}
Beispiel #8
0
/**
 * Connect to mediaserver using lunaservice.
 */
LSPalmService* SoundPlayer::connectToBus()
{
	PRINTF_BLUE("SoundPlayer::connectToBus(%s)", getStateName());
	VERIFY(m_state == eState_Connecting);
	setState(eState_Connecting);

	if (m_serviceHandle)
		return m_serviceHandle;

	bool result = true;
	LSError lserror;
	LSErrorInit(&lserror);

	result = LSRegisterPalmService(NULL, &m_serviceHandle, &lserror);
	if (!result)
	{
		CRITICAL("SoundPlayer::connectToBus: Could not register SoundPlayer");
		LSErrorPrint(&lserror, stderr);
		LSErrorFree(&lserror);
		// Make next health check fail ASAP...
		m_lastPlayingTime = 0;
		return NULL;
	}

	result = LSGmainAttachPalmService (m_serviceHandle, HostBase::instance()->mainLoop(), &lserror);
	if (!result)
	{
		CRITICAL("SoundPlayer::connectToBus: Could not attach SoundPlayer to main loop");
		LSErrorPrint(&lserror, stderr);
		LSErrorFree(&lserror);
		// Make next health check fail ASAP...
		m_lastPlayingTime = 0;
		return NULL;
	}
	return m_serviceHandle;
}
Beispiel #9
0
int
main(int argc, char **argv)
{
    bool retVal;
    int opt;
    bool invertCarrier = false;

    LSPalmService * lsps = NULL;

    while ((opt = getopt(argc, argv, "chdst")) != -1)
    {
        switch (opt) {
        case 'c':
            invertCarrier = true;
            break;
        case 'd':
            setLogLevel(G_LOG_LEVEL_DEBUG);
            break;
        case 's':
            setUseSyslog(true);
            break;
        case 'h':
        default:
            PrintUsage(argv[0]);
            return EXIT_SUCCESS;
        }
    }

	// make sure we aren't already running.  
	if (!LockProcess("storaged")) {
		g_error("%s: %s daemon is already running.\n", __func__, argv[0]);
		exit(EXIT_FAILURE);
	}


    g_log_set_default_handler(logFilter, NULL);
    g_debug( "entering %s in %s", __func__, __FILE__ );

    signal(SIGTERM, term_handler);

    g_mainloop = g_main_loop_new(NULL, FALSE);


 	int ret = nyx_device_open(NYX_DEVICE_SYSTEM, "Main", &nyxSystem);
 	if(ret != NYX_ERROR_NONE)
 	{
 		g_critical("Unable to open the nyx device system");
 		abort();
 	}
 	else
 		g_debug("Initialized nyx system device");

    /**
     *  initialize the lunaservice and we want it before all the init
     *  stuff happening.
     */
    LSError lserror;
    LSErrorInit(&lserror);

    retVal = LSRegisterPalmService("com.palm.storage", &lsps, &lserror);
    if (!retVal)
    {
        g_critical ("failed in function %s with erro %s", lserror.func, lserror.message);
        LSErrorFree(&lserror);
        return EXIT_FAILURE;
    }

    SignalsInit( lsps );

    LSHandle *lsh_priv = LSPalmServiceGetPrivateConnection(lsps);
    LSHandle *lsh_pub = LSPalmServiceGetPublicConnection(lsps);

    DiskModeInterfaceInit( g_mainloop, lsh_priv, lsh_pub, invertCarrier );
    EraseInit(g_mainloop, lsh_priv);

    retVal = LSGmainAttach( lsh_priv, g_mainloop, &lserror ); 
    if ( !retVal )
    {
        g_critical( "LSGmainAttach private returned %s", lserror.message );
        LSErrorFree(&lserror);
    }
    retVal = LSGmainAttach( lsh_pub, g_mainloop, &lserror ); 
    if ( !retVal )
    {
        g_critical( "LSGmainAttach public returned %s", lserror.message );
        LSErrorFree(&lserror);
    }
    g_main_loop_run(g_mainloop);
    g_main_loop_unref(g_mainloop);

    if (!LSUnregister( lsh_priv, &lserror)) {
        g_critical( "LSUnregister private returned %s", lserror.message );
    }
    if (!LSUnregister( lsh_pub, &lserror)) {
        g_critical( "LSUnregister public returned %s", lserror.message );
    }

	UnlockProcess();

    g_debug( "exiting %s in %s", __func__, __FILE__ );

    if (!retVal)
        return EXIT_FAILURE;
    else
        return EXIT_SUCCESS;
}
Beispiel #10
0
/**
 * 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;
}
Beispiel #11
0
int main(int argc, char **argv)
{
	GOptionContext *context;
	LSError lserror;
	GError *err = NULL;
	guint signal;
	struct telephony_service *service;

	g_message("Telephony Interface Layer Daemon %s", VERSION);

	g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, debug_handler, NULL);

	context = g_option_context_new(NULL);
	g_option_context_add_main_entries(context, options, NULL);

	if (g_option_context_parse(context, &argc, &argv, &err) == FALSE) {
		if (err != NULL) {
			g_printerr("%s\n", err->message);
			g_error_free(err);
			exit(1);
		}

		g_printerr("An unknown error occurred\n");
		exit(1);
	}

	g_option_context_free(context);

	if (option_version == TRUE) {
		printf("%s\n", VERSION);
		exit(0);
	}

	if (option_detach == TRUE) {
		if (daemon(0, 0)) {
			perror("Can't start daemon");
			return 1;
		}
	}

	signal = setup_signalfd();

	event_loop = g_main_loop_new(NULL, FALSE);

	LSErrorInit(&lserror);

	if (!LSRegisterPalmService("com.palm.telephony", &palm_serivce_handle, &lserror)) {
		g_error("Failed to initialize the Luna Palm service: %s", lserror.message);
		LSErrorFree(&lserror);
		goto cleanup;
	}

	if (!LSGmainAttachPalmService(palm_serivce_handle, event_loop, &lserror)) {
		g_error("Failed to attach to glib mainloop for palm service: %s", lserror.message);
		LSErrorFree(&lserror);
		goto cleanup;
	}

	private_service_handle = LSPalmServiceGetPrivateConnection(palm_serivce_handle);

	service = telephony_service_create(palm_serivce_handle);
	/* FIXME this should be done as part of a plugin mechanism */
	ofono_init(service);

	g_main_loop_run(event_loop);

cleanup:
	/* FIXME this should be done as part of a plugin mechanism */
	ofono_exit(service);

	telephony_service_free(service);

	if (palm_serivce_handle != NULL && LSUnregisterPalmService(palm_serivce_handle, &lserror) < 0) {
		g_error("Could not unregister palm service: %s", lserror.message);
		LSErrorFree(&lserror);
	}

	g_source_remove(signal);

	g_main_loop_unref(event_loop);

	return 0;
}
Beispiel #12
0
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;
}
Beispiel #13
0
int main(int argc, char ** argv)
{
    setenv("QT_PLUGIN_PATH","/usr/plugins",1);
    setenv("QT_QPA_PLATFORM", "minimal",1);
    QApplication app(argc, argv);

	parseCommandlineOptions(argc, argv);
	setLoglevel(Settings::settings()->m_logLevel.c_str());

	g_log_set_default_handler(logFilter, NULL);
	g_warning("Started");

	SystemRestore::createSpecialDirectories();
	
	// Initialize the Preferences database
	(void) PrefsDb::instance();
	///and system restore (refresh settings while I'm at it...)
	SystemRestore::instance()->refreshDefaultSettings();
	
	//run startup restore before anything else starts
	SystemRestore::startupConsistencyCheck();
	
	Mainloop * mainLoopObj = new Mainloop();
	g_gmainLoop = mainLoopObj->getMainLoopPtr();
	
	//GMainLoop* mainLoop =  g_main_loop_new(NULL, FALSE);	
	
	LSPalmService* serviceHandle = NULL;
	LSError lsError;
	bool result;

	LSErrorInit(&lsError);

	// Register the service
	result = LSRegisterPalmService("com.palm.systemservice", &serviceHandle, &lsError);
	if (!result) {
		g_warning("Failed to register service: com.palm.sysservice");
		return -1;
	}

//	LSHandle * serviceHandlePublic = LSPalmServiceGetPublicConnection(serviceHandle);
	LSHandle * serviceHandlePrivate = LSPalmServiceGetPrivateConnection(serviceHandle);
		
	result = LSGmainAttachPalmService(serviceHandle, g_gmainLoop, &lsError);
	if (!result) {
		g_warning("Failed to attach service handle to main loop");
		return -1;
	}

	//turn novacom on if requested
	if (Settings::settings()->m_turnNovacomOnAtStartup)
	{
		turnNovacomOn(serviceHandlePrivate);
	}

	if ((result = LSCall(serviceHandlePrivate,"palm://com.palm.bus/signal/registerServerStatus",
			"{\"serviceName\":\"com.palm.image2\", \"subscribe\":true}",
			cbComPalmImage2Status,NULL,NULL, &lsError)) == false)
	{
		//non-fatal
		LSErrorFree(&lsError);
		LSErrorInit(&lsError);
	}

	// register for storage daemon signals
	result = LSCall(serviceHandlePrivate,
			"palm://com.palm.lunabus/signal/addmatch",
			"{\"category\":\"/storaged\", \"method\":\"MSMAvail\"}",
			SystemRestore::msmAvailCallback, NULL, SystemRestore::instance()->getLSStorageToken(), &lsError);
	if (!result)
		return -1;

	result = LSCall(serviceHandlePrivate,
			"palm://com.palm.lunabus/signal/addmatch",
			"{\"category\":\"/storaged\", \"method\":\"MSMProgress\"}",
			SystemRestore::msmProgressCallback, NULL, SystemRestore::instance()->getLSStorageToken(), &lsError);
	if (!result)
		return -1;

	result = LSCall(serviceHandlePrivate,
			"palm://com.palm.lunabus/signal/addmatch",
			"{\"category\":\"/storaged\", \"method\":\"MSMEntry\"}",
			SystemRestore::msmEntryCallback, NULL, SystemRestore::instance()->getLSStorageToken(), &lsError);
	if (!result)
		return -1;

	result = LSCall(serviceHandlePrivate,
			"palm://com.palm.lunabus/signal/addmatch",
			"{\"category\":\"/storaged\", \"method\":\"MSMFscking\"}",
			SystemRestore::msmFsckingCallback, NULL, SystemRestore::instance()->getLSStorageToken(), &lsError);
	if (!result)
		return -1;

	result = LSCall(serviceHandlePrivate,
			"palm://com.palm.lunabus/signal/addmatch",
			"{\"category\":\"/storaged\", \"method\":\"PartitionAvail\"}",
			SystemRestore::msmPartitionAvailCallback, NULL, SystemRestore::instance()->getLSStorageToken(), &lsError);
	if (!result)
		return -1;

	// Initialize the Prefs Factory
	PrefsFactory::instance()->setServiceHandle(serviceHandle);
	BackupManager::instance()->setServiceHandle(serviceHandle);

	//init the image service
	ImageServices * imgSvc = ImageServices::instance(mainLoopObj);
	if (!imgSvc) {
		g_warning("Image service failed init!");
	}

	//init the timezone service;
	TimeZoneService* tzSvc = TimeZoneService::instance();
	tzSvc->setServiceHandle(serviceHandle);
	
	// Run the main loop
	g_main_loop_run(g_gmainLoop);
	
	return 0;
}
Beispiel #14
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;
}