bool AmbientLightSensor::cancelSubscription(LSHandle *sh, LSMessage *message, void *ctx) { bool result = false; g_debug ("%s: category %s, method %s", __FUNCTION__, LSMessageGetCategory(message), LSMessageGetMethod(message)); AmbientLightSensor *als = (AmbientLightSensor *)ctx; if (0 == strcmp (LSMessageGetMethod(message), "status") && 0 == strcmp (LSMessageGetCategory(message), "/control")) { als->m_alsSubscriptions--; if (als->m_alsSubscriptions == 0) { 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 (result && disable) als->m_alsDisabled--; als->off (); } } return true; }
/** * @brief Returns true if the message is an error message from the hub. * * @param message * * @retval true, if message is error message from hub * @retval false, otherwise */ bool LSMessageIsHubErrorMessage(LSMessage *message) { if (!message) return false; const char *category = LSMessageGetCategory(message); if (!category) return false; return (strcmp(category, LUNABUS_ERROR_CATEGORY) == 0); }
/** * @brief Convenience function to pretty print a message. * * @param lmsg * @param out * * @retval */ bool LSMessagePrint(LSMessage *message, FILE *out) { _LSErrorIfFail(NULL != message, NULL); fprintf(out, "%s/%s <%s>\n", LSMessageGetCategory(message), LSMessageGetMethod(message), LSMessageGetPayload(message)); return true; }
/** * @brief Common callback used for incoming signals. * * @param sh * @param message * @param ctx * * @retval */ static bool ClientNoParamCallback(LSHandle *sh, LSMessage *message, void *ctx) { CBH *helper = (CBH *)ctx; if (!helper || !helper->callback) goto end; if (strcmp(LSMessageGetCategory(message), "/com/palm/power") == 0) { ((PowerdCallback)helper->callback)(); } end: return true; }
/** * @brief Returns the kind of the message (i.e. category + method). * * @param message * * @retval */ const char * LSMessageGetKind(LSMessage *message) { if (!message) return NULL; if (message->kindAllocated) return message->kindAllocated; const char *category = LSMessageGetCategory(message); const char *method = LSMessageGetMethod(message); message->kindAllocated = _LSMessageGetKindHelper(category,method); return message->kindAllocated; }
bool LunaServiceCall::handleResponse(LSHandle *handle, LSMessage *message) { LunaServiceMessage msg(message); mResponseCount++; if (mCallback.isCallable()) { QQmlContext *context = QQmlEngine::contextForObject(parent()); mCallback.call(QJSValueList() << context->engine()->newQObject(&msg)); } const char* category = LSMessageGetCategory(message); bool messageInErrorCategory = (category && strcmp(LUNABUS_ERROR_CATEGORY, category) == 0); if (messageInErrorCategory || (mResponseLimit != -1 && mResponseCount >= mResponseLimit)) cancel(); return true; }