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; }
/** * Destructor: Stop anything we have going & disconnect proxy listener */ SoundPlayer::~SoundPlayer() { PRINTF_BLUE("SoundPlayer::~SoundPlayer(%s)", getStateName()); if (m_state == eState_PlayPending || m_state == eState_Playing) stop(); if (m_player.get()) { m_player->removeMediaPlayerChangeListener(m_mediaPlayerChangeListener); m_player.reset((media::MediaPlayer*) 0); } // Important: Make sure to call this before the service handle destuction if (m_mediaPlayerChangeListener.get()) m_mediaPlayerChangeListener.reset((media::MediaPlayerChangeListener*)0); if (m_serviceHandle) { LSError lserror; LSErrorInit(&lserror); if (!LSUnregisterPalmService(m_serviceHandle, &lserror)) { LSErrorPrint (&lserror, stderr); LSErrorFree (&lserror); } m_serviceHandle = 0; } }
bool SysmgrDebuggerService::shutdown() { LSError lserror; LSErrorInit(&lserror); bool result; result = LSUnregisterPalmService(m_p_service, &lserror); if (!result) { qWarning() << __FUNCTION__ << " failed - the service handle may have just been leaked" ; LSErrorFree(&lserror); } m_p_service = 0; return result; }
int main(int argc, char **argv) { LSError lserror; g_type_init(); g_log_set_handler (NULL, G_LOG_LEVEL_MASK, log_handler, NULL); signal(SIGTERM, signal_term_handler); signal(SIGINT, signal_term_handler); mainloop = g_main_loop_new(NULL, FALSE); LSErrorInit(&lserror); if (!LSRegisterPalmService("org.webosinternals.service.update", &palm_service_handle, &lserror)) { g_error("Failed to initialize the Luna Palm service: %s", lserror.message); LSErrorFree(&lserror); goto cleanup; } if (!LSGmainAttachPalmService(palm_service_handle, mainloop, &lserror)) { g_error("Failed to attach to glib mainloop for palm service: %s", lserror.message); LSErrorFree(&lserror); goto cleanup; } private_service_handle = LSPalmServiceGetPrivateConnection(palm_service_handle); initialize_luna_service(); g_main_loop_run(mainloop); cleanup: shutdown_luna_service(); if (palm_service_handle != NULL && LSUnregisterPalmService(palm_service_handle, &lserror) < 0) { g_error("Could not unregister palm service: %s", lserror.message); LSErrorFree(&lserror); } g_source_remove(signal); g_main_loop_unref(mainloop); return 0; }
MojErr MojLunaService::close() { LOG_TRACE("Entering function %s", __FUNCTION__); MojErr err = MojErrNone; MojErr errClose = MojService::close(); MojErrAccumulate(err, errClose); // destroy service handle MojLunaErr lserr; bool retVal; if (m_service) { retVal = LSUnregisterPalmService(m_service, lserr); m_service = NULL; m_handle = NULL; MojLsErrAccumulate(err, retVal, lserr); } else if (m_handle) { retVal = LSUnregister(m_handle, lserr); m_handle = NULL; MojLsErrAccumulate(err, retVal, lserr); } return err; }
int main(int argc, char **argv) { GOptionContext *context; LSError lserror; GError *err = NULL; guint signal; struct telephony_service *service; g_message("Telephony Interface Layer Daemon %s", VERSION); g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, debug_handler, NULL); context = g_option_context_new(NULL); g_option_context_add_main_entries(context, options, NULL); if (g_option_context_parse(context, &argc, &argv, &err) == FALSE) { if (err != NULL) { g_printerr("%s\n", err->message); g_error_free(err); exit(1); } g_printerr("An unknown error occurred\n"); exit(1); } g_option_context_free(context); if (option_version == TRUE) { printf("%s\n", VERSION); exit(0); } if (option_detach == TRUE) { if (daemon(0, 0)) { perror("Can't start daemon"); return 1; } } signal = setup_signalfd(); event_loop = g_main_loop_new(NULL, FALSE); LSErrorInit(&lserror); if (!LSRegisterPalmService("com.palm.telephony", &palm_serivce_handle, &lserror)) { g_error("Failed to initialize the Luna Palm service: %s", lserror.message); LSErrorFree(&lserror); goto cleanup; } if (!LSGmainAttachPalmService(palm_serivce_handle, event_loop, &lserror)) { g_error("Failed to attach to glib mainloop for palm service: %s", lserror.message); LSErrorFree(&lserror); goto cleanup; } private_service_handle = LSPalmServiceGetPrivateConnection(palm_serivce_handle); service = telephony_service_create(palm_serivce_handle); /* FIXME this should be done as part of a plugin mechanism */ ofono_init(service); g_main_loop_run(event_loop); cleanup: /* FIXME this should be done as part of a plugin mechanism */ ofono_exit(service); telephony_service_free(service); if (palm_serivce_handle != NULL && LSUnregisterPalmService(palm_serivce_handle, &lserror) < 0) { g_error("Could not unregister palm service: %s", lserror.message); LSErrorFree(&lserror); } g_source_remove(signal); g_main_loop_unref(event_loop); return 0; }