bool service_register(const char *name) { bool rc; LSError err; LSErrorInit(&err); loop = g_main_loop_new(NULL, FALSE); if(loop == NULL) goto end; rc = LSRegisterPalmService(name, &handle, &err); if(rc) { pub = LSPalmServiceGetPublicConnection(handle); prv = LSPalmServiceGetPrivateConnection(handle); } else goto end; rc = LSPalmServiceRegisterCategory(handle, "/", methods, NULL, NULL, NULL, &err); LSGmainAttachPalmService(handle, loop, &err); if(!rc) goto end; end: if(LSErrorIsSet(&err)) { LSErrorPrint(&err, stderr); LSErrorFree(&err); puts("servece startup error..."); } return rc; }
MojErr MojLunaService::open(const MojChar* serviceName) { LOG_TRACE("Entering function %s", __FUNCTION__); MojErr err = MojService::open(serviceName); MojErrCheck(err); bool retVal; MojLunaErr lserr; // create service handle if (m_allowPublicMethods) { retVal = LSRegisterPalmService(serviceName, &m_service, lserr); MojLsErrCheck(retVal, lserr); LSHandle* handle = LSPalmServiceGetPublicConnection(m_service); retVal = LSSubscriptionSetCancelFunction(handle, handleCancel, this, lserr); MojLsErrCheck(retVal, lserr); handle = LSPalmServiceGetPrivateConnection(m_service); retVal = LSSubscriptionSetCancelFunction(handle, handleCancel, this, lserr); MojLsErrCheck(retVal, lserr); } else { retVal = LSRegister(serviceName, &m_handle, lserr); MojLsErrCheck(retVal, lserr); retVal = LSSubscriptionSetCancelFunction(m_handle, handleCancel, this, lserr); MojLsErrCheck(retVal, lserr); } return MojErrNone; }
bool luna_service_initialize(const char *dbusAddress) { bool returnVal = FALSE; LSError lserror; LSErrorInit(&lserror); loop = g_main_loop_new(NULL, FALSE); if (loop==NULL) goto end; returnVal = LSRegisterPalmService(dbusAddress, &serviceHandle, &lserror); if (returnVal) { pub_serviceHandle = LSPalmServiceGetPublicConnection(serviceHandle); priv_serviceHandle = LSPalmServiceGetPrivateConnection(serviceHandle); } else goto end; returnVal = register_methods(serviceHandle, lserror); if (returnVal) { LSGmainAttachPalmService(serviceHandle, loop, &lserror); } end: if (LSErrorIsSet(&lserror)) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } return returnVal; }
void InputManager::startService() { LSError lserror; LSErrorInit(&lserror); bool result; GMainLoop* mainLoop = HostBase::instance()->mainLoop(); g_debug ("%s starting", __PRETTY_FUNCTION__); result = LSRegisterPalmService(LUNA_KEYS, &m_palmService, &lserror); if (!result) goto Error; // Save off public and private bus handles m_publicService = LSPalmServiceGetPublicConnection(m_palmService); if (NULL == m_publicService) { g_message("unable to get public handle"); } m_service = LSPalmServiceGetPrivateConnection(m_palmService); if (NULL == m_service) { g_message("unable to get private handle"); } // We're providing the notion of "key categories" that you can // subscribe to in order to get notifications when a key is pressed result = LSPalmServiceRegisterCategory(m_palmService, CATEGORY_AUDIO, s_audioMethods, NULL, NULL, this, &lserror); if (!result) goto Error; // For now the media keys are the only ones that have been requested // to be put on the public bus -- the calling syntax is a little // strange, but when using this call everything on the public bus // is also put on the private bus result = LSPalmServiceRegisterCategory(m_palmService, CATEGORY_MEDIA, s_mediaMethods, NULL, NULL, this, &lserror); if (!result) goto Error; result = LSPalmServiceRegisterCategory(m_palmService, CATEGORY_SWITCHES, s_switchesMethods, NULL, NULL, this, &lserror); if (!result) goto Error; result = LSPalmServiceRegisterCategory(m_palmService, CATEGORY_HEADSET, s_headsetMethods, NULL, NULL, this, &lserror); if (!result) goto Error; result = LSGmainAttachPalmService(m_palmService, mainLoop, &lserror); if (!result) goto Error; g_debug ("%s service started", LUNA_KEYS); return; Error: if (LSErrorIsSet(&lserror)) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } g_debug(":%s: Unable to start service", __PRETTY_FUNCTION__); }
bool ImageServices::init(MainLoopProvider * p) { if (p == NULL) return false; //grab the main loop ptr from the provider m_p_mainloop = p->getMainLoopPtr(); if (m_p_mainloop == NULL) return false; //register the service LSError lsError; bool result; LSErrorInit(&lsError); // Register the service result = LSRegisterPalmService("com.palm.image", &m_service, &lsError); if (!result) { g_warning("Failed to register service: com.palm.image"); return false; } m_serviceHandlePublic = LSPalmServiceGetPublicConnection(m_service); m_serviceHandlePrivate = LSPalmServiceGetPrivateConnection(m_service); result = LSGmainAttachPalmService(m_service, m_p_mainloop, &lsError); if (!result) { g_warning("Failed to attach service handle to main loop"); LSErrorFree(&lsError); LSErrorInit(&lsError); result = LSUnregisterPalmService(m_service,&lsError); if (!result) LSErrorFree(&lsError); return false; } //register methods result = LSPalmServiceRegisterCategory( m_service, "/", s_methods_public, s_methods_private, NULL, this, &lsError); if (!result) { g_warning("Failed in registering handler methods on /: %s", lsError.message); LSErrorFree(&lsError); result = LSUnregisterPalmService(m_service,&lsError); if (!result) LSErrorFree(&lsError); return false; } return true; }
LSHandle* MojLunaService::getHandle(bool onPublic) { LSHandle* handle; if (m_service) { if (onPublic) { handle = LSPalmServiceGetPublicConnection(m_service); } else { handle = LSPalmServiceGetPrivateConnection(m_service); } } else { handle = m_handle; } return handle; }
/** * @brief Post a notification to all subscribers with name 'key'. * * This is equivalent to: * LSSubscriptionReply(public_bus, ...) * LSSubscriptionReply(private_bus, ...) * * @param psh * @param key * @param payload * @param lserror * * @retval */ bool LSSubscriptionRespond(LSPalmService *psh, const char *key, const char *payload, LSError *lserror) { LSHandle *public_bus = LSPalmServiceGetPublicConnection(psh); LSHandle *private_bus = LSPalmServiceGetPrivateConnection(psh); bool retVal; retVal = LSSubscriptionReply(public_bus, key, payload, lserror); if (!retVal) return retVal; retVal = LSSubscriptionReply(private_bus, key, payload, lserror); if (!retVal) return retVal; return true; }
void TimeZoneService::setServiceHandle(LSPalmService* service) { m_service = service; LSError lsError; LSErrorInit(&lsError); bool result = LSPalmServiceRegisterCategory(m_service, "/timezone", s_methods, NULL, NULL, this, &lsError); if (!result) { g_critical("Failed in registering timezone handler method: %s", lsError.message); LSErrorFree(&lsError); return; } m_serviceHandlePublic = LSPalmServiceGetPublicConnection(m_service); m_serviceHandlePrivate = LSPalmServiceGetPrivateConnection(m_service); }
int main(int argc, char **argv) { bool retVal; int opt; bool invertCarrier = false; LSPalmService * lsps = NULL; while ((opt = getopt(argc, argv, "chdst")) != -1) { switch (opt) { case 'c': invertCarrier = true; break; case 'd': setLogLevel(G_LOG_LEVEL_DEBUG); break; case 's': setUseSyslog(true); break; case 'h': default: PrintUsage(argv[0]); return EXIT_SUCCESS; } } // make sure we aren't already running. if (!LockProcess("storaged")) { g_error("%s: %s daemon is already running.\n", __func__, argv[0]); exit(EXIT_FAILURE); } g_log_set_default_handler(logFilter, NULL); g_debug( "entering %s in %s", __func__, __FILE__ ); signal(SIGTERM, term_handler); g_mainloop = g_main_loop_new(NULL, FALSE); int ret = nyx_device_open(NYX_DEVICE_SYSTEM, "Main", &nyxSystem); if(ret != NYX_ERROR_NONE) { g_critical("Unable to open the nyx device system"); abort(); } else g_debug("Initialized nyx system device"); /** * initialize the lunaservice and we want it before all the init * stuff happening. */ LSError lserror; LSErrorInit(&lserror); retVal = LSRegisterPalmService("com.palm.storage", &lsps, &lserror); if (!retVal) { g_critical ("failed in function %s with erro %s", lserror.func, lserror.message); LSErrorFree(&lserror); return EXIT_FAILURE; } SignalsInit( lsps ); LSHandle *lsh_priv = LSPalmServiceGetPrivateConnection(lsps); LSHandle *lsh_pub = LSPalmServiceGetPublicConnection(lsps); DiskModeInterfaceInit( g_mainloop, lsh_priv, lsh_pub, invertCarrier ); EraseInit(g_mainloop, lsh_priv); retVal = LSGmainAttach( lsh_priv, g_mainloop, &lserror ); if ( !retVal ) { g_critical( "LSGmainAttach private returned %s", lserror.message ); LSErrorFree(&lserror); } retVal = LSGmainAttach( lsh_pub, g_mainloop, &lserror ); if ( !retVal ) { g_critical( "LSGmainAttach public returned %s", lserror.message ); LSErrorFree(&lserror); } g_main_loop_run(g_mainloop); g_main_loop_unref(g_mainloop); if (!LSUnregister( lsh_priv, &lserror)) { g_critical( "LSUnregister private returned %s", lserror.message ); } if (!LSUnregister( lsh_pub, &lserror)) { g_critical( "LSUnregister public returned %s", lserror.message ); } UnlockProcess(); g_debug( "exiting %s in %s", __func__, __FILE__ ); if (!retVal) return EXIT_FAILURE; else return EXIT_SUCCESS; }