예제 #1
0
파일: shutdown.c 프로젝트: Andolamin/powerd
/** 
* @brief Called by test code to reset state machine to square 1.
* 
* @retval
*/
static bool
TESTresetShutdownState(LSHandle *sh, LSMessage *message, void *user_data)
{
    LSMessageRef(message);
    LSCallOneReply(GetLunaServiceHandle(), SLEEPD_SHUTDOWN_SERVICE"TESTresetShutdownState",
                   LSMessageGetPayload(message), shutdown_method_cb,(void *)message, NULL, NULL);
    return true;
}
예제 #2
0
파일: shutdown.c 프로젝트: Andolamin/powerd
/**
 * @brief Ack the "shutdownApplications" signal.
 */
static bool
shutdownApplicationsAck(LSHandle *sh, LSMessage *message,
                             void *user_data)
{
    LSMessageRef(message);
    LSCallOneReply(GetLunaServiceHandle(), SLEEPD_SHUTDOWN_SERVICE"shutdownApplicationsAck",
                   LSMessageGetPayload(message), shutdown_method_cb,(void *)message, NULL, NULL);
    return true;
}
예제 #3
0
static bool
alarmRemove(LSHandle *sh, LSMessage *message, void *ctx)
{
	LSMessageRef(message);
	LSCallOneReply(GetLunaServiceHandle(), "palm://com.palm.sleep/time/alarmRemove",
			LSMessageGetPayload(message), alarms_timeout_cb, (void *)message, NULL, NULL);

	return true;
}
예제 #4
0
void EASPolicyManager::save()
{
	if (!m_service) {
		g_warning ("Service handle not available yet, cannot query device policy");
		return;
	}

	LSError lserror;
	LSErrorInit (&lserror);

	if (m_callToken) {
		g_debug ("Cancelling call token %lu", m_callToken);
		if (LSCallCancel (m_service, m_callToken, &lserror)) {
			g_warning ("Unable to cancel call with token %lu error message %s", m_callToken, lserror.message);
		}
		m_callToken = 0;
	}

	json_object* policyJson = m_aggregate->toNewJSON();
	json_object_object_add(policyJson, "status", getPolicyStatus());
	gchar* policyStr = g_strdup_printf ("{ \"objects\":[%s]}", json_object_to_json_string (policyJson));
	g_message ("%s: Writing device policy %s to mojodb", __func__, policyStr);

	if (m_aggregate->m_id.empty()) {

	    if (!LSCallOneReply (m_service, "palm://com.palm.db/put", policyStr, 
							 &EASPolicyManager::cbDevicePolicySaved, this, NULL, &lserror)) 
		{
			g_warning ("%s: Failed at %s with message %s", __func__, lserror.func, lserror.message);
			LSErrorFree (&lserror);
	    }
	}
	else {

	    if (!LSCallOneReply (m_service, "palm://com.palm.db/merge", policyStr, 
				    &EASPolicyManager::cbDevicePolicySaved, this, NULL, &lserror)) {
			g_warning ("%s: Failed at %s with message %s", __func__, lserror.func, lserror.message);
			LSErrorFree (&lserror);
	    }
	}

	json_object_put (policyJson);
	g_free (policyStr);
}
예제 #5
0
void EASPolicyManager::querySecurityPolicies()
{
    if (!m_service) {
		g_warning ("Service handle not available yet, cannot query device policy");
		return;
    }

    LSError lserror;
    LSErrorInit (&lserror);

    gchar* query = g_strdup ("{\"query\":{\"from\":\"com.palm.securitypolicy:1\", \"incDel\" : true}}");
    bool result = LSCallOneReply (m_service, "palm://com.palm.db/find", query, &EASPolicyManager::cbSecurityPolicy, this, NULL, &lserror);
    if (!result) {
		g_warning ("%s: Failed at %s with message %s", __func__, lserror.func, lserror.message);
		LSErrorFree (&lserror);
    }
    g_free (query);
}
예제 #6
0
/**
 * @brief Add a new alarm based on calender time. Sets the callback function based on the "subscribe" option value.
 */
static bool
alarmAddCalendar(LSHandle *sh, LSMessage *message, void *ctx)
{
	struct json_object *object=NULL;

	object = json_tokener_parse(LSMessageGetPayload(message));
	if ( is_error(object) )
	{
		goto malformed_json;
	}

	struct json_object *subscribe_json =
	            json_object_object_get(object, "subscribe");

	bool subscribe = json_object_get_boolean(subscribe_json);

	LSMessageRef(message);
	if(subscribe) {
		struct context *alrm_ctx=NULL;
		alrm_ctx = malloc(sizeof(struct context));
		if(!alrm_ctx) goto error;
		memset(alrm_ctx,0,sizeof(struct context));

		alrm_ctx->replyMessage = message;
		LSCall(GetLunaServiceHandle(), "palm://com.palm.sleep/time/alarmAddCalender",
					LSMessageGetPayload(message), alarms_timeout_subscribe_cb, (void *)alrm_ctx, &alrm_ctx->call_token, NULL);
	}
	else
		LSCallOneReply(GetLunaServiceHandle(), "palm://com.palm.sleep/time/alarmAddCalender",
			LSMessageGetPayload(message), alarms_timeout_cb, (void *)message, NULL, NULL);

	goto cleanup;

malformed_json:
	LSMessageReplyErrorBadJSON(sh, message);
	goto cleanup;
error:
	POWERDLOG(LOG_ERR,"Failed to allocate memory");
	LSMessageReplyErrorUnknown(sh, message);
cleanup:
	if (!is_error(object)) json_object_put(object);
	return true;

}
예제 #7
0
void EASPolicyManager::removeTemporaryPolicies()
{
    if (!m_service) {
		g_warning ("Service handle not available yet, cannot query device policy");
		return;
    }

    LSError lserror;
    LSErrorInit (&lserror);

    gchar* query = g_strdup ("{\"query\":{\"from\":\"com.palm.securitypolicy:1\", \"where\":[{\"prop\":\"isTemp\",\"op\":\"=\",\"val\":true}]}}");
    g_debug ("%s: Calling %s with %s", __func__, "palm://com.palm.db/del", query);
    bool result = LSCallOneReply (m_service, "palm://com.palm.db/del", query, &EASPolicyManager::cbTempPoliciesDeleted, this, NULL, &lserror);
    if (!result) {
		g_warning ("%s: Failed at %s with message %s", __func__, lserror.func, lserror.message);
		LSErrorFree (&lserror);
    }
    g_free (query);
}
예제 #8
0
파일: shutdown.c 프로젝트: Andolamin/powerd
static bool
shutdownServicesRegister(LSHandle *sh, LSMessage *message,
                             void *user_data)
{
    LSMessageRef(message);
    LSCallOneReply(GetLunaServiceHandle(), SLEEPD_SHUTDOWN_SERVICE"shutdownServicesRegister",
                   LSMessageGetPayload(message), shutdown_method_cb,(void *)message, NULL, NULL);
    bool retVal;
    LSError lserror;
    LSErrorInit(&lserror);

    retVal = LSSubscriptionAdd(sh, "shutdownClient", message, &lserror);
    if (!retVal)
    {
        g_critical("LSSubscriptionAdd failed.");
        LSErrorPrint(&lserror, stderr);
        LSErrorFree(&lserror);
    }
    return true;
}
예제 #9
0
MojErr MojLunaService::sendImpl(MojServiceRequest* req, const MojChar* service, const MojChar* method, Token& tokenOut)
{
    LOG_TRACE("Entering function %s", __FUNCTION__);
	MojAssert(req && service && method);
	MojAssert(m_service || m_handle);
	MojAssertMutexLocked(m_mutex);

	MojLunaRequest* lunaReq = static_cast<MojLunaRequest*>(req);
	const MojChar* json = lunaReq->payload();
    LOG_DEBUG("[db_lunaService] request sent: %s", json);

	MojString uri;
	MojErr err = uri.format(_T("%s://%s/%s"), UriScheme, service, method);
	MojErrCheck(err);

	MojLunaErr lserr;
	LSMessageToken lsToken;
	LSHandle* handle = getHandle(lunaReq->onPublic());
	if (req->numRepliesExpected() > 1) {
		if (!lunaReq->isProxyRequest()) {
			bool retVal = LSCall(handle, uri, json, &handleResponse, this, &lsToken, lserr);
			MojLsErrCheck(retVal, lserr);
		} else {
			bool retVal = LSCallFromApplication(handle, uri, json, lunaReq->getRequester(), &handleResponse, this, &lsToken, lserr);
			MojLsErrCheck(retVal, lserr);
		}
	} else {
		if (!lunaReq->isProxyRequest()) {
			bool retVal = LSCallOneReply(handle, uri, json, &handleResponse, this, &lsToken, lserr);
			MojLsErrCheck(retVal, lserr);
		} else {
			bool retVal = LSCallFromApplicationOneReply(handle, uri, json, lunaReq->getRequester(), &handleResponse, this, &lsToken, lserr);
			MojLsErrCheck(retVal, lserr);
		}
	}
	tokenOut = (Token) lsToken;

	return MojErrNone;
}
예제 #10
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);
}
bool LunaServiceCall::execute(const QString& uri, const QString& arguments)
{
    LSError error;
    LSErrorInit(&error);
    QString errorMessage;

    if (mResponseLimit == 1) {
        if (!LSCallOneReply(mServiceHandle, uri.toUtf8().constData(), arguments.toUtf8().constData(),
                            &LunaServiceCall::responseCallback, this, &mToken, &error)) {
            qWarning("Failed to call remote service %s", uri.toUtf8().constData());
            errorMessage = QString("Failed to call remote service: %0").arg(error.message);
            goto error;
        }
    }
    else {
        if (!LSCall(mServiceHandle, uri.toUtf8().constData(), arguments.toUtf8().constData(),
                            &LunaServiceCall::responseCallback, this, &mToken, &error)) {
            qWarning("Failed to call remote service %s", uri.toUtf8().constData());
            errorMessage = QString("Failed to call remote service: %0").arg(error.message);
            goto error;
        }
    }

    return true;

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

    if (mErrorCallback.isCallable())
        mErrorCallback.call(QJSValueList() << errorMessage);

    return false;
}
예제 #12
0
void InputManager::headsetStateMachine(QEvent* e)
{
	switch (m_headsetBtnState) {

	case Start: {
		if (e->type() == QEvent::KeyPress) {
			m_headsetBtnState = SinglePressOrHold;
			m_headsetBtnTimer.start(PRESS_AND_HOLD_TIME_MS, true); // singleshot
		}
		// if we get an up in this state, we'll ignore it
		// that might happen if the user is holding the button down on
		// start up
		break;
	}
	case SinglePressOrHold: {
		if (e->type() == QEvent::KeyRelease) {
			m_headsetBtnTimer.stop();
			
			// single press
			postKeyToSubscribers(NULL, CATEGORY_HEADSET, STR_HEADSET_BTN, HEADSET_BTN_SINGLE_PRESS);

			m_headsetBtnState = PotentialDoublePress;
			m_headsetBtnTimer.start(DOUBLE_PRESS_TIME_MS, true); // singleshot

			// FIXME:
			// We start an activity timer to make sure that
			// we don't go to sleep before the double-click
			// timer fires.
			LSCallOneReply(m_publicService, ACTIVITY_START_URI, ACTIVITY_JSON_MSG_HEADSET,
					 activityStartCallback, NULL, NULL, NULL);


		} else {
			g_critical("%s: SinglePressOrHold state received event type: %d",
				__PRETTY_FUNCTION__, (int)e->type());
		}
		break;
	}
	case Hold: {
		if (e->type() == QEvent::KeyRelease) {
			// make sure timer is stopped
			m_headsetBtnTimer.stop();
			m_headsetBtnState = Start;
		} else {
			g_critical("%s: Hold state received event type: %d",
				__PRETTY_FUNCTION__, (int)e->type());
		}
		break;
	}
	case PotentialDoublePress: {
		if (e->type() == QEvent::KeyPress) {
			m_headsetBtnTimer.stop();
			m_headsetBtnState = DoublePressOrHold;
			m_headsetBtnTimer.start(PRESS_AND_HOLD_TIME_MS, true);	// singleshot
		} else {
			g_critical("%s: Hold state received event type: %d",
				__PRETTY_FUNCTION__, (int)e->type());
		}
		break;
	}
	case DoublePressOrHold: {
		if (e->type() == QEvent::KeyRelease) {
			m_headsetBtnTimer.stop();
			
			// double press
			postKeyToSubscribers(NULL, CATEGORY_HEADSET, STR_HEADSET_BTN, HEADSET_BTN_DOUBLE_PRESS);
			m_headsetBtnState = Start;
		}
		break;
	}
	default: {
		g_critical("%s: Invalid headset state: %d",
			__PRETTY_FUNCTION__, (int)m_headsetBtnState);
		break;
	}

	}
}