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; }
bool luna_service_check_for_subscription_and_process(LSHandle *handle, LSMessage *message) { LSError lserror; bool subscribed = false; LSErrorInit(&lserror); if (LSMessageIsSubscription(message)) { if (!LSSubscriptionProcess(handle, message, &subscribed, &lserror)) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } } return subscribed; }
static bool handle_get_status_command(LSHandle* sh, LSMessage *message, void* context) { jvalue_ref reply = jobject_create(); LSError lserror; LSErrorInit(&lserror); bool subscribed = false; if (LSMessageIsSubscription(message)) { if (!LSSubscriptionProcess(sh, message, &subscribed, &lserror)) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } jobject_put(reply, J_CSTR_TO_JVAL("subscribed"), jboolean_create(subscribed)); if(!connman_manager_is_manager_available(manager)) goto response; } if(!connman_status_check(manager, sh, message)) goto cleanup; send_connection_status(&reply); response: { jschema_ref response_schema = jschema_parse (j_cstr_to_buffer("{}"), DOMOPT_NOOPT, NULL); if(!response_schema) { LSMessageReplyErrorUnknown(sh,message); goto cleanup; } if (!LSMessageReply(sh, message, jvalue_tostring(reply, response_schema), &lserror)) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } jschema_release(&response_schema); } cleanup: j_release(&reply); return true; }
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 }
bool AmbientLightSensor::controlStatus(LSHandle *sh, LSMessage *message, void *ctx) { #if defined (TARGET_DEVICE) LSError lserror; LSErrorInit(&lserror); bool result = true; AmbientLightSensor *als = (AmbientLightSensor*)ctx; // {"subscribe":boolean, "disableALS" : boolean} VALIDATE_SCHEMA_AND_RETURN(sh, message, SCHEMA_2(REQUIRED(subscribe, boolean), REQUIRED(disableALS, boolean))); g_debug ("%s: received '%s;", __PRETTY_FUNCTION__, LSMessageGetPayload(message)); bool subscribed = false; result = LSSubscriptionProcess (sh, message, &subscribed, &lserror); if(!result) { LSErrorFree (&lserror); result = true; subscribed = false; } if (subscribed) { als->m_alsSubscriptions++; als->on (); bool disable = false; const char* str = LSMessageGetPayload(message); if (str) { json_object* root = json_tokener_parse(str); if (root && !is_error(root)) { result = true; disable = json_object_get_boolean(json_object_object_get(root, "disableALS")); json_object_put(root); } } if (disable) als->m_alsDisabled++; } int ptr = (als->m_alsPointer + als->m_alsSamplesNeeded - 1) % als->m_alsSamplesNeeded; gchar *status = g_strdup_printf ("{\"returnValue\":true,\"current\":%i,\"average\":%i,\"disabled\":%s,\"subscribed\":%s}", als->m_alsValue[ptr], als->m_alsSum / als->m_alsSamplesNeeded, als->m_alsDisabled > 0 ? "true" : "false", subscribed ? "true" : "false"); if (NULL != status) result = LSMessageReply(sh, message, status, &lserror); if(!result) { LSErrorPrint (&lserror, stderr); LSErrorFree (&lserror); } g_free(status); #endif return true; }