Esempio n. 1
0
bool
LSGmainAttachPalmService(LSPalmService *psh,
                           GMainLoop *mainLoop, LSError *lserror)
{
    _LSErrorIfFail(psh != NULL, lserror);
    _LSErrorIfFail(mainLoop != NULL, lserror);

    bool retVal;
    retVal = LSGmainAttach(psh->public_sh, mainLoop, lserror);
    if (!retVal) return retVal;
    retVal = LSGmainAttach(psh->private_sh, mainLoop, lserror);
    if (!retVal) return retVal;

    return retVal;
}
Esempio n. 2
0
void Preferences::registerService()
{
	bool ret;
	LSError error;
	LSErrorInit(&error);

	ret = LSRegister(NULL, &m_lsHandle, &error);
	if (!ret) {
		g_critical("Failed to register handler: %s", error.message);
		LSErrorFree(&error);
		exit(1);
	}

	ret = LSGmainAttach(m_lsHandle, HostBase::instance()->mainLoop(), &error);
	if (!ret) {
		g_critical("Failed to attach service to main loop: %s", error.message);
		LSErrorFree(&error);
		exit(1);
	}

	ret = LSCall(m_lsHandle, "palm://com.palm.lunabus/signal/registerServerStatus",
				 "{\"serviceName\":\"com.palm.systemservice\"}",
				 serverConnectCallback, this, &m_serverStatusToken, &error);
	if (!ret) {
		g_critical("Failed in calling palm://com.palm.lunabus/signal/registerServerStatus: %s",
					  error.message);
		LSErrorFree(&error);
		exit(1);
	}
	
}
Esempio n. 3
0
void BootManager::startService()
{
	bool result;
	LSError error;
	LSErrorInit(&error);

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

	g_message("BootManager starting...");

	if (!LSRegister("org.webosports.bootmgr", &m_service, &error)) {
		g_warning("Failed in BootManager: %s", error.message);
		LSErrorFree(&error);
		return;
	}

	if (!LSRegisterCategory(m_service, "/", s_methods, NULL, NULL, &error)) {
		g_warning("Failed in BootManager: %s", error.message);
		LSErrorFree(&error);
		return;
	}

	if (!LSGmainAttach(m_service, mainLoop, &error)) {
		g_warning("Failed in BootManager: %s", error.message);
		LSErrorFree(&error);
		return;
	}

	if (!LSRegisterServerStatus(m_service, "org.webosports.luna",
				cbCompositorAvailable, NULL, &error)) {
		g_warning("Failed to register for compositor status");
		LSErrorFree(&error);
	}
}
Esempio n. 4
0
void Handle::attachToLoop(GMainLoop *loop) const
{
    Error error;

    if (!LSGmainAttach(_handle, loop, error.get()))
    {
        throw error;
    }
}
Esempio n. 5
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;
}
// If service handle exists, return it, otherwise create it then return it
// In an error situation, this could return NULL
LSHandle *SysmgrIMEModel::getLunaServiceHandle()
{
    if (!m_serviceHandle) {
        LSError lserror;
        LSErrorInit(&lserror);
        if (LSRegister(NULL, &m_serviceHandle, &lserror))
            LSGmainAttach(m_serviceHandle, HostBase::instance()->mainLoop(), &lserror);
        if (LSErrorIsSet(&lserror)) {
            qCritical() << lserror.message << lserror.file << lserror.line << lserror.func;
            LSErrorFree(&lserror);
        }
    }
    return m_serviceHandle;
}
Esempio n. 7
0
void
_PowerdClientIPCRun(void)
{
    bool retVal;
    LSError lserror;
    LSErrorInit(&lserror);

    if (!gServiceHandle)
    {
        retVal = LSRegister(NULL, &gServiceHandle, &lserror);
        if (!retVal) goto error;

        if (!gMainLoop)
        {
            int ret;

            GMainContext *context = g_main_context_new();
            if (!context) goto error;

            gMainLoop = g_main_loop_new(context, FALSE);
            g_main_context_unref(context);
            if (!gMainLoop) goto error;

            pthread_attr_t attr;
            pthread_attr_init(&attr);

            ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
            assert(ret == 0);

            pthread_t tid;
            pthread_create(&tid, &attr, _PowerdIPCThread, NULL);
        }

        retVal = LSGmainAttach(gServiceHandle, gMainLoop, &lserror);
        if (!retVal) goto error;
    }

    retVal = LSCall(gServiceHandle,
        "luna://com.palm.lunabus/signal/registerServerStatus",
        "{\"serviceName\":\"com.palm.power\"}", _powerd_server_up,
        NULL, NULL, &lserror);
    if (!retVal) goto error;

    return;
error:
    LSErrorPrint(&lserror, stderr);
    LSErrorFree(&lserror);
    return;
}
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. 9
0
void Activity::setup()
{
    LSError lserror;
    LSErrorInit(&lserror);

    if (!LSRegister(NULL, &mHandle, NULL)) {
        LSErrorPrint(&lserror, stderr);
        LSErrorFree(&lserror);
        return;
    }

    GMainLoop *mainloop = g_main_loop_new(g_main_context_default(), TRUE);
    if (!LSGmainAttach(mHandle, mainloop, &lserror)) {
        LSErrorPrint(&lserror, stderr);
        LSErrorFree(&lserror);
        return;
    }

    QJsonObject activity;
    activity.insert("name", mAppId);
    char *description = g_strdup_printf("%i", mProcessId);
    activity.insert("description", (qint64) mProcessId);

    QJsonObject activityType;
    activityType.insert("foreground", true);

    activity.insert("type", activityType);

    QJsonObject request;
    request.insert("activity", activity);
    request.insert("subscribe", true);
    request.insert("start", true);
    request.insert("replace", true);

    QJsonDocument payload(request);

    if (!LSCallFromApplication(mHandle, "palm://com.palm.activitymanager/create", payload.toJson().constData(),
                               mIdentifier.toUtf8().constData(), Activity::activityCallback, this, &mToken, &lserror)) {
        LSErrorPrint(&lserror, stderr);
        LSErrorFree(&lserror);
        return;
    }

    g_free(description);
}
Esempio n. 10
0
MojErr MojLunaService::attach(GMainLoop* loop)
{
	MojAssert(loop);
    LOG_TRACE("Entering function %s", __FUNCTION__);

	MojLunaErr lserr;
	bool retVal;
	if (m_service) {
		retVal= LSGmainAttachPalmService(m_service, loop, lserr);
		MojLsErrCheck(retVal, lserr);
	} else {
		MojAssert(m_handle);
		retVal= LSGmainAttach(m_handle, loop, lserr);
		MojLsErrCheck(retVal, lserr);
	}
	m_loop = loop;

	return MojErrNone;
}
Esempio n. 11
0
DisplayBlocker::DisplayBlocker() :
    m_service(0),
    m_token(0),
    m_acquired(false)
{
	LSError lserror;
	LSErrorInit(&lserror);

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

	if (!LSRegister(NULL, &m_service, &lserror)) {
		LSErrorPrint(&lserror, stderr);
		LSErrorFree(&lserror);
		return;
	}

	if (!LSGmainAttach(m_service, mainLoop, &lserror)) {
		LSErrorPrint(&lserror, stderr);
		LSErrorFree(&lserror);
		return;
	}
}
Esempio n. 12
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);
}
Esempio n. 13
0
int
main(int argc, char *argv[])
{
    bool haveNFlag = false;
    bool haveTFlag = false;
    std::string sizeStr;
    std::string typeStr;

    for (int i = 1; i < argc; i++)
    {

	std::string thisArg = argv[i];
	if (thisArg == "-s")
	{
		if (i == (argc - 1))
		{
			Usage();
		}
		sizeStr = argv[i + 1];
		fileSize = atoi(sizeStr.c_str());
		if (fileSize < 0)
		{
			Usage();
		}
		i++;
	}
	else if (thisArg == "-n")
	{
		haveNFlag = true;
		if (i == (argc -1))
		{
			Usage();
		}
		std::string nFileStr = argv[i + 1];
		nFiles = atoi(nFilesStr.c_str());
		if (nFiles < 0)
		{
			Usage();
		}
		i++;
	}
	else if (thisArg == "-t")
	{
		haveTFlag = true;
		if (i == (argc - 1))
		{
			Usage();
		}
		typeStr = argv[i + 1];
		i++;
	}
	else
	{
		Usage();
	}
    }

    if (!haveTFlag)
    {
	Usage();
    }

    if (haveNFlag)
    {
	printf("Run for %d files\n", nFiles);
    }
    else
    {
	printf("Run forever\n");
    }
    printf("File size %d bytes\n", fileSize);
    printf("Use filecache type %s\n", typeStr.c_str());



    LSError lserror;
    LSErrorInit(&lserror);

    GMainLoop *mainLoop = NULL;

    mainLoop = g_main_loop_new(NULL, FALSE);

    bool ret = LSRegister(NULL, &filecacheService, &lserror);
    if (!ret)
    {
	fprintf(stderr, "LSRegister failed\n");
	exit(1);
    }

    ret = LSGmainAttach(filecacheService, mainLoop, &lserror);
    if (!ret) 
    {
	fprintf(stderr, "LSGmainAttach failed\n");
	exit(1);
    }

    //
    // Create types in filecache.
    //
    std::string typeName = typeStr;	
    std::string loWatermark = "10000";
    std::string hiWatermark = "100000000";
    std::string size = sizeStr;
    std::string cost = "1";
    std::string lifetime = "100000";
    std::string payload = 
	"{\"typeName\":\"" + typeName + "\"" +
	", \"loWatermark\": " + loWatermark + 
	", \"hiWatermark\": " + hiWatermark +
	", \"size\": " + size +
	", \"cost\": " + cost +
	", \"lifetime\": " + lifetime +
	", \"dirType\": false }";


    std::string DefineTypeURI = std::string(FILECACHE_SERVICE_URI) + 
	"/DefineType";

    printf("calling DefineType %s\n", payload.c_str());

    ret = LSCall(filecacheService, DefineTypeURI.c_str(), payload.c_str(), FilecacheServiceCb,
		GINT_TO_POINTER(send_count - 1), NULL, &lserror);
    if (!ret)
    {
	fprintf(stderr, "DefineType failed\n");
	exit(1);
    }

    //
    // Wait for response from this LSCall()
    //
    handledResponse = false;
    while (!handledResponse)
    {
    	g_main_context_iteration(NULL, true);
    }

    printf("created filecache type %s\n", typeName.c_str());

    //
    // OK now create file in the cache.
    //
    int filesCreated = 0;
    while (true)
    {
	std::string fileName = "a.txt";
	size = sizeStr;
	std::string cost = "1";
	std::string lifetime = "100000";
	std::string subscribe = "true";

	payload =
        "{\"typeName\":\"" + typeName + "\"" +
        ", \"fileName\":\"" + fileName + "\"" +
        ", \"size\": " + size + 
        ", \"cost\": " + cost +
        ", \"lifetime\": " + lifetime +
        ", \"subscribe\": true }";

	std::string InsertCacheObjectURI = 
		std::string(FILECACHE_SERVICE_URI) +
		"/InsertCacheObject";

	LSMessageToken token;
        handledResponse = false;
	printf("calling InsertCacheObject %s\n", payload.c_str());
	ret = LSCall(filecacheService, InsertCacheObjectURI.c_str(),
		payload.c_str(), FilecacheServiceCb, 
		GINT_TO_POINTER(send_count -1), &token, &lserror);
	if (!ret)
	{
		fprintf(stderr, "InsertCacheObject failed\n");
		goto error;
	}

	while (!handledResponse)
	{
		g_main_context_iteration(NULL, true);
	}

	printf("created cache object\n");

	//
	// Parse the returned json.
	//
    	pbnjson::JSchemaFragment inputSchema("{}");
    	pbnjson::JDomParser parser(NULL);   
    	if (!parser.parse(jsonResponseStr, inputSchema, NULL)) 
	{      
        	// handle error
		fprintf(stderr, "Error parsing json response\n");
		exit(1);
    	}

    	pbnjson::JValue parsed = parser.getDom();

	std::string cacheFileName = parsed["pathName"].asString();
	printf("cacheFileName = %s\n", cacheFileName.c_str());

	//
	// Write data to the file.
	//
	char buf[fileSize];
	int fd;
	if ((fd = open(cacheFileName.c_str(), O_WRONLY)) == -1)
	{
		fprintf(stderr, "Error, unable to open file %s for writing\n",
			cacheFileName.c_str());
		exit(1);
	}

	if (write(fd, buf, fileSize) != fileSize)
	{
		fprintf(stderr, "Error, write to %s failed\n",
			cacheFileName.c_str());
		exit(1);
	}

	close(fd);

	//
	// Cancel the subscription.
	//	
	ret = LSCallCancel(filecacheService, token, &lserror);
	if (!ret)
	{
		fprintf(stderr, "Cancel of subscription failed\n");
		goto error;
	}
	printf("subscription cancelled\n");

 	filesCreated++;
        if (filesCreated == nFiles)
	{
		printf("Done with %d files created\n", nFiles);
		exit(0);
	}
	
    }


    exit(0);

error:
    fprintf(stderr, "stresstest exits\n");
    exit(1);
}
Esempio n. 14
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;
}
Esempio n. 15
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;
}
Esempio n. 16
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. 17
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;
}
AmbientLightSensor::AmbientLightSensor ()
    : m_service(NULL)
    , m_alsEnabled(false)
    , m_alsIsOn(false)
    , m_alsPointer(0)
    , m_alsRegion(ALS_REGION_UNDEFINED)
    , m_alsSum(0)
    , m_alsLastOff(0)
    , m_alsDisplayOn(false)
    , m_alsSubscriptions(0)
    , m_alsDisabled(0)
    , m_alsHiddOnline(false)
    , m_alsFastRate(false)
    , m_alsSampleCount(0)
    , m_alsCountInRegion(0)
    , m_alsSamplesNeeded (ALS_INIT_SAMPLE_SIZE)
    , m_alsLastSampleTs (0)
{
    LSError lserror;
    LSErrorInit(&lserror);
    bool result;

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

    result = LSRegister(AMBIENT_LIGHT_SENSOR_ID, &m_service, &lserror);
    if (!result)
    {
        LSErrorPrint (&lserror, stderr);
        LSErrorFree(&lserror);
    }

    result = LSRegisterCategory (m_service, "/control", alsMethods, NULL, NULL, &lserror);
    if (!result)
    {
        LSErrorPrint (&lserror, stderr);
        LSErrorFree(&lserror);
    }

    result = LSCategorySetData (m_service, "/control", this, &lserror);
    if (!result)
    {
        LSErrorPrint (&lserror, stderr);
        LSErrorFree(&lserror);
    }

    result = LSSubscriptionSetCancelFunction(m_service, AmbientLightSensor::cancelSubscription, this, &lserror);
    if (!result)
    {
        LSErrorPrint (&lserror, stderr);
        LSErrorFree (&lserror);
    }

    result = LSGmainAttach(m_service, mainLoop, &lserror);
    if (!result)
    {
        LSErrorPrint (&lserror, stderr);
        LSErrorFree(&lserror);
    }

    result = LSRegisterServerStatus(m_service, "com.palm.hidd", AmbientLightSensor::hiddServiceNotification, this, &lserror);
    if (!result)
    {
        LSErrorPrint (&lserror, stderr);
        LSErrorFree (&lserror);
    }


#if defined (MACHINE_CASTLE)

    m_alsEnabled = true; 

    m_alsBorder[0] = 10  * ALS_SAMPLE_SIZE; 
    m_alsBorder[1] = 200 * ALS_SAMPLE_SIZE;

    m_alsMargin[0] = 2 * ALS_SAMPLE_SIZE;
    m_alsMargin[1] = (m_alsBorder[1] / 10) > (ALS_SAMPLE_SIZE * 2) ?  m_alsBorder[1] / 10 : ALS_SAMPLE_SIZE * 2;

#else
    if (Settings::LunaSettings()->enableAls) {
	m_alsEnabled = true; 

	g_warning ("ALSCal token found, expecting lux values in light events");


	m_alsBorder[ALS_REGION_UNDEFINED] = -1;
	m_alsBorder[ALS_REGION_DARK] = 6;
	m_alsBorder[ALS_REGION_DIM] = 100;
	m_alsBorder[ALS_REGION_INDOOR] = 1000;
	m_alsBorder[ALS_REGION_OUTDOOR] = INT_MAX;

	// margins are higher at lower lux values
	m_alsMargin[ALS_REGION_UNDEFINED] = 0;
	m_alsMargin[ALS_REGION_DARK] = 4;
	m_alsMargin[ALS_REGION_DIM] = 10;
	m_alsMargin[ALS_REGION_INDOOR] = 100;
	m_alsMargin[ALS_REGION_OUTDOOR] = 0;

    }
    else {
        g_warning ("%s: ALS is not enabled", __PRETTY_FUNCTION__); 

    }

#endif

    m_instance = this;

    g_debug ("%s started", __PRETTY_FUNCTION__);
}