예제 #1
0
bool cbGetStatus(LSHandle *handle, LSMessage *message, void *user_data)
{
	SUBSCRIBE_SCHEMA_RETURN(handle, message);

	bool success = true;
	LSError error;
	json_object* json = json_object_new_object();
	bool subscribed = false;
	bool firstUse = false;
	std::string stateStr;

	LSErrorInit(&error);

	if (LSMessageIsSubscription(message)) {
		if (!LSSubscriptionProcess(handle, message, &subscribed, &error)) {
			LSErrorFree (&error);
			goto done;
		}
	}

	stateStr = bootStateToStr(BootManager::instance()->currentState());
	json_object_object_add(json, "state", json_object_new_string(stateStr.c_str()));

done:
	json_object_object_add(json, "returnValue", json_object_new_boolean(success));
	json_object_object_add(json, "subscribed", json_object_new_boolean(subscribed));

	if (!LSMessageReply(handle, message, json_object_to_json_string(json), &error))
		LSErrorFree (&error);

	json_object_put(json);

	return true;
}
예제 #2
0
bool InputManager::processSubscription(LSHandle* handle, LSMessage* msg, void* userData)
{
    SUBSCRIBE_SCHEMA_RETURN(handle, msg);

	// process subscriptions for a group of keys
	bool retVal = false;
	LSError lserror;
	LSErrorInit(&lserror);
	bool subscribed = false;
	json_object* json = json_object_new_object();

	if (LSMessageIsSubscription(msg)) {
		retVal = LSSubscriptionProcess(handle, msg, &subscribed, &lserror);
		if (!retVal) {
			LSErrorPrint (&lserror, stderr);
			LSErrorFree (&lserror);
			goto Error;
		}
	} else {
		json_object_object_add(json, "errorCode", json_object_new_int(-1));
		json_object_object_add(json, "errorText", json_object_new_string("We were expecting a subscribe type message, but we did not recieve one."));
	}

Error:

	json_object_object_add(json, "returnValue", json_object_new_boolean(retVal));
	json_object_object_add(json, "subscribed", json_object_new_boolean(subscribed));
	

	if (!LSMessageReply(handle, msg, json_object_to_json_string(json), &lserror)) {
		LSErrorPrint(&lserror, stderr);
		LSErrorFree (&lserror);
	}
	json_object_put(json);

	return true;	// message has been processed, don't call the callback anymore
}