Exemple #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;
}
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);
	}
}
Exemple #3
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);
	}
	
}
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;
}
Exemple #6
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;
}
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);
}
Exemple #8
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);
    }
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);
}
Exemple #10
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;
	}
}
Exemple #11
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);
}
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__);
}
Exemple #13
0
    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);
    }
    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));