/** * @brief This method will make the async call to DBUS. * * @param uri * @param payload * @param listener * * @retval 0 if message could not be sent. * @retval >0 serial number for the message. */ unsigned long service_invoker::async_call(svc_accessor* accessor , const char* uri , const char* payload , invoke_listener_base* listener , bool use_private_bus_) { LOG(__PRETTY_FUNCTION__); hl::ls_error lserror; LSMessageToken token = 0; //com.hl.luna- if (!listener) hl::std_throw_("The listener not set."); if (LSCall(use_private_bus_ ? accessor->private_bus_ : accessor->bus_ , uri , payload , message_filter_async, listener, &token, &lserror)) { listener->token_ = token; } return token; }
void AlertWebApp::startPowerdActivity() { if (!m_isPowerdActivityRunning) { LSHandle* lshandle = WebAppManager::instance()->getStatsServiceHandle(); LSError lsError; LSErrorInit(&lsError); gchar* activityId = g_strdup_printf("com.palm.lunastats-alert-%p", this); g_message ("%s: starting powerd activity for %s", __PRETTY_FUNCTION__, activityId); gchar* params = g_strdup_printf("{\"id\": \"%s\", \"duration_ms\": %d}", activityId, kAlertActivityDuration); bool ret = LSCall(lshandle, "palm://com.palm.power/com/palm/power/activityStart", params, NULL, NULL, NULL, &lsError); g_free (activityId); g_free (params); if (!ret) { g_warning("%s: Failed to call powerd activityStart: %s", __PRETTY_FUNCTION__, lsError.message); LSErrorFree(&lsError); return; } m_isPowerdActivityRunning = true; } }
void Preferences::registerService() { bool ret; LSError error; LSErrorInit(&error); ret = LSRegister(NULL, &m_lsHandle, &error); if (!ret) { g_critical("Failed to register handler: %s", error.message); LSErrorFree(&error); exit(1); } ret = LSGmainAttach(m_lsHandle, HostBase::instance()->mainLoop(), &error); if (!ret) { g_critical("Failed to attach service to main loop: %s", error.message); LSErrorFree(&error); exit(1); } ret = LSCall(m_lsHandle, "palm://com.palm.lunabus/signal/registerServerStatus", "{\"serviceName\":\"com.palm.systemservice\"}", serverConnectCallback, this, &m_serverStatusToken, &error); if (!ret) { g_critical("Failed in calling palm://com.palm.lunabus/signal/registerServerStatus: %s", error.message); LSErrorFree(&error); exit(1); } }
static bool clientCancel(LSHandle *sh, LSMessage *message, void *ctx) { LSCall(GetLunaServiceHandle(), SLEEPD_SUSPEND_SERVICE"clientCancelByName", LSMessageGetPayload(message), NULL,(void *)message, NULL, NULL); return true; }
/** * @brief This method will make the call to DBUS. * * @param accessor * @param uri * @param payload * @param listener * @param use_private_bus_ * * @retval 0 if message could not be sent. * @retval >0 serial number for the message. */ std::size_t service_invoker::call(svc_accessor* accessor , const char* uri , const char* payload , invoke_listener_base* listener , bool use_private_bus_) { LOG(__PRETTY_FUNCTION__); if (!listener) hl::std_throw_("The listener was not set."); // This place we had many errors. // We can't use service created as -active hl::ls_error lserror; // Set the accessor to std::mutex locker; std::unique_lock<std::mutex> lock(locker); if (LSCall(use_private_bus_ ? accessor->private_bus_ : accessor->bus_ , uri, payload, message_filter<invoke_listener_base>, listener, 0, &lserror)) { listener->cv_.wait(lock); (*listener)(0); return 1; } return 0; }
/** * Simply start the healthCheck timer with a single refresh setting * Also start activity if necessary */ void SoundPlayer::startTimer() { if (!m_timer.running()) { m_timer.start(1000, false); m_activityID = ++m_activityCount; gchar * request = g_strdup_printf("{\"id\":\"com.palm.sysmgr.soundplayer.%i\",\"duration_ms\":60000}", m_activityID); LSError lserror; LSErrorInit(&lserror); bool activityStartRequestSuccess = LSCall(getServiceHandle(), "palm://com.palm.power/com/palm/power/activityStart", request, NULL, NULL, NULL, &lserror); if (!activityStartRequestSuccess) { CRITICAL("SoundPlayer::startTimer: activity '%s' Start failed", request); LSErrorPrint (&lserror, stderr); LSErrorFree (&lserror); } else DEBUG("SoundPlayer::startTimer: booked activity '%s'...", request); g_free(request); } m_lastPlayingTime = currentTime(); }
void AppEffector::remove(const QString& webosAppId,const QUuid& iconUid) { WebOSApp * pWebOSapp = AppMonitor::appMonitor()->webosAppByAppId(webosAppId); if (!pWebOSapp) { qDebug() << __FUNCTION__ << ": didn't find a webos app with appId ["<<webosAppId<<"]"; return; } ApplicationDescription * pAppDesc = ApplicationManager::instance()->getAppById(StringTranslator::outputString(pWebOSapp->appId())); if (!pAppDesc) { return; } //if the app is a sysmgr builtin, then ignore if (pAppDesc->type() == ApplicationDescription::Type_SysmgrBuiltin) { return; } //check to see if the icon that triggered this is an auxiliary launch point or the main one WOAppIconType::Enum type; QString launchPointId = pWebOSapp->launchpointIdOfIcon(iconUid,&type); if (type == WOAppIconType::Auxiliary) { //yes, auxiliary...delegate to removeLaunchpoint g_message("%s: The remove was on one of the app's auxiliary icons (launchpoints)...delegating to another function to do that removal", __FUNCTION__); return removeLaunchpoint(webosAppId,launchPointId); } g_message("%s: The remove is on the app's main icon; the whole app will be removed from the system",__FUNCTION__); //else, it's the main icon, so the app removal procedure needs to take place pWebOSapp->m_stateBeingRemoved = true; //this is set in case at some point the removal process needs to go async //I'm going to hijack ApplicationManager's LS handle to make a call to remove an app json_object* payload = json_object_new_object(); LSError lserror; LSErrorInit(&lserror); ///TODO: do I want to track remove status??? json_object_object_add(payload, "id", json_object_new_string(pWebOSapp->appId().toAscii().constData())); if (!LSCall(ApplicationManager::instance()->m_serviceHandlePrivate, "palm://com.palm.appInstallService/remove",json_object_to_json_string(payload), NULL, NULL, NULL, &lserror)) { LSErrorFree(&lserror); } json_object_put(payload); //!...this HAS TO BE THE LAST CALL IN THIS FUNCTION!!! and also, make sure nothing much happens up the chain either #if defined(TARGET_DESKTOP) LauncherObject::primaryInstance()->slotAppPreRemove(*pWebOSapp,DimensionsSystemInterface::AppMonitorSignalType::AppManSourced); #endif return; }
/** * @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; }
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; }
void HostArmPixie::getInitialSwitchStates() { LSError err; LSErrorInit(&err); if (!LSCall(m_service, HIDD_RINGER_URI, HIDD_GET_STATE, HostArm::switchStateCallback, (void*)SW_RINGER, NULL, &err)) goto Error; if (!LSCall(m_service, HIDD_HEADSET_URI, HIDD_GET_STATE, HostArm::switchStateCallback, (void*)SW_HEADPHONE_INSERT, NULL, &err)) goto Error; Error: if (LSErrorIsSet(&err)) { LSErrorPrint(&err, stderr); LSErrorFree(&err); } }
static void turnNovacomOn(LSHandle * lshandle) { LSError lserror; LSErrorInit(&lserror); if (!(LSCall(lshandle,"palm://com.palm.connectionmanager/setnovacommode", "{\"isEnabled\":true, \"bypassFirstUse\":false}", NULL,NULL,NULL, &lserror))) { g_message("%s: failed to force novacom to On state",__FUNCTION__); LSErrorFree(&lserror); } }
// // 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; }
void _PowerdClientIPCRun(void) { bool retVal; LSError lserror; LSErrorInit(&lserror); if (!gServiceHandle) { retVal = LSRegister(NULL, &gServiceHandle, &lserror); if (!retVal) goto error; if (!gMainLoop) { int ret; GMainContext *context = g_main_context_new(); if (!context) goto error; gMainLoop = g_main_loop_new(context, FALSE); g_main_context_unref(context); if (!gMainLoop) goto error; pthread_attr_t attr; pthread_attr_init(&attr); ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); assert(ret == 0); pthread_t tid; pthread_create(&tid, &attr, _PowerdIPCThread, NULL); } retVal = LSGmainAttach(gServiceHandle, gMainLoop, &lserror); if (!retVal) goto error; } retVal = LSCall(gServiceHandle, "luna://com.palm.lunabus/signal/registerServerStatus", "{\"serviceName\":\"com.palm.power\"}", _powerd_server_up, NULL, NULL, &lserror); if (!retVal) goto error; return; error: LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); return; }
// // 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; }
void BootStateFirstUse::createLocalAccount() { LSError error; LSErrorInit(&error); QFile localProfileMarker("/var/luna/preferences/first-use-profile-created"); if (!localProfileMarker.exists()) { if (!LSCall(BootManager::instance()->service(), "palm://com.palm.service.accounts/createLocalAccount", "{}", cbCreateLocalAccount, NULL, NULL, &error)) { g_warning("Failed to create local account after first use is done: %s", error.message); } } else { BootManager::instance()->switchState(BOOT_STATE_NORMAL); } }
void WindowServerLuna::slotFullEraseDevice() { LSHandle* handle = SystemService::instance()->serviceHandle(); LSError err; LSErrorInit(&err); luna_assert(handle != 0); LSCall(handle, "palm://com.palm.storage/erase/EraseAll", "{}", &WindowServerLuna::cbFullEraseCallback, this, NULL, &err); if (LSErrorIsSet(&err)) { LSErrorPrint(&err, stderr); LSErrorFree(&err); } else { m_fullErasePending = 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 void _ListServiceSubscriptions(LSHandle *sh, LSFilterFunc callback, GSList *monitor_list, int total_services, GSList **reply_list) { LSError lserror; LSErrorInit(&lserror); _LSMonitorListInfo *cur = NULL; bool retVal = false; _SubscriptionReplyData *data = g_malloc(sizeof(_SubscriptionReplyData)); if (!data) { g_critical("Out of memory when allocating reply data"); exit(EXIT_FAILURE); } /* NOTE: we only allocate one of these items and pass it as the data to all the callbacks */ data->reply_list = reply_list; data->total_replies = total_services; for (; monitor_list != NULL; monitor_list = g_slist_next(monitor_list)) { cur = monitor_list->data; /* skip any non-services and the monitor itself */ if (!_CanGetSubscriptionInfo(cur)) { continue; } char *uri = g_strconcat("palm://", cur->service_name, list_subscriptions ? SUBSCRIPTION_DEBUG_METHOD : MALLOC_DEBUG_METHOD, NULL); retVal = LSCall(sh, uri, "{}", callback, data, NULL, &lserror); if (!retVal) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } g_free(uri); } }
void DisplayBlocker::acquire(const char *clientName) { if (!m_service) return; char *parameters = g_strdup_printf("{\"requestBlock\":true,\"client\":\"%s\"}", clientName); LSError lserror; LSErrorInit(&lserror); if (!LSCall(m_service, "palm://com.palm.display/control/setProperty", parameters, cbRegistrationResponse, this, &m_token, &lserror)) { m_token = 0; LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } }
void AppEffector::remove(ExternalApp * pApp) { //TODO: IMPLEMENT (unfinished) if (!pApp) { return; } WebOSApp * pWebOSapp = qobject_cast<WebOSApp *>(pApp); pApp->m_stateBeingRemoved = true; //this is set in case at some point the removal process needs to go async qDebug() << __FUNCTION__ << ": Removing app " << pApp->m_uid << (pWebOSapp ? QString(" , ") + pWebOSapp->appId() : QString(" (not a webOS app type)")); if (!pWebOSapp) { qDebug() << __FUNCTION__ << ": not supporting removal of non-WebOSApp type at this point"; return; } //I'm going to hijack ApplicationManager's LS handle to make a call to remove an app json_object* payload = json_object_new_object(); LSError lserror; LSErrorInit(&lserror); ///TODO: do I want to track remove status??? json_object_object_add(payload, "id", json_object_new_string(pWebOSapp->appId().toAscii().constData())); if (!LSCall(ApplicationManager::instance()->m_serviceHandlePrivate, "palm://com.palm.appInstallService/remove",json_object_to_json_string(payload), NULL, NULL, NULL, &lserror)) { LSErrorFree(&lserror); } json_object_put(payload); //!...this HAS TO BE THE LAST CALL IN THIS FUNCTION!!! and also, make sure nothing much happens up the chain either #if defined(TARGET_DESKTOP) LauncherObject::primaryInstance()->slotAppPreRemove(*pWebOSapp,DimensionsSystemInterface::AppMonitorSignalType::AppManSourced); #endif return; }
/** * Client side cancel point. Also used internally. */ void SoundPlayer::stop() { PRINTF_BLUE("SoundPlayer::stop(%s)", getStateName()); if (m_state == eState_PlayPending || m_state == eState_Playing) { if (VERIFY(m_player)) { m_player->pause(); m_player->unload(); } setState(eState_Closing); } else { // not sure why we were not playing: don't take chance... WARNING("SoundPlayer::stop(%s): unexpected stop request. Declaring SoundPlayer object dead.", getStateName()); setState(eState_Dead); } m_filePath.clear(); m_streamClass.clear(); m_lastPlayingTime = currentTime(); m_fakeBackupRingtoneCount = 0; if (m_activityID) { gchar * request = g_strdup_printf("{\"id\":\"com.palm.sysmgr.soundplayer.%i\"}", m_activityID); LSError lserror; LSErrorInit(&lserror); bool activityStartRequestSuccess = LSCall(getServiceHandle(), "palm://com.palm.power/com/palm/power/activityEnd", request, NULL, NULL, NULL, &lserror); if (!activityStartRequestSuccess) { CRITICAL("SoundPlayer::stop: activity '%s' End failed", request); LSErrorPrint (&lserror, stderr); LSErrorFree (&lserror); } else DEBUG("SoundPlayer::stop: ended activity '%s'...", request); g_free(request); m_activityID = 0; } }
/** * @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; }
MojErr MojLunaService::sendImpl(MojServiceRequest* req, const MojChar* service, const MojChar* method, Token& tokenOut) { LOG_TRACE("Entering function %s", __FUNCTION__); MojAssert(req && service && method); MojAssert(m_service || m_handle); MojAssertMutexLocked(m_mutex); MojLunaRequest* lunaReq = static_cast<MojLunaRequest*>(req); const MojChar* json = lunaReq->payload(); LOG_DEBUG("[db_lunaService] request sent: %s", json); MojString uri; MojErr err = uri.format(_T("%s://%s/%s"), UriScheme, service, method); MojErrCheck(err); MojLunaErr lserr; LSMessageToken lsToken; LSHandle* handle = getHandle(lunaReq->onPublic()); if (req->numRepliesExpected() > 1) { if (!lunaReq->isProxyRequest()) { bool retVal = LSCall(handle, uri, json, &handleResponse, this, &lsToken, lserr); MojLsErrCheck(retVal, lserr); } else { bool retVal = LSCallFromApplication(handle, uri, json, lunaReq->getRequester(), &handleResponse, this, &lsToken, lserr); MojLsErrCheck(retVal, lserr); } } else { if (!lunaReq->isProxyRequest()) { bool retVal = LSCallOneReply(handle, uri, json, &handleResponse, this, &lsToken, lserr); MojLsErrCheck(retVal, lserr); } else { bool retVal = LSCallFromApplicationOneReply(handle, uri, json, lunaReq->getRequester(), &handleResponse, this, &lsToken, lserr); MojLsErrCheck(retVal, lserr); } } tokenOut = (Token) lsToken; return MojErrNone; }
static void SignalRegister(const char *signalName, LSFilterFunc callback, CBH *helper) { bool retVal; LSError lserror; LSErrorInit(&lserror); char *payload = g_strdup_printf( "{\"category\":\"/com/palm/power\",\"method\":\"%s\"}", signalName); retVal = LSCall(gServiceHandle, "luna://com.palm.lunabus/signal/addmatch", payload, callback, helper, &helper->token, &lserror); if (!retVal) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } g_free(payload); }
bool Preferences::setStringPreference(const char * keyName, const char * value) { pbnjson::JValue pref = pbnjson::Object(); pref.put(keyName, value); LSError error; LSErrorInit(&error); std::string valueStr = jsonToString(pref); //g_debug("Preferences::setStringPreference: '%s' = '%s'", keyName, valueStr.c_str()); bool ret = LSCall(Preferences::instance()->m_lsHandle, "palm://com.palm.systemservice/setPreferences", valueStr.c_str(), NULL, NULL, NULL, &error); if (!ret) { g_warning("%s: Failed setting '%s' to '%s' (%s)", __FUNCTION__, keyName, value, error.message); LSErrorFree(&error); return false; } return true; }
bool Preferences::setMuteSoundPref(bool mute) { m_muteOn = mute; pbnjson::JValue pref = pbnjson::Object(); pref.put("muteSound", m_muteOn); LSError error; LSErrorInit(&error); std::string valueStr = jsonToString(pref); bool ret = LSCall(Preferences::instance()->m_lsHandle, "palm://com.palm.systemservice/setPreferences", valueStr.c_str(), NULL, NULL, NULL, &error); if (!ret) { g_warning("%s: Failed setting 'muteSound' to '%d' (%s)", __FUNCTION__, m_muteOn, error.message); LSErrorFree(&error); return false; } return true; }
bool Preferences::saveBluetoothState(bool on) { m_bluetoothOn = on; pbnjson::JValue pref = pbnjson::Object(); pref.put("bluetoothRadio", m_bluetoothOn); LSError error; LSErrorInit(&error); std::string valueStr = jsonToString(pref); bool ret = LSCall(Preferences::instance()->m_lsHandle, "palm://com.palm.systemservice/setPreferences", valueStr.c_str(), NULL, NULL, NULL, &error); if (!ret) { g_warning("%s: Failed setting 'wifiRadio' to '%d' (%s)", __FUNCTION__, m_bluetoothOn, error.message); LSErrorFree(&error); return false; } return true; }
bool Preferences::setRotationLockPref(OrientationEvent::Orientation lockedOrientation) { m_rotationLock = lockedOrientation; pbnjson::JValue pref = pbnjson::Object(); pref.put("rotationLock", (int)m_rotationLock); LSError error; LSErrorInit(&error); std::string valueStr = jsonToString(pref); bool ret = LSCall(Preferences::instance()->m_lsHandle, "palm://com.palm.systemservice/setPreferences", valueStr.c_str(), NULL, NULL, NULL, &error); if (!ret) { g_warning("%s: Failed setting 'rotationLock' to '%d' (%s)", __FUNCTION__, m_rotationLock, error.message); LSErrorFree(&error); return false; } return true; }