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; }
/*! \page com_palm_keys \n \section com_palm_keys_switches_status switches/status \e Public. com.palm.keys/switches/status Subscribe to switch state changes or request the state of a particular switch. \subsection com_palm_keys_switches_status_syntax_subscribe Syntax for subscribing: \code { "subscribe": boolean } \endcode \param subscribe Set to true to subscribe to status changes. \subsection com_palm_keys_switches_status_syntax_request Syntax for requesting a switch state: \code { "get": string } \endcode \param get Name of the swtich, for example ringer, slider, etc. \subsection com_palm_keys_switches_status_returns_subscribe Returns for subscribe messages: \code { "returnValue": boolean, "subscribe": boolean } \endcode \param returnValue Indicates if the call was succesful. \param subscribe True if subscribed to switch status changes. \subsection com_palm_keys_switches_status_returns_request Returns for request messages: \code { "key": string, "state": string, "returnValue": boolean } \endcode \param key Name of the switch. \param state State of the switch. \param returnValue Indicates if the call was succesful. \subsection com_palm_keys_switches_status_examples Examples: \code luna-send -n 1 -f luna://com.palm.keys/switches/status '{ "get": "ringer" } ' \endcode Example response for a succesful request call: \code { "key": "ringer", "state": "up", "returnValue": true } \endcode Example response for a succesful subscription call: \code { "returnValue": true, "subscribed": true } \endcode Example response for a failed call: \code { "returnValue": false } \endcode */ bool InputManager::switchesStatusCallback(LSHandle* handle, LSMessage* msg, void* userData) { InputManager* i = (InputManager*)userData; // users can subscribe for notification of changes in state and also // request the current state if (LSMessageIsSubscription(msg)) { return processSubscription(handle, msg, userData); } else { return i->processKeyState(handle, msg, userData); } }
// // Handler for the impersonate service. // bool impersonate_handler(LSHandle* lshandle, LSMessage *reply, void *ctx) { bool retVal; LSError lserror; LSErrorInit(&lserror); LSMessage* message = (LSMessage*)ctx; retVal = LSMessageRespond(message, LSMessageGetPayload(reply), &lserror); if (!LSMessageIsSubscription(message)) { LSMessageUnref(message); } if (!retVal) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } return retVal; }
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 }