Example #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;
}
Example #2
0
static int
SuspendIPCInit(void)
{
    bool retVal;
    LSError lserror;
    LSErrorInit(&lserror);

    retVal = LSSubscriptionSetCancelFunction(GetLunaServiceHandle(),
        clientCancel, NULL, &lserror);
    if (!retVal)
    {
        LSErrorPrint(&lserror, stderr);
        LSErrorFree(&lserror);
    }
    return 0;
}
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__);
}