Example #1
0
int main(void)
{
    GMainLoop *mainLoop = g_main_loop_new(NULL, FALSE);
    void *userData = mainLoop;

    g_timeout_add(10000, &OnTimeout, mainLoop);

    GThread *client_thread = g_thread_new(NULL, ClientProc, mainLoop);

    /*! [service registration] */
    bool retVal;
    LSError lserror;
    LSErrorInit(&lserror);

    LSHandle *serviceHandle = NULL;
    retVal = LSRegister("com.palm.contacts", &serviceHandle, &lserror);
    if (!retVal) goto error;

    retVal = LSRegisterCategory(serviceHandle, "/category",  ipcMethods, NULL, NULL, &lserror);
    if (!retVal) goto error;

    retVal = LSCategorySetData(serviceHandle, "/category", userData, &lserror);
    if (!retVal) goto error;

    retVal = LSGmainAttach(serviceHandle, mainLoop, &lserror);
    if (!retVal) goto error;

    g_main_loop_run(mainLoop);
    /*! [service registration] */

    LSUnregister(serviceHandle, &lserror);
    g_main_loop_unref(mainLoop);
    g_thread_join(client_thread);

    if (hit_reply)
    {
        printf("PASS\n");
        return 0;
    }

    printf("FAILED\n");
    return 1;

error:
    LSErrorPrint(&lserror, stderr);
    LSErrorFree(&lserror);

    if (serviceHandle) LSUnregister(serviceHandle, &lserror);
    g_main_loop_unref(mainLoop);
    g_thread_join(client_thread);

    fprintf(stderr, "FAILED\n");
    return 1;
}
Example #2
0
/** 
* @brief Cleanup all IPC.
*/
void
_PowerdClientIPCStop(void)
{
    if (gMainLoop)
    {
        if (!gOwnMainLoop)
            g_main_loop_quit(gMainLoop);

        g_main_loop_unref(gMainLoop);

        gMainLoop = NULL;
        gOwnMainLoop = false;
    }

    if (gServiceHandle && !gOwnLunaService)
    {
        bool retVal;
        LSError lserror;
        LSErrorInit(&lserror);

        retVal = LSUnregister(gServiceHandle, &lserror);
        if (!retVal)
        {
            LSErrorPrint(&lserror, stderr);
            LSErrorFree(&lserror);
        }
    }
    gServiceHandle = NULL;
    gOwnLunaService = false;
}
Example #3
0
void InputManager::stopService()
{
	LSError lserror;
	LSErrorInit(&lserror);
	bool result;

	result = LSUnregister(m_publicService, &lserror);
	if (!result) {
		LSErrorPrint(&lserror, stderr);
		LSErrorFree(&lserror);
	}

	result = LSUnregister(m_service, &lserror);
	if (!result) {
		LSErrorPrint(&lserror, stderr);
		LSErrorFree(&lserror);
	}
}
Example #4
0
Handle::~Handle()
{
    if (_handle)
    {
        Error error;

        if (!LSUnregister(_handle, error.get()))
        {
            error.log(PmLogGetLibContext(), "LS_FAILED_TO_UNREG");
        }
    }
}
Example #5
0
void BootManager::stopService()
{
	LSError error;
	LSErrorInit(&error);
	bool result;

	result = LSUnregister(m_service, &error);
	if (!result)
		LSErrorFree(&error);

	m_service = 0;
}
void property_service_free(struct property_service *service)
{
	LSError error;

	LSErrorInit(&error);

	if (service->handle != NULL && LSUnregister(service->handle, &error) < 0) {
		g_error("Could not unregister service: %s", error.message);
		LSErrorFree(&error);
	}

	g_free(service);
}
Example #7
0
static gpointer ClientProc(gpointer data)
{
    GMainLoop *mainLoop = g_main_loop_new(NULL, FALSE);
    gpointer userData = mainLoop;
    g_timeout_add(10000, &OnTimeout, mainLoop);

    /*! [client call] */
    bool retVal;
    LSError lserror;
    LSErrorInit(&lserror);
    LSMessageToken token = LSMESSAGE_TOKEN_INVALID;

    LSHandle *serviceHandle;
    retVal = LSRegister(NULL, &serviceHandle, &lserror);
    if (!retVal) goto error;

    retVal = LSCallOneReply(serviceHandle, "luna://com.palm.contacts/category/listContacts",
                            "{ \"json payload\" }", listContactsHandler, userData, &token, &lserror);
    if (!retVal) goto error;

    LSGmainAttach(serviceHandle, mainLoop, &lserror);
    g_main_loop_run(mainLoop);
    /*! [client call] */

    LSUnregister(serviceHandle, &lserror);
    g_main_loop_unref(mainLoop);
    g_main_loop_quit((GMainLoop *) data); // Finish the service with the client

    return GINT_TO_POINTER(0);

error:
    LSErrorPrint(&lserror, stderr);
    LSErrorFree(&lserror);

    if (serviceHandle) LSUnregister(serviceHandle, &lserror);
    g_main_loop_unref(mainLoop);
    g_main_loop_quit((GMainLoop *) data);
    return GINT_TO_POINTER(1);
}
AmbientLightSensor::~AmbientLightSensor()
{    
    LSError lserror;
    LSErrorInit(&lserror);
    bool result;

	result = LSUnregister(m_service, &lserror);
    if (!result)
    {
        g_message ("%s: failed at %s with message %s", __PRETTY_FUNCTION__, lserror.func, lserror.message);
        LSErrorFree(&lserror);
    }
}
Example #9
0
Handle &Handle::operator=(Handle &&other)
{
    if (_handle)
    {
        Error error;

        if (!LSUnregister(_handle, error.get()))
        {
            throw error;
        }
    }
    _handle = other.release();
    return *this;
}
struct property_service* property_service_create()
{
	struct property_service *service;
	LSError error;

	service = g_try_new0(struct property_service, 1);
	if (!service)
		return NULL;

	LSErrorInit(&error);

	if (!LSRegisterPubPriv("com.android.properties", &service->handle, false, &error)) {
		g_error("Failed to register the luna service: %s", error.message);
		LSErrorFree(&error);
		goto error;
	}

	if (!LSRegisterCategory(service->handle, "/", property_service_methods,
			NULL, NULL, &error)) {
		g_error("Could not register service category: %s", error.message);
		LSErrorFree(&error);
		goto error;
	}

	if (!LSCategorySetData(service->handle, "/", service, &error)) {
		g_error("Could not set daa for service category: %s", error.message);
		LSErrorFree(&error);
		goto error;
	}

	if (!LSGmainAttach(service->handle, event_loop, &error)) {
		g_error("Could not attach service handle to mainloop: %s", error.message);
		LSErrorFree(&error);
		goto error;
	}

	return service;

error:
	if (service->handle != NULL) {
		LSUnregister(service->handle, &error);
		LSErrorFree(&error);
	}

	g_free(service);

	return NULL;
}
Example #11
0
void audio_service_free(struct audio_service *service)
{
	LSError error;

	LSErrorInit(&error);

	if (service->handle != NULL && LSUnregister(service->handle, &error) < 0) {
		g_warning("Could not unregister service: %s", error.message);
		LSErrorFree(&error);
	}

	g_slist_free_full(sample_list, g_free);

	g_free(service->default_sink_name);
	g_free(service);
}
    bool unref()
    {
        mRefCount--;
        if (mRefCount == 0) {
            LSError error;
            LSErrorInit(&error);

            if (!LSUnregister(mHandle, &error)) {
                qWarning("Failed to unregister service: %s", error.message);
                LSErrorFree(&error);
            }

            return false;
        }

        return true;
    }
Example #13
0
Activity::~Activity()
{
    LSError lserror;
    LSErrorInit(&lserror);

    if (mToken != LSMESSAGE_TOKEN_INVALID) {
        if (!LSCallCancel(mHandle, mToken, &lserror)) {
            LSErrorPrint(&lserror, stderr);
            LSErrorFree(&lserror);
        }
    }

    if (mHandle) {
        if (LSUnregister(mHandle, &lserror)) {
            LSErrorPrint(&lserror, stderr);
            LSErrorFree(&lserror);
        }
    }
}
Example #14
0
static void
test_LSRegisterAndUnregister(TestData *fixture, gconstpointer user_data)
{
    LSError error;
    LSErrorInit(&error);

    LSHandle *sh = NULL;

    if (g_test_trap_fork(0, G_TEST_TRAP_SILENCE_STDERR))
    {
        setenv("LS_DEBUG", "2", 1);
        setenv("LS_ENABLE_UTF8", "2", 1);

        LSRegister("com.name.service", &sh, &error);
        g_assert_cmpint(_ls_debug_tracing, ==, 2);
        g_assert(_ls_enable_utf8_validation == true);
        LSUnregister(sh, &error);
        exit(0);
    }
Example #15
0
MojErr MojLunaService::close()
{
    LOG_TRACE("Entering function %s", __FUNCTION__);

	MojErr err = MojErrNone;
	MojErr errClose = MojService::close();
	MojErrAccumulate(err, errClose);

	// destroy service handle
	MojLunaErr lserr;
	bool retVal;
	if (m_service) {
		retVal = LSUnregisterPalmService(m_service, lserr);
		m_service = NULL;
		m_handle = NULL;
		MojLsErrAccumulate(err, retVal, lserr);
	} else if (m_handle) {
		retVal = LSUnregister(m_handle, lserr);
		m_handle = NULL;
		MojLsErrAccumulate(err, retVal, lserr);
	}
	return err;
}
Example #16
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;
}
Example #17
0
int
main(int argc, char **argv)
{
    bool interactive = false;
    bool timing = false;
    bool signal = false;
    bool use_public_bus = false;
    char *serviceName = NULL;
    int optionCount = 0;
    int opt;

    while ((opt = getopt(argc, argv, "hdisPrlfn:t:m:a:q:")) != -1)
    {
    switch (opt) {
    case 'i':
        interactive = true;
        optionCount++;
        break;
    case 's':
        signal = true;
        optionCount++;
        break;
    case 'P':
        use_public_bus = true;
        optionCount++;
        break;
    case 'd':
        sLogLevel = G_LOG_LEVEL_DEBUG;
        optionCount++;
        break;
    case 'n':
        interactive = true;
        count = atoi(optarg);
        optionCount+=2;
        break;
    case 't':
        timing = true;
        count = atoi(optarg);
        optionCount+=2;
        break;
    case 'm':
        serviceName = g_strdup(optarg);
        optionCount+=2;
        break;
    case 'a':
        appId = g_strdup(optarg);
        optionCount+=2;
        break;
    case 'l':
        line_number = true;
        optionCount++;
        break;
    case 'f':
        format_response = true;
        optionCount++;
        break;
    case 'q':
        query_list = g_list_append(query_list, g_strdup(optarg));
        optionCount+=2;
        break;
    case 'h':
    default:
        PrintUsage(argv[0]);
        return 0;
        }
    }

    if (argc < 3 + optionCount) {
        PrintUsage(argv[0]);
        return 0;
    }

    g_log_set_default_handler(g_log_filter, NULL);

    GMainLoop *mainLoop = g_main_loop_new(NULL, FALSE); 

    if (mainLoop == NULL)
    {
        g_critical("Unable to create mainloop");
        exit(EXIT_FAILURE);
    }

    LSError lserror;
    LSErrorInit(&lserror);

    LSHandle *sh = NULL;
    bool serviceInit = LSRegisterPubPriv(serviceName, &sh,
                use_public_bus, &lserror);

    if (!serviceInit) goto exit;

    bool gmainAttach = LSGmainAttach(sh, mainLoop, &lserror);
    if (!gmainAttach) goto exit;    

    url = g_strdup(argv[optionCount + 1]);
    message = g_strdup(argv[optionCount + 2]);

    LSMessageToken sessionToken;
    bool retVal;

    if (timing) {

      /* Timing loop */
      clock_gettime(CLOCK_MONOTONIC, &startTime);
      retVal = LSCallFromApplication(sh, url, message, appId,
            timingServiceResponse, mainLoop, &sessionToken, &lserror);
      
      if (!retVal) goto exit;

      g_main_loop_run(mainLoop);
      
      printf("Total time %.02f ms, %d iterations, %.02f ms per iteration\n",
        roundtripTime * 1000.0, roundtripCount, (roundtripTime / roundtripCount) * 1000.0);
      
      printf("%d bytes sent, %d bytes received\n",
        sentBytes, rcvdBytes);
    
    } else {

      if (signal)
      {
          retVal = LSSignalSend(sh, url, message, &lserror);
      }
      else
      {
          /* Basic sending */
          retVal = LSCallFromApplication(sh, url, message, appId,
                serviceResponse, mainLoop, &sessionToken, &lserror);
      }
      
      if (!retVal) goto exit;

      if (interactive && !signal) 
      {
          g_io_add_watch(g_io_channel_unix_new(0), G_IO_ERR|G_IO_HUP, input_closed, mainLoop);
          g_main_loop_run(mainLoop);
      }
      else if (!signal)
      {
          /* 
           * NOV-93580: In the non-interactive case, we can't guarantee that
           * an LSCall() will necessarily get the QueryNameReply before
           * shutting down if it does not wait for (or have) a reply from the
           * far side.
           */
          g_critical("WARNING: you must always call luna-send with \"-i\" or \"-n\". Exiting with failure return code.");
          exit(EXIT_FAILURE);
      }
    }

exit:

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

    if (sh != NULL)
    {
        if (!LSUnregister(sh, &lserror))
        {
            LSErrorPrint(&lserror, stderr);
            LSErrorFree(&lserror);
        }
    }

    g_main_loop_unref(mainLoop);

    if (url)
        g_free (url);

    if (message)
        g_free (message);

    return 0;
}
int initialize_connectionmanager_ls2_calls( GMainLoop *mainloop )
{
	LSError lserror;
	LSErrorInit (&lserror);
	pLsHandle       = NULL;
	pLsPublicHandle = NULL;

	if(NULL == mainloop)
		goto Exit;

	if (LSRegisterPubPriv(CONNECTIONMANAGER_LUNA_SERVICE_NAME, &pLsHandle, false, &lserror) == false)
	{
		WCA_LOG_FATAL("LSRegister() private returned error");
		goto Exit;
	}

	if (LSRegisterPubPriv(CONNECTIONMANAGER_LUNA_SERVICE_NAME, &pLsPublicHandle, true, &lserror) == false)
	{
		WCA_LOG_FATAL("LSRegister() public returned error");
		goto Exit;
	}

	if (LSRegisterCategory(pLsHandle, NULL, connectionmanager_methods, NULL, NULL, &lserror) == false)
	{
		WCA_LOG_FATAL("LSRegisterCategory() returned error");
		goto Exit;
	}

	if (LSGmainAttach(pLsHandle, mainloop, &lserror) == false)
	{
		WCA_LOG_FATAL("LSGmainAttach() private returned error");
		goto Exit;
	}

	if (LSGmainAttach(pLsPublicHandle, mainloop, &lserror) == false)
	{
		WCA_LOG_FATAL("LSGmainAttach() public returned error");
		goto Exit;
	}

	/* Register for Wired technology's "PropertyChanged" signal (For wifi its being done in wifi_service.c*/
	connman_technology_t *technology = connman_manager_find_ethernet_technology(manager);
	if(technology)
	{
		connman_technology_register_property_changed_cb(technology, technology_property_changed_callback);
	}

	return 0;

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

        if (pLsHandle)
	{
		LSErrorInit (&lserror);
		if(LSUnregister(pLsHandle, &lserror) == false)
		{
			LSErrorPrint(&lserror, stderr);
			LSErrorFree(&lserror);
		}
	}

        if (pLsPublicHandle)
        {
		LSErrorInit (&lserror);
		if(LSUnregister(pLsPublicHandle, &lserror) == false)
		{
			LSErrorPrint(&lserror, stderr);
			LSErrorFree(&lserror);
		}
        }
	return -1;
}
Example #19
0
struct audio_service* audio_service_create()
{
	struct audio_service *service;
	LSError error;
	pa_mainloop_api *mainloop_api;
	char name[100];

	service = g_try_new0(struct audio_service, 1);
	if (!service)
		return NULL;

	LSErrorInit(&error);

	if (!LSRegisterPubPriv("org.webosports.audio", &service->handle, false, &error)) {
		g_warning("Failed to register the luna service: %s", error.message);
		LSErrorFree(&error);
		goto error;
	}

	if (!LSRegisterCategory(service->handle, "/", audio_service_methods,
			NULL, NULL, &error)) {
		g_warning("Could not register service category: %s", error.message);
		LSErrorFree(&error);
		goto error;
	}

	if (!LSCategorySetData(service->handle, "/", service, &error)) {
		g_warning("Could not set daa for service category: %s", error.message);
		LSErrorFree(&error);
		goto error;
	}

	if (!LSGmainAttach(service->handle, event_loop, &error)) {
		g_warning("Could not attach service handle to mainloop: %s", error.message);
		LSErrorFree(&error);
		goto error;
	}

	service->pa_mainloop = pa_glib_mainloop_new(g_main_context_default());
	mainloop_api = pa_glib_mainloop_get_api(service->pa_mainloop);

	snprintf(name, 100, "AudioServiceContext:%i", getpid());
	service->context = pa_context_new(mainloop_api, name);
	service->context_initialized = false;
	pa_context_set_state_callback(service->context, context_state_cb, service);

	if (pa_context_connect(service->context, NULL, 0, NULL) < 0) {
		g_warning("Failed to connect to PulseAudio");
		pa_context_unref(service->context);
		pa_glib_mainloop_free(service->pa_mainloop);
		goto error;
	}

	sample_list = g_slist_alloc();

	return service;

error:
	if (service->handle != NULL) {
		LSUnregister(service->handle, &error);
		LSErrorFree(&error);
	}

	g_free(service);

	return NULL;
}
Example #20
0
        setenv("LS_ENABLE_UTF8", "2", 1);

        LSRegister("com.name.service", &sh, &error);
        g_assert_cmpint(_ls_debug_tracing, ==, 2);
        g_assert(_ls_enable_utf8_validation == true);
        LSUnregister(sh, &error);
        exit(0);
    }
    g_test_trap_assert_stderr("Log mode enabled to level 2\nEnable UTF8 validation on payloads\n");
    g_test_trap_assert_passed();

    g_assert(LSRegister("com.name.service", &sh, &error));
    g_assert(NULL != sh);
    g_assert(!LSErrorIsSet(&error));
    g_assert_cmpstr(LSHandleGetName(sh), ==, "com.name.service");
    g_assert(LSUnregister(sh, &error));
    g_assert(!LSErrorIsSet(&error));

    g_assert(LSRegisterPubPriv("com.name.service", &sh, true, &error));
    g_assert(NULL != sh);
    g_assert(!LSErrorIsSet(&error));
    g_assert(LSUnregister(sh, &error));
    g_assert(!LSErrorIsSet(&error));

    g_assert(LSRegisterPubPriv("com.name.service", &sh, false, &error));
    g_assert(NULL != sh);
    g_assert(!LSErrorIsSet(&error));

    if (g_test_trap_fork(0, G_TEST_TRAP_SILENCE_STDERR))
    {
        sh->history.magic_state_num = 0;