static int shutdown_init(void) { sClientList = g_new0(ShutdownClientList, 1); sClientList->applications = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, (GDestroyNotify)client_free); sClientList->services = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, (GDestroyNotify)client_free); sClientList->num_ack = 0; sClientList->num_nack = 0; shutdown_timer = g_timer_new(); gCurrentState = &kStateMachine[kPowerShutdownNone]; LSError lserror; LSErrorInit(&lserror); if (!LSRegisterCategory(GetLunaServiceHandle(), "/shutdown", shutdown_methods, shutdown_signals, NULL, &lserror)) { goto error; } return 0; error: LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); return -1; }
static int _power_timeout_init(void) { /* Set up luna service */ psh = GetPalmService(); LSError lserror; LSErrorInit(&lserror); if (!LSPalmServiceRegisterCategory(psh, "/timeout", timeout_methods /*public*/, NULL /*private*/, NULL, NULL, &lserror)) { POWERDLOG(LOG_ERR, "%s could not register category: %s", __FUNCTION__, lserror.message); LSErrorFree(&lserror); goto error; } if (!LSRegisterCategory(GetLunaServiceHandle(), "/time", time_methods, NULL, NULL, &lserror)) { goto error; } UEventListen("/com/palm/powerd/timechange/uevent", _timechange_callback); return 0; error: return -1; }
void BootManager::startService() { bool result; LSError error; LSErrorInit(&error); GMainLoop *mainLoop = HostBase::instance()->mainLoop(); g_message("BootManager starting..."); if (!LSRegister("org.webosports.bootmgr", &m_service, &error)) { g_warning("Failed in BootManager: %s", error.message); LSErrorFree(&error); return; } if (!LSRegisterCategory(m_service, "/", s_methods, NULL, NULL, &error)) { g_warning("Failed in BootManager: %s", error.message); LSErrorFree(&error); return; } if (!LSGmainAttach(m_service, mainLoop, &error)) { g_warning("Failed in BootManager: %s", error.message); LSErrorFree(&error); return; } if (!LSRegisterServerStatus(m_service, "org.webosports.luna", cbCompositorAvailable, NULL, &error)) { g_warning("Failed to register for compositor status"); LSErrorFree(&error); } }
int main(void) { GMainLoop *mainLoop = g_main_loop_new(NULL, FALSE); void *userData = mainLoop; g_timeout_add(10000, &OnTimeout, mainLoop); GThread *client_thread = g_thread_new(NULL, ClientProc, mainLoop); /*! [service registration] */ bool retVal; LSError lserror; LSErrorInit(&lserror); LSHandle *serviceHandle = NULL; retVal = LSRegister("com.palm.contacts", &serviceHandle, &lserror); if (!retVal) goto error; retVal = LSRegisterCategory(serviceHandle, "/category", ipcMethods, NULL, NULL, &lserror); if (!retVal) goto error; retVal = LSCategorySetData(serviceHandle, "/category", userData, &lserror); if (!retVal) goto error; retVal = LSGmainAttach(serviceHandle, mainLoop, &lserror); if (!retVal) goto error; g_main_loop_run(mainLoop); /*! [service registration] */ LSUnregister(serviceHandle, &lserror); g_main_loop_unref(mainLoop); g_thread_join(client_thread); if (hit_reply) { printf("PASS\n"); return 0; } printf("FAILED\n"); return 1; error: LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); if (serviceHandle) LSUnregister(serviceHandle, &lserror); g_main_loop_unref(mainLoop); g_thread_join(client_thread); fprintf(stderr, "FAILED\n"); return 1; }
MojErr MojLunaService::addCategory(const MojChar* name, CategoryHandler* handler) { LOG_TRACE("Entering function %s", __FUNCTION__); MojAssert(name && handler); MojAssertMutexUnlocked(m_mutex); MojThreadGuard guard(m_mutex); // create array of LSMethods MethodVec pubMethods; MethodVec privMethods; const CategoryHandler::CallbackMap& callbacks = handler->callbacks(); for (CategoryHandler::CallbackMap::ConstIterator i = callbacks.begin(); i != callbacks.end(); i++) { LSMethod m = {i.key(), &handleRequest}; MethodVec& methods = i->m_pub ? pubMethods : privMethods; MojErr err = methods.push(m); MojErrCheck(err); } LSMethod nullMethod = {NULL, NULL}; MojErr err = pubMethods.push(nullMethod); MojErrCheck(err); err = privMethods.push(nullMethod); MojErrCheck(err); // create category object to hang on to method array MojRefCountedPtr<LunaCategory> cat(new LunaCategory(this, handler, pubMethods, privMethods)); MojAllocCheck(cat.get()); LSMethod* pubLsMethods = const_cast<LSMethod*>(cat->m_pubMethods.begin()); LSMethod* privLsMethods = const_cast<LSMethod*>(cat->m_privMethods.begin()); MojLunaErr lserr; bool retVal; if (m_service) { retVal = LSPalmServiceRegisterCategory(m_service, name, pubLsMethods, privLsMethods, NULL, cat.get(), lserr); MojLsErrCheck(retVal, lserr); } else { MojAssert(m_handle); retVal = LSRegisterCategory(m_handle, name, privLsMethods, NULL, NULL, lserr); MojLsErrCheck(retVal, lserr); retVal = LSCategorySetData(m_handle, name, cat.get(), lserr); MojLsErrCheck(retVal, lserr); } MojString categoryStr; err = categoryStr.assign(name); MojErrCheck(err); err = m_categories.put(categoryStr, cat); MojErrCheck(err); return MojErrNone; }
struct property_service* property_service_create() { struct property_service *service; LSError error; service = g_try_new0(struct property_service, 1); if (!service) return NULL; LSErrorInit(&error); if (!LSRegisterPubPriv("com.android.properties", &service->handle, false, &error)) { g_error("Failed to register the luna service: %s", error.message); LSErrorFree(&error); goto error; } if (!LSRegisterCategory(service->handle, "/", property_service_methods, NULL, NULL, &error)) { g_error("Could not register service category: %s", error.message); LSErrorFree(&error); goto error; } if (!LSCategorySetData(service->handle, "/", service, &error)) { g_error("Could not set daa for service category: %s", error.message); LSErrorFree(&error); goto error; } if (!LSGmainAttach(service->handle, event_loop, &error)) { g_error("Could not attach service handle to mainloop: %s", error.message); LSErrorFree(&error); goto error; } return service; error: if (service->handle != NULL) { LSUnregister(service->handle, &error); LSErrorFree(&error); } g_free(service); return NULL; }
void Handle::registerCategory(const char *category, const LSMethod *methods, const LSSignal *signals, const LSProperty *properties) { Error error; if (!LSRegisterCategory(_handle, category, const_cast<LSMethod *>(methods), const_cast<LSSignal *>(signals), const_cast<LSProperty *>(properties), error.get())) { throw error; } }
/** * EraseInit * * @brief Register storaged with luna-service as implementer of several * methods. */ int EraseInit(GMainLoop *loop, LSHandle* handle) { LSError lserror; LSErrorInit(&lserror); if ( !LSRegisterCategory ( handle, "/erase", erase_mthds, NULL, NULL, &lserror) ) { LSREPORT( lserror ); } LSErrorFree( &lserror ); nyxSystem = GetNyxSystemDevice(); return 0; }
static int shutdown_init(void) { LSError lserror; LSErrorInit(&lserror); if (!LSRegisterCategory(GetLunaServiceHandle(), "/shutdown", shutdown_methods, NULL, NULL, &lserror)) { goto error; } return 0; error: LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); return -1; }
/** * @brief Init registers with bus and udev. * */ int alarm_init(void) { LSError lserror; LSErrorInit(&lserror); if (!LSRegisterCategory(GetLunaServiceHandle(), "/time", time_methods, NULL, NULL, &lserror)) { goto error; } alarm_queue_create(); alarm_read_db(); update_alarms(); return 0; error: return -1; }
int initialize_connectionmanager_ls2_calls( GMainLoop *mainloop ) { LSError lserror; LSErrorInit (&lserror); pLsHandle = NULL; pLsPublicHandle = NULL; if(NULL == mainloop) goto Exit; if (LSRegisterPubPriv(CONNECTIONMANAGER_LUNA_SERVICE_NAME, &pLsHandle, false, &lserror) == false) { WCA_LOG_FATAL("LSRegister() private returned error"); goto Exit; } if (LSRegisterPubPriv(CONNECTIONMANAGER_LUNA_SERVICE_NAME, &pLsPublicHandle, true, &lserror) == false) { WCA_LOG_FATAL("LSRegister() public returned error"); goto Exit; } if (LSRegisterCategory(pLsHandle, NULL, connectionmanager_methods, NULL, NULL, &lserror) == false) { WCA_LOG_FATAL("LSRegisterCategory() returned error"); goto Exit; } if (LSGmainAttach(pLsHandle, mainloop, &lserror) == false) { WCA_LOG_FATAL("LSGmainAttach() private returned error"); goto Exit; } if (LSGmainAttach(pLsPublicHandle, mainloop, &lserror) == false) { WCA_LOG_FATAL("LSGmainAttach() public returned error"); goto Exit; } /* Register for Wired technology's "PropertyChanged" signal (For wifi its being done in wifi_service.c*/ connman_technology_t *technology = connman_manager_find_ethernet_technology(manager); if(technology) { connman_technology_register_property_changed_cb(technology, technology_property_changed_callback); } return 0; Exit: if (LSErrorIsSet(&lserror)) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } if (pLsHandle) { LSErrorInit (&lserror); if(LSUnregister(pLsHandle, &lserror) == false) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } } if (pLsPublicHandle) { LSErrorInit (&lserror); if(LSUnregister(pLsPublicHandle, &lserror) == false) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } } return -1; }
AmbientLightSensor::AmbientLightSensor () : m_service(NULL) , m_alsEnabled(false) , m_alsIsOn(false) , m_alsPointer(0) , m_alsRegion(ALS_REGION_UNDEFINED) , m_alsSum(0) , m_alsLastOff(0) , m_alsDisplayOn(false) , m_alsSubscriptions(0) , m_alsDisabled(0) , m_alsHiddOnline(false) , m_alsFastRate(false) , m_alsSampleCount(0) , m_alsCountInRegion(0) , m_alsSamplesNeeded (ALS_INIT_SAMPLE_SIZE) , m_alsLastSampleTs (0) { LSError lserror; LSErrorInit(&lserror); bool result; GMainLoop* mainLoop = HostBase::instance()->mainLoop(); result = LSRegister(AMBIENT_LIGHT_SENSOR_ID, &m_service, &lserror); if (!result) { LSErrorPrint (&lserror, stderr); LSErrorFree(&lserror); } result = LSRegisterCategory (m_service, "/control", alsMethods, NULL, NULL, &lserror); if (!result) { LSErrorPrint (&lserror, stderr); LSErrorFree(&lserror); } result = LSCategorySetData (m_service, "/control", this, &lserror); if (!result) { LSErrorPrint (&lserror, stderr); LSErrorFree(&lserror); } result = LSSubscriptionSetCancelFunction(m_service, AmbientLightSensor::cancelSubscription, this, &lserror); if (!result) { LSErrorPrint (&lserror, stderr); LSErrorFree (&lserror); } result = LSGmainAttach(m_service, mainLoop, &lserror); if (!result) { LSErrorPrint (&lserror, stderr); LSErrorFree(&lserror); } result = LSRegisterServerStatus(m_service, "com.palm.hidd", AmbientLightSensor::hiddServiceNotification, this, &lserror); if (!result) { LSErrorPrint (&lserror, stderr); LSErrorFree (&lserror); } #if defined (MACHINE_CASTLE) m_alsEnabled = true; m_alsBorder[0] = 10 * ALS_SAMPLE_SIZE; m_alsBorder[1] = 200 * ALS_SAMPLE_SIZE; m_alsMargin[0] = 2 * ALS_SAMPLE_SIZE; m_alsMargin[1] = (m_alsBorder[1] / 10) > (ALS_SAMPLE_SIZE * 2) ? m_alsBorder[1] / 10 : ALS_SAMPLE_SIZE * 2; #else if (Settings::LunaSettings()->enableAls) { m_alsEnabled = true; g_warning ("ALSCal token found, expecting lux values in light events"); m_alsBorder[ALS_REGION_UNDEFINED] = -1; m_alsBorder[ALS_REGION_DARK] = 6; m_alsBorder[ALS_REGION_DIM] = 100; m_alsBorder[ALS_REGION_INDOOR] = 1000; m_alsBorder[ALS_REGION_OUTDOOR] = INT_MAX; // margins are higher at lower lux values m_alsMargin[ALS_REGION_UNDEFINED] = 0; m_alsMargin[ALS_REGION_DARK] = 4; m_alsMargin[ALS_REGION_DIM] = 10; m_alsMargin[ALS_REGION_INDOOR] = 100; m_alsMargin[ALS_REGION_OUTDOOR] = 0; } else { g_warning ("%s: ALS is not enabled", __PRETTY_FUNCTION__); } #endif m_instance = this; g_debug ("%s started", __PRETTY_FUNCTION__); }
struct audio_service* audio_service_create() { struct audio_service *service; LSError error; pa_mainloop_api *mainloop_api; char name[100]; service = g_try_new0(struct audio_service, 1); if (!service) return NULL; LSErrorInit(&error); if (!LSRegisterPubPriv("org.webosports.audio", &service->handle, false, &error)) { g_warning("Failed to register the luna service: %s", error.message); LSErrorFree(&error); goto error; } if (!LSRegisterCategory(service->handle, "/", audio_service_methods, NULL, NULL, &error)) { g_warning("Could not register service category: %s", error.message); LSErrorFree(&error); goto error; } if (!LSCategorySetData(service->handle, "/", service, &error)) { g_warning("Could not set daa for service category: %s", error.message); LSErrorFree(&error); goto error; } if (!LSGmainAttach(service->handle, event_loop, &error)) { g_warning("Could not attach service handle to mainloop: %s", error.message); LSErrorFree(&error); goto error; } service->pa_mainloop = pa_glib_mainloop_new(g_main_context_default()); mainloop_api = pa_glib_mainloop_get_api(service->pa_mainloop); snprintf(name, 100, "AudioServiceContext:%i", getpid()); service->context = pa_context_new(mainloop_api, name); service->context_initialized = false; pa_context_set_state_callback(service->context, context_state_cb, service); if (pa_context_connect(service->context, NULL, 0, NULL) < 0) { g_warning("Failed to connect to PulseAudio"); pa_context_unref(service->context); pa_glib_mainloop_free(service->pa_mainloop); goto error; } sample_list = g_slist_alloc(); return service; error: if (service->handle != NULL) { LSUnregister(service->handle, &error); LSErrorFree(&error); } g_free(service); return NULL; }