Esempio n. 1
0
Handle::Handle(const char *name, bool public_service)
{
    Error error;
    LSHandle *handle;

    if (!LSRegisterPubPriv(name, &handle, public_service, error.get()))
    {
        throw error;
    }

    _handle = handle;
}
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;
}
Esempio n. 3
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;
}
Esempio n. 4
0
static LSMessageHandlerResult
_LSMonitorListMessageHandler(_LSTransportMessage *message, void *context)
{
    LS_ASSERT(_LSTransportMessageGetType(message) == _LSTransportMessageTypeListClientsReply);

    static int call_count = 0;
    const char *unique_name = NULL;
    const char *service_name = NULL;
    int32_t pid = 0;
    const char *exe_path = NULL;
    const char *service_type = NULL;
    static int total_sub_services = 0;

    int type = *(int*)context;
    bool iter_ret = false;

    static GSList *public_monitor_info = NULL;
    static GSList *private_monitor_info = NULL;
 
    GSList **cur_list = NULL;

    _LSTransportMessageIter iter;

    if (type == HUB_TYPE_PUBLIC)
    {
        cur_list = &public_monitor_info;
    }
    else
    {
        cur_list = &private_monitor_info;
    }
    
    _LSTransportMessageIterInit(message, &iter);

    while (_LSTransportMessageIterHasNext(&iter))
    {
        _LSMonitorListInfo *info = g_malloc(sizeof(_LSMonitorListInfo));

        if (!info)
        {
            g_critical("Out of memory when allocating list info");
            exit(EXIT_FAILURE);
        }

        iter_ret = _LSTransportMessageGetString(&iter, &unique_name);
        if (!iter_ret) break;
        info->unique_name = g_strdup(unique_name);
        _LSTransportMessageIterNext(&iter);

        iter_ret = _LSTransportMessageGetString(&iter, &service_name);
        if (!iter_ret) break;
        info->service_name = g_strdup(service_name);
        _LSTransportMessageIterNext(&iter);

        iter_ret = _LSTransportMessageGetInt32(&iter, &pid);
        if (!iter_ret) break;
        info->pid = pid;
        _LSTransportMessageIterNext(&iter);
    
        iter_ret = _LSTransportMessageGetString(&iter, &exe_path);
        if (!iter_ret) break;
        info->exe_path = g_strdup(exe_path);
        _LSTransportMessageIterNext(&iter);

        iter_ret = _LSTransportMessageGetString(&iter, &service_type);
        if (!iter_ret) break;
        info->service_type = g_strdup(service_type);
        _LSTransportMessageIterNext(&iter);

        if (_CanGetSubscriptionInfo(info))
        {
            total_sub_services++;
        }
       
        *cur_list = g_slist_prepend(*cur_list, info);
    }

    /* Process and display when we receive public and private responses */
    if (++call_count == 2)
    {
        if (list_subscriptions || list_malloc)
        {
            LSError lserror;
            LSErrorInit(&lserror);

            LSHandle *private_sh = NULL;
            LSHandle *public_sh = NULL;

            _DisconnectCustomTransport();

            if (total_sub_services == 0)
            {
                _PrintSubscriptionResults();
                g_main_loop_quit(mainloop);
                goto Done;
            }

            /* register as a "high-level" client */
            if (!LSRegisterPubPriv(MONITOR_NAME, &private_sh, false, &lserror))
            {
                LSErrorPrint(&lserror, stderr);
                LSErrorFree(&lserror);
            }
            else
            {
                LSGmainAttach(private_sh, mainloop, &lserror);
                _ListServiceSubscriptions(private_sh, _SubscriptionResultsCallback, private_monitor_info, total_sub_services, &private_sub_replies);
            }

            /* Same for the public hub */
            if (!LSRegisterPubPriv(MONITOR_NAME, &public_sh, true, &lserror))
            {
                LSErrorPrint(&lserror, stderr);
                LSErrorFree(&lserror);
            }
            else
            {
                LSGmainAttach(public_sh, mainloop, &lserror);
                _ListServiceSubscriptions(public_sh, _SubscriptionResultsCallback, public_monitor_info, total_sub_services, &public_sub_replies);
            }
        }
        else if (list_clients)
        {
            fprintf(stdout, "PRIVATE HUB CLIENTS:\n");
            fprintf(stdout, "%-10s\t%-30s\t%-35s\t%-20s\t%-20s\n", "PID", "SERVICE NAME", "EXE", "TYPE", "UNIQUE NAME");
            _PrintMonitorListInfo(private_monitor_info);
            fprintf(stdout, "\n");
            _FreeMonitorListInfo(&private_monitor_info);
 
            fprintf(stdout, "PUBLIC HUB CLIENTS:\n");
            fprintf(stdout, "%-10s\t%-30s\t%-35s\t%-20s\t%-20s\n", "PID", "SERVICE NAME", "EXE", "TYPE", "UNIQUE NAME");
            _PrintMonitorListInfo(public_monitor_info);
            fprintf(stdout, "\n");
            _FreeMonitorListInfo(&public_monitor_info);
        
            g_main_loop_quit(mainloop);
        }
    }

Done:
    return LSMessageHandlerResultHandled;
}
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;
}
Esempio n. 6
0
        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;
        _lshandle_validate(sh);
        exit(0);
    }
Esempio n. 7
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;
}