static bool alarms_timeout_subscribe_cb(LSHandle *sh, LSMessage *message, void *ctx) { bool retVal; bool fired = false; struct context *alrm_ctx = (struct context *)ctx; const char *payload = LSMessageGetPayload(message); struct json_object *object = json_tokener_parse(payload); if (is_error(object)) { POWERDLOG(LOG_CRIT,"%s: invalid json from sleep daemon",__func__); } else { fired = json_object_get_boolean(json_object_object_get(object, "fired")); } POWERDLOG(LOG_INFO,"%s: response with payload %s, count : %d", __FUNCTION__, payload, alrm_ctx->count); if(alrm_ctx->replyMessage) { if(fired) { retVal = LSMessageReply(GetLunaServiceHandle(), alrm_ctx->replyMessage, payload, NULL); if (!retVal) { POWERDLOG(LOG_WARNING, "%s could not send reply.", __FUNCTION__); } } else if(LSMessageGetConnection(alrm_ctx->replyMessage)) { retVal = LSMessageReply(LSMessageGetConnection(alrm_ctx->replyMessage), alrm_ctx->replyMessage, payload, NULL); if (!retVal) { POWERDLOG(LOG_WARNING, "%s could not send reply.", __FUNCTION__); } } alrm_ctx->count++; } else POWERDLOG(LOG_CRIT,"%s: replyMessage is NULL",__func__); if(alrm_ctx->count == 2) { if(!LSCallCancel(sh, alrm_ctx->call_token, NULL)) { POWERDLOG(LOG_WARNING, "%s could not cancel luna-service alarm call.", __FUNCTION__); } LSMessageUnref(alrm_ctx->replyMessage); free(alrm_ctx); } if (!is_error(object)) json_object_put(object); return true; }
/** * @brief Send a reply to message using the same bus that * message came from. * * @param lsmsg * @param reply_payload * @param lserror * * @retval */ bool LSMessageRespond(LSMessage *message, const char *reply_payload, LSError *lserror) { return LSMessageReply(LSMessageGetConnection(message), message, reply_payload, lserror); }
static bool suspend_ipc_method_cb(LSHandle *sh, LSMessage *message, void *ctx) { bool retVal; LSMessage *replyMessage = (LSMessage *)ctx; POWERDLOG(LOG_INFO,"%s: response with payload %s", __FUNCTION__, LSMessageGetPayload(message)); if(replyMessage && LSMessageGetConnection(replyMessage)) { retVal = LSMessageReply(LSMessageGetConnection(replyMessage), replyMessage, LSMessageGetPayload(message), NULL); if (!retVal) { POWERDLOG(LOG_WARNING, "%s could not send reply.", __FUNCTION__); } LSMessageUnref(replyMessage); } else POWERDLOG(LOG_CRIT,"%s: replyMessage is NULL",__func__); return true; }
MojErr MojLunaService::enableSubscriptionImpl(MojServiceMessage* msg) { LOG_TRACE("Entering function %s", __FUNCTION__); MojAssert(msg); MojAssertMutexUnlocked(m_mutex); MojString token; MojErr err = token.format(_T("%d"), msg->token()); MojErrCheck(err); MojLunaErr lserr; MojLunaMessage* lsMessage = static_cast<MojLunaMessage*>(msg); LSHandle* handle = LSMessageGetConnection(lsMessage->impl()); bool retVal = LSSubscriptionAdd(handle, token, lsMessage->impl(), lserr); MojLsErrCheck(retVal, lserr); return MojErrNone; }
/** * @brief Send a reply to a message using the bus identified by LSHandle. * * To use the same bus upon which the message arrived, it is * recommended to use LSMessageRespond(). * * @param sh * @param lsmsg * @param replyPayload * @param lserror * * @retval */ bool LSMessageReply(LSHandle *sh, LSMessage *lsmsg, const char *replyPayload, LSError *lserror) { _LSErrorIfFail (sh != NULL, lserror); _LSErrorIfFail (lsmsg != NULL, lserror); _LSErrorIfFail (replyPayload != NULL, lserror); LSHANDLE_VALIDATE(sh); if (unlikely(_ls_enable_utf8_validation)) { if (!g_utf8_validate (replyPayload, -1, NULL)) { _LSErrorSet(lserror, -EINVAL, "%s: payload is not utf-8", __FUNCTION__); return false; } } if (unlikely(strcmp(replyPayload, "") == 0)) { _LSErrorSet(lserror, -EINVAL, "Empty payload is not valid JSON. Use {}"); return false; } if (DEBUG_TRACING) { if (DEBUG_VERBOSE) { g_debug("TX: LSMessageReply token <<%ld>> %s", LSMessageGetToken(lsmsg), replyPayload); } else { g_debug("TX: LSMessageReply token <<%ld>>", LSMessageGetToken(lsmsg)); } } if (_LSTransportMessageGetType(lsmsg->transport_msg) == _LSTransportMessageTypeReply) { g_warning("%s: \nYou are attempting to send a reply to a reply message. \n" "I'm going to allow this for now to more easily reproduce some bugs \n" "we encountered with services using LSCustomWaitForMessage \n" "receiving a reply-to-a-reply, but soon this will return an error.", __FUNCTION__); } if (unlikely(LSMessageGetConnection(lsmsg) != sh)) { _LSErrorSet(lserror, -EINVAL, "%s: You are replying to message on different bus.\n" " If you can't identify which bus, " "try LSMessageRespond() instead.", __FUNCTION__); return false; } bool retVal = _LSTransportSendReply(lsmsg->transport_msg, replyPayload, lserror); return retVal; }