// // Run ls-monitor --capture and provide the output back to Mojo // bool ls2Monitor_method(LSHandle* lshandle, LSMessage *message, void *ctx) { LSError lserror; LSErrorInit(&lserror); if (ls2MonitorThread) { syslog(LOG_NOTICE, "Ls2 thread already running\n"); if (!LSMessageReply(lshandle, message, "{\"returnValue\": false, \"ouroboros\": true, \"stage\": \"failed\"}", &lserror)) goto error; return true; } syslog(LOG_DEBUG, "Create ls2 thread, ref message %p\n", message); // Ref and save the message for use in ls2 thread LSMessageRef(message); if (pthread_create(&ls2MonitorThread, NULL, ls2_monitor, (void*)message)) { syslog(LOG_ERR, "Creating ls2 thread failed (0x%x)\n", ls2MonitorThread); // Report that the ls2 operation was not able to start if (!LSMessageReply(lshandle, message, "{\"returnValue\": false, \"ouroboros\": true, \"errorCode\": -1, \"errorText\": \"Unable to start ls2 thread\"}", &lserror)) goto error; } else { syslog(LOG_DEBUG, "Created ls2 thread successfully (0x%x)\n", ls2MonitorThread); // Report that the ls2 operation has begun if (!LSMessageReply(lshandle, message, "{\"returnValue\": true, \"ouroboros\": true, \"stage\": \"start\"}", &lserror)) goto error; } return true; error: LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); end: return false; }
static bool _SubscriptionResultsCallback(LSHandle *sh, LSMessage *reply, void *ctx) { static int received_replies = 0; _SubscriptionReplyData *reply_data = ctx; LSMessageRef(reply); (*reply_data->reply_list) = g_slist_prepend((*reply_data->reply_list), reply); received_replies++; if (received_replies == reply_data->total_replies) { _PrintSubscriptionResults(); g_slist_free(private_sub_replies); g_slist_free(public_sub_replies); g_free(reply_data); /* done */ g_main_loop_quit(mainloop); } return true; }
/** * @brief Obtain the next subscription message. * * @param iter * * @retval */ LSMessage * LSSubscriptionNext(LSSubscriptionIter *iter) { _Subscription *subs = NULL; LSMessage *message = NULL; iter->index++; const char *tok = _SubListGet(iter->tokens, iter->index); if (tok) { subs = _SubscriptionAcquire(iter->catalog, tok); if (subs) { message = subs->message; LSMessageRef(message); iter->seen_messages = g_slist_prepend(iter->seen_messages, message); _SubscriptionRelease(iter->catalog, subs); } } return message; }
/** * @brief Start an activity. */ bool activityStartCallback(LSHandle *sh, LSMessage *message, void *user_data) { LSMessageRef(message); LSCall(GetLunaServiceHandle(), SLEEPD_SUSPEND_SERVICE"activityStart", LSMessageGetPayload(message), suspend_ipc_method_cb,(void *)message, NULL, NULL); return true; }
/** * @brief Called by test code to reset state machine to square 1. * * @retval */ static bool TESTresetShutdownState(LSHandle *sh, LSMessage *message, void *user_data) { LSMessageRef(message); LSCallOneReply(GetLunaServiceHandle(), SLEEPD_SHUTDOWN_SERVICE"TESTresetShutdownState", LSMessageGetPayload(message), shutdown_method_cb,(void *)message, NULL, NULL); return true; }
bool prepareSuspendRegister(LSHandle *sh, LSMessage *message, void *data) { LSMessageRef(message); LSCall(GetLunaServiceHandle(), SLEEPD_SUSPEND_SERVICE"prepareSuspendRegister", LSMessageGetPayload(message), suspend_ipc_method_cb,(void *)message, NULL, NULL); return true; }
/** * @brief Turn on/off visual leds suspend via luna-service. * * @retval */ bool visualLedSuspendCallback(LSHandle *sh, LSMessage *message, void *data) { LSMessageRef(message); LSCall(GetLunaServiceHandle(), SLEEPD_SUSPEND_SERVICE"visualLedSuspend", LSMessageGetPayload(message), suspend_ipc_method_cb,(void *)message, NULL, NULL); return true; }
static bool alarmRemove(LSHandle *sh, LSMessage *message, void *ctx) { LSMessageRef(message); LSCallOneReply(GetLunaServiceHandle(), "palm://com.palm.sleep/time/alarmRemove", LSMessageGetPayload(message), alarms_timeout_cb, (void *)message, NULL, NULL); return true; }
/** * @brief Ack the "shutdownApplications" signal. */ static bool shutdownApplicationsAck(LSHandle *sh, LSMessage *message, void *user_data) { LSMessageRef(message); LSCallOneReply(GetLunaServiceHandle(), SLEEPD_SHUTDOWN_SERVICE"shutdownApplicationsAck", LSMessageGetPayload(message), shutdown_method_cb,(void *)message, NULL, NULL); return true; }
static bool play_feedback_cb(LSHandle *handle, LSMessage *message, void *user_data) { struct audio_service *service = user_data; struct play_feedback_data *pfd; const char *payload; jvalue_ref parsed_obj; char *name, *sink; bool play; if (!service->context_initialized) { luna_service_message_reply_custom_error(handle, message, "Not yet initialized"); return true; } payload = LSMessageGetPayload(message); parsed_obj = luna_service_message_parse_and_validate(payload); if (jis_null(parsed_obj)) { luna_service_message_reply_error_bad_json(handle, message); goto cleanup; } name = luna_service_message_get_string(parsed_obj, "name", NULL); if (!name) { luna_service_message_reply_custom_error(handle, message, "Invalid parameters: name parameter is required"); goto cleanup; } play = luna_service_message_get_boolean(parsed_obj, "play", true); sink = luna_service_message_get_string(parsed_obj, "sink", NULL); pfd = g_new0(struct play_feedback_data, 1); pfd->service = service; pfd->handle = handle; pfd->message = message; pfd->name = name; pfd->sink = sink; pfd->play = play; LSMessageRef(message); if (!preload_sample(service, pfd)) { luna_service_message_reply_custom_error(handle, message, "Could not preload sample"); LSMessageUnref(message); g_free(pfd); g_free(name); g_free(sink); goto cleanup; } cleanup: if (!jis_null(parsed_obj)) j_release(&parsed_obj); return true; }
// // Call the getStats service using liblunaservice and return the output to webOS. // bool getStats_method(LSHandle* lshandle, LSMessage *message, void *ctx) { bool retVal; LSError lserror; LSErrorInit(&lserror); LSMessageRef(message); retVal = LSCall(priv_serviceHandle, "palm://com.palm.lunastats/getStats", "{\"subscribe\":true}", getStats_handler, message, NULL, &lserror); if (!retVal) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } return retVal; }
// // Call the listApps service using liblunaservice and return the output to webOS. // bool listApps_method(LSHandle* lshandle, LSMessage *message, void *ctx) { bool retVal; LSError lserror; LSErrorInit(&lserror); LSMessageRef(message); retVal = LSCall(priv_serviceHandle, "palm://com.palm.applicationManager/listApps", "{}", listApps_handler, message, NULL, &lserror); if (!retVal) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } return retVal; }
/** * @brief Add a new alarm to the queue. * * @param id * @param calendar_time * @param expiry * @param serviceName * @param applicationName * * @retval */ static bool alarm_queue_add(uint32_t id, const char *key, bool calendar_time, time_t expiry, const char *serviceName, const char *applicationName, bool subscribe, LSMessage *message) { _Alarm *alarm = g_new0(_Alarm, 1); alarm->key = g_strdup(key); alarm->id = id; alarm->calendar = calendar_time; alarm->expiry = expiry; alarm->serviceName = g_strdup(serviceName); alarm->applicationName = g_strdup(applicationName); if (subscribe) { LSError lserror; LSErrorInit(&lserror); bool retVal = LSSubscriptionAdd( GetLunaServiceHandle(), "alarm", message, &lserror); if (!retVal) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); goto error; } LSMessageRef(message); alarm->message = message; } alarm_print(alarm); if (alarm->id >= gAlarmQueue->seq_id) { gAlarmQueue->seq_id = alarm->id + 1; } g_sequence_insert_sorted(gAlarmQueue->alarms, alarm, (GCompareDataFunc)alarm_cmp_func, NULL); update_alarms(); return true; error: return false; }
// // Call the swapResourceHandler service using liblunaservice and return the output to webOS. // bool swapResource_method(LSHandle* lshandle, LSMessage *message, void *ctx) { bool retVal; LSError lserror; LSErrorInit(&lserror); LSMessageRef(message); const char *payload; payload = LSMessageGetPayload(message); retVal = LSCall(priv_serviceHandle, "palm://com.palm.applicationManager/swapResourceHandler", payload, swapResource_handler, message, NULL, &lserror); if (!retVal) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } return retVal; }
/** * @brief Create a new subscription. * * @param message * * @retval */ static _Subscription * _SubscriptionNew(LSHandle *sh, LSMessage *message) { _Subscription *subs; subs = g_new0(_Subscription,1); subs->ref = 1; subs->keys = g_ptr_array_new(); LSMessageRef(message); subs->message = message; return subs; }
/** * @brief The callback function for "initiate" method. This will initiate the shutdown process. * * @param sh * @param message This method doesn't need any arguments. * @param user_data */ static bool initiateShutdown(LSHandle *sh, LSMessage *message, void *user_data) { ShutdownEvent event; event.id = kShutdownEventShutdownInit; event.client = NULL; LSMessageRef(message); shutdown_message = message; g_timer_start(shutdown_timer); shutdown_state_dispatch(&event); return true; }
/** * @brief Add a new alarm based on calender time. Sets the callback function based on the "subscribe" option value. */ static bool alarmAddCalendar(LSHandle *sh, LSMessage *message, void *ctx) { struct json_object *object=NULL; object = json_tokener_parse(LSMessageGetPayload(message)); if ( is_error(object) ) { goto malformed_json; } struct json_object *subscribe_json = json_object_object_get(object, "subscribe"); bool subscribe = json_object_get_boolean(subscribe_json); LSMessageRef(message); if(subscribe) { struct context *alrm_ctx=NULL; alrm_ctx = malloc(sizeof(struct context)); if(!alrm_ctx) goto error; memset(alrm_ctx,0,sizeof(struct context)); alrm_ctx->replyMessage = message; LSCall(GetLunaServiceHandle(), "palm://com.palm.sleep/time/alarmAddCalender", LSMessageGetPayload(message), alarms_timeout_subscribe_cb, (void *)alrm_ctx, &alrm_ctx->call_token, NULL); } else LSCallOneReply(GetLunaServiceHandle(), "palm://com.palm.sleep/time/alarmAddCalender", LSMessageGetPayload(message), alarms_timeout_cb, (void *)message, NULL, NULL); goto cleanup; malformed_json: LSMessageReplyErrorBadJSON(sh, message); goto cleanup; error: POWERDLOG(LOG_ERR,"Failed to allocate memory"); LSMessageReplyErrorUnknown(sh, message); cleanup: if (!is_error(object)) json_object_put(object); return true; }
static bool shutdownServicesRegister(LSHandle *sh, LSMessage *message, void *user_data) { LSMessageRef(message); LSCallOneReply(GetLunaServiceHandle(), SLEEPD_SHUTDOWN_SERVICE"shutdownServicesRegister", LSMessageGetPayload(message), shutdown_method_cb,(void *)message, NULL, NULL); bool retVal; LSError lserror; LSErrorInit(&lserror); retVal = LSSubscriptionAdd(sh, "shutdownClient", message, &lserror); if (!retVal) { g_critical("LSSubscriptionAdd failed."); LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } return true; }
/** * @brief Register a new client. */ bool identifyCallback(LSHandle *sh, LSMessage *message, void *data) { LSMessageRef(message); LSCall(GetLunaServiceHandle(), SLEEPD_SUSPEND_SERVICE"identify", LSMessageGetPayload(message), suspend_ipc_method_cb,(void *)message, NULL, NULL); struct json_object *object = json_tokener_parse(LSMessageGetPayload(message)); if ( is_error(object) ) { goto out; } bool subscribe = json_object_get_boolean(json_object_object_get(object, "subscribe")); if (subscribe) { LSSubscriptionAdd(sh, "PowerdClients", message, NULL); } out: return true; }
LunaServiceMessage::LunaServiceMessage(LSMessage *message, QObject *parent) : QObject(parent), mMessage(message) { LSMessageRef(mMessage); }
// // Impersonate a call to the requested service and return the output to webOS. // bool impersonate_method(LSHandle* lshandle, LSMessage *message, void *ctx) { bool retVal; LSError lserror; LSErrorInit(&lserror); LSMessageRef(message); if (access_denied(message)) return true; // Extract the method argument from the message json_t *object = json_parse_document(LSMessageGetPayload(message)); json_t *id = json_find_first_label(object, "id"); if (!id || (id->child->type != JSON_STRING)) { if (!LSMessageRespond(message, "{\"returnValue\": false, \"errorCode\": -1, \"errorText\": \"Invalid or missing id\"}", &lserror)) goto error; return true; } // Extract the service argument from the message object = json_parse_document(LSMessageGetPayload(message)); json_t *service = json_find_first_label(object, "service"); if (!service || (service->child->type != JSON_STRING)) { if (!LSMessageRespond(message, "{\"returnValue\": false, \"errorCode\": -1, \"errorText\": \"Invalid or missing service\"}", &lserror)) goto error; return true; } // Extract the method argument from the message object = json_parse_document(LSMessageGetPayload(message)); json_t *method = json_find_first_label(object, "method"); if (!method || (method->child->type != JSON_STRING)) { if (!LSMessageRespond(message, "{\"returnValue\": false, \"errorCode\": -1, \"errorText\": \"Invalid or missing method\"}", &lserror)) goto error; return true; } // Extract the params argument from the message object = json_parse_document(LSMessageGetPayload(message)); json_t *params = json_find_first_label(object, "params"); if (!params || (params->child->type != JSON_OBJECT)) { if (!LSMessageRespond(message, "{\"returnValue\": false, \"errorCode\": -1, \"errorText\": \"Invalid or missing params\"}", &lserror)) goto error; return true; } char uri[MAXLINLEN]; sprintf(uri, "palm://%s/%s", service->child->text, method->child->text); char *paramstring = NULL; json_tree_to_string (params->child, ¶mstring); if (!LSCallFromApplication(priv_serviceHandle, uri, paramstring, id->child->text, impersonate_handler, message, NULL, &lserror)) goto error; return true; error: LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); end: return false; }