// returns true on successful subscription post, false on failure
void InputManager::postKeyToSubscribers(QKeyEvent* event, const char* category, const char* keyString, const char* keyValue)
{
	LSError lserror;
	LSErrorInit(&lserror);
	
	json_object* response = NULL;

	if (!m_publicService || !m_service)
		return;

	// normally this will be called with an event ptr, but if we pass it a 
	// "keyValue", then we'll ignore the event ptr and use that directly
	if (keyValue != NULL) {
		response = createKeyJson(keyString, keyValue);
	} else {
		response = createKeyJson(keyString, event->type());
	}

	const char* payloadStr = json_object_to_json_string(response);

	// Post to all subscribers on private bus
	if (!LSSubscriptionPost(m_service, category, METHOD_STATUS, payloadStr, &lserror)) {
		LSErrorPrint(&lserror, stderr);
		LSErrorFree(&lserror);
	}

	// If it's a public category, post it to public subscribers
	if (isPublicCategory(category)) {
		if (!LSSubscriptionPost(m_publicService, category, METHOD_STATUS, payloadStr, &lserror)) {
			LSErrorPrint(&lserror, stderr);
			LSErrorFree(&lserror);
		}
	}

	if (response && !is_error(response))
		json_object_put(response);
}
Exemple #2
0
void luna_service_post_subscription(LSHandle *handle, const char *path, const char *method, jvalue_ref reply_obj)
{
	jschema_ref response_schema = NULL;
	LSError lserror;

	LSErrorInit(&lserror);

	response_schema = jschema_parse (j_cstr_to_buffer("{}"), DOMOPT_NOOPT, NULL);
	if(!response_schema)
		goto cleanup;

	if (!LSSubscriptionPost(handle, path, method,
						jvalue_tostring(reply_obj, response_schema), &lserror)) {
		LSErrorPrint(&lserror, stderr);
		LSErrorFree(&lserror);
	}

cleanup:
	if (response_schema)
		jschema_release(&response_schema);
}
void BootManager::postCurrentState()
{
	LSError error;
	json_object* json = 0;

    if (m_currentState == BOOT_STATE_FIRSTUSE ||
        m_currentState == BOOT_STATE_NORMAL)
        Q_EMIT bootFinished();

	LSErrorInit(&error);

	json = json_object_new_object();

	std::string stateStr = bootStateToStr(m_currentState);
	json_object_object_add(json, (char*) "state", json_object_new_string(stateStr.c_str()));

	if (!LSSubscriptionPost(m_service, "/", "getStatus", json_object_to_json_string(json), &error))
		LSErrorFree (&error);

	json_object_put(json);
}
void connectionmanager_send_status(void)
{
	jvalue_ref reply = jobject_create();
	jobject_put(reply, J_CSTR_TO_JVAL("returnValue"), jboolean_create(true));

	send_connection_status(&reply);

	jschema_ref response_schema = jschema_parse (j_cstr_to_buffer("{}"), DOMOPT_NOOPT, NULL);
	if(response_schema)
	{
		const char *payload = jvalue_tostring(reply, response_schema);
		LSError lserror;
		LSErrorInit(&lserror);
		WCA_LOG_INFO("Sending payload %s",payload);
		if (!LSSubscriptionPost(pLsHandle, "/", "getstatus", payload, &lserror))
		{
			LSErrorPrint(&lserror, stderr);
			LSErrorFree(&lserror);
		}
		jschema_release(&response_schema);
	}
	j_release(&reply);
}