1 // Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <ArgvKeeper.hxx>
24 #include <Container_init_python.hxx> // this include must be the first one as it includes Python.h
25 #include <Basics_Utils.hxx>
27 #include <RegistryService.hxx>
28 #include <SALOME_LifeCycleCORBA.hxx>
29 #include <SALOME_ModuleCatalog_impl.hxx>
30 #include <SALOME_NamingService.hxx>
31 #include <Utils_CorbaException.hxx>
32 #include <Utils_ORB_INIT.hxx>
33 #include <Utils_SALOME_Exception.hxx>
34 #include <Utils_SINGLETON.hxx>
35 #include <utilities.h>
36 #include "KernelBasis.hxx"
38 #include "Session_Session_i.hxx"
39 #include "Session_ServerCheck.hxx"
40 #include "Session_ServerLauncher.hxx"
41 #include "Session_Promises.hxx"
42 #include "Session_NS_wrapper.hxx"
44 #include "GUI_version.h"
46 #include "QtxMsgHandler.h"
47 #include "QtxSplash.h"
48 #include "SALOME_Event.h"
49 #ifdef USE_SALOME_STYLE
50 #include "Style_Salome.h"
51 #endif // USE_SALOME_STYLE
52 #include "SUIT_Application.h"
53 #include "SUIT_Desktop.h"
54 #include "SUIT_ExceptionHandler.h"
55 #include "SUIT_ResourceMgr.h"
56 #include "SUIT_Session.h"
57 #include "SUIT_Tools.h"
59 #include <SALOMEconfig.h>
60 #include CORBA_SERVER_HEADER(SALOME_Session)
61 #include CORBA_SERVER_HEADER(SALOMEDS)
72 #include <QApplication>
77 #include <QTextStream>
78 #include <QWaitCondition>
82 // For DWORD (see end of file)
84 // Force high-performance graphics on dual-GPU systems
85 // http://developer.download.nvidia.com/devzone/devcenter/gamegraphics/files/OptimusRenderingPolicies.pdf
86 __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
87 // https://community.amd.com/thread/169965
88 __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
92 //! CORBA server for SALOME GUI session
94 * SALOME_Session_Server launches a SALOME session servant.
95 * The servant registers to the Naming Service.
96 * See SALOME_Session.idl for interface specification.
97 * Main services offered by the servant are:
99 * - stop Session ( must be idle )
100 * - get session state
102 * Also, session server:
104 * - defines list of embedded services to launch with their arguments,
105 * - defines list of standalone services to connect/wait,
106 * - waits for naming service to finish its initalization,
107 * - creates and runs a separate thread to launch/initialize all services.
112 std::string handleCorbaException(const CORBA::Exception &e)
117 CORBA::TypeCode_var tc = tmp.type();
118 message += tc->name();
122 //! Custom handler to manage Qt messages
123 class MsgHandler : public QtxMsgHandlerCallback
127 void qtMessage(QtMsgType type, const QMessageLogContext & /*context*/, const QString &message)
129 (void)message; // unused in debug mode
133 #ifdef QT_DEBUG_MESSAGE
134 MESSAGE("Debug: " << qPrintable(message));
138 MESSAGE("Warning: " << qPrintable(message));
141 MESSAGE("Critical: " << qPrintable(message));
144 MESSAGE("Fatal: " << qPrintable(message));
148 MESSAGE("Information: " << qPrintable(message));
154 //! Get version of SALOME GUI module
155 QString salomeVersion()
157 return GUI_VERSION_STR;
160 //! Custom resources manager, that allows customization of application name/version
161 // via configuration/translation files.
162 class ResourceMgr : public SUIT_ResourceMgr
165 ResourceMgr(const QString &appName = "SalomeApp") : SUIT_ResourceMgr(appName, "%1Config")
167 customize(); // activate customization
168 setCurrentFormat("xml");
169 setOption("translators", QString("%P_msg_%L.qm|%P_icons.qm|%P_images.qm"));
172 QString customName() const { return myCustomAppName; }
173 QString version() const { return myCustomAppVersion; }
176 static void customize()
178 // Try to retrieve actual application name and version from translation files.
179 // We create temporary resource manager and load LightApp and SalomeApp translations.
180 // This procedure is supposed to be done only once, at first call.
181 if (myCustomAppName.isNull())
183 SUIT_ResourceMgr mgr("SalomeApp", "%1Config");
184 mgr.setCurrentFormat("xml");
185 mgr.setWorkingMode(IgnoreUserValues); // prevent reading data from user's file
186 mgr.loadLanguage("LightApp", "en");
187 mgr.loadLanguage("SalomeApp", "en");
189 // actual application name can be customized via APP_NAME resource key
190 myCustomAppName = QObject::tr("APP_NAME").trimmed();
191 if (myCustomAppName == "APP_NAME" || myCustomAppName.toLower() == "salome")
192 myCustomAppName = "SalomeApp"; // fallback name
194 // actual application name can be customized via APP_VERSION resource key
195 myCustomAppVersion = QObject::tr("APP_VERSION").trimmed();
196 if (myCustomAppVersion == "APP_VERSION")
197 myCustomAppVersion = myCustomAppName == "SalomeApp" ? salomeVersion() : ""; // fallback version
202 QString userFileName(const QString & /*appName*/, const bool forLoad) const
204 if (version().isEmpty())
206 return SUIT_ResourceMgr::userFileName(myCustomAppName, forLoad);
209 virtual long userFileId(const QString &_fname) const
211 //////////////////////////////////////////////////////////////////////////////////////////////
212 // In SALOME and SALOME-based applications the user preferences file is named as
213 // - <AppName>.xml.<AppVersion> on Windows
214 // - <AppName>rc.<AppVersion> on Linux
216 // * AppName is application name, defaults to SalomeApp. Can be customized in SALOME-based
217 // applications, see ResourceMgr above for more details.
218 // * AppVersion is application version, defaults to current version of SALOME GUI module
219 // if AppName is not customize, otherwise empty. Can be customized in SALOME-based
220 // applications, see ResourceMgr above for more details.
222 // Since version 6.5.0 of SALOME, user file is stored in the ~/.config/salome
223 // directory. For backward compatibility, when user preferences from nearest
224 // version of application is searched, user home directory is also looked through,
225 // with lower priority.
227 // Since version 6.6.0 of SALOME, user file name on Linux is no more prefixed by dot
228 // symbol since it is stored in the hidden ~/.config/salome directory. However, dot-prefixed
229 // files are also taken into account (with lower priority) for backward compatibility.
232 // - Currently the following format of version number is supported:
233 // <major>[.<minor>[.<release>[<type><dev>]]]
234 // Parts in square brackets are considered optional. Here:
235 // * major - major version id
236 // * minor - minor version id
237 // * release - maintenance version id
238 // * type - dev or patch marker; it can be either one alphabetical symbol (from 'a' to 'z')
239 // or 'rc' to point release candidate (case-insensitive)
240 // * dev - dev version or patch number
241 // All numerical values must be of range [1-99].
242 // Examples: 1.0, 6.5.0, 1.2.0a1, 3.3.3rc3 (release candidate 3), 11.0.0p1 (patch 1)
244 // - Versioning approach can be customized by implementing and using own resource manager class,
245 // see QtxResurceMgr, SUIT_ResourceMgr classes, and ResourceMgr class above in this file.
246 //////////////////////////////////////////////////////////////////////////////////////////////
249 if (!myCustomAppName.isEmpty())
252 // On Windows, user file name is something like SalomeApp.xml.6.5.0 where
253 // - SalomeApp is an application name (can be customized)
254 // - xml is a file format (xml or ini)
255 // - 6.5.0 is an application version, can include alfa/beta/rc marks, e.g. 6.5.0a3, 6.5.0rc1
256 QRegExp exp(QString("%1\\.%2\\.([a-zA-Z0-9.]+)").arg(myCustomAppName).arg(currentFormat()));
258 // On Linux, user file name is something like SalomeApprc.6.5.0 where
259 // - SalomeApp is an application name (can be customized)
260 // - 6.5.0 is an application version, can include alfa/beta/rc marks, e.g. 6.5.0a3, 6.5.0rc1
262 // VSR 24/09/2012: issue 0021781: since version 6.6.0 user filename is not prepended with "."
263 // when it is stored in the ~/.config/<appname> directory;
264 // for backward compatibility we also check files prepended with "." with lower priority
265 QRegExp exp(QString("\\.?%1rc\\.([a-zA-Z0-9.]+)").arg(myCustomAppName));
267 QString fname = QFileInfo(_fname).fileName();
268 if (exp.exactMatch(fname))
270 long fid = Qtx::versionToId(exp.cap(1));
279 static QString myCustomAppName;
280 static QString myCustomAppVersion;
282 QString ResourceMgr::myCustomAppName;
283 QString ResourceMgr::myCustomAppVersion;
285 //! Custom session, to use custom resource manager class.
286 class Session : public SUIT_Session
289 virtual SUIT_ResourceMgr *createResourceMgr(const QString &appName) const
291 return new ResourceMgr(appName);
295 //! Custom QApplication class, redefines notify() method, to transfer all events
296 // via centralized exception handling mechanism.
297 class Application : public QApplication
300 Application(int &argc, char **argv)
301 : QApplication(argc, argv),
304 myDebug = !Qtx::getenv("SALOME_DEBUG_EXCEPTIONS").isEmpty();
307 virtual bool notify(QObject *receiver, QEvent *e)
309 if (myDebug || !myHandler)
311 return QApplication::notify(receiver, e);
317 return myHandler->handle(receiver, e);
319 catch (std::exception &e)
321 std::cerr << "notify(): Caught exception : " << e.what() << std::endl;
323 catch (CORBA::Exception &e)
325 std::cerr << "notify(): Caught CORBA exception : " << handleCorbaException(e) << std::endl;
329 std::cerr << "notify(): Caught unknown exception : there's probably a bug in SALOME platform" << std::endl;
331 return false; // return false when exception is caught
335 SUIT_ExceptionHandler *handler() const { return myHandler; }
336 void setHandler(SUIT_ExceptionHandler *h) { myHandler = h; }
339 SUIT_ExceptionHandler *myHandler;
343 //! Class which calls SALOME::Session::GetInterface() from another thread
344 // to avoid mutual lock if called from the same thread as main()
345 class GetInterfaceThread : public QThread
348 GetInterfaceThread(SALOME::Session_var s) : session(s)
356 if (!CORBA::is_nil(session))
357 session->GetInterface();
359 std::cerr << "FATAL ERROR: SALOME::Session object is nil! Cannot display GUI" << std::endl;
363 SALOME::Session_var session;
366 //! Checks command line for presense of given option(s).
367 // Option that results to \c true is specified via \a trueOption parameter.
368 // Option that results to \c false is specified via \a falseOption parameter (empty for default).
369 // Default value for the result (returned if both \a trueOption \a falseOption are not given) is specified via \c defValue parameter.
370 bool boolCmdOption(const QString trueOption, const QString falseOption = QString(), bool defValue = false)
372 bool value = defValue;
374 QStringList args = QApplication::arguments();
375 foreach (QString arg, args)
377 if (arg == trueOption)
379 else if (arg == falseOption)
385 // Shutdown standalone servers
386 void shutdownServers(SALOME_NamingService *theNS, bool remoteLauncher)
388 SALOME_LifeCycleCORBA lcc(theNS);
389 lcc.shutdownServers(!remoteLauncher);
391 } // end of anonymous namespace
393 template<class GUI_APP_STYLE>
394 int AbstractGUIAppMain(int argc, char **argv);
399 static constexpr bool SSL_MODE = false;
400 using NamingServiceImplementation = OldStyleNS;
401 void connectToNSIfNeeded(CORBA::ORB_ptr orb) { _NS.reset(new SALOME_NamingService(orb)); }
402 void shutdownCORBAStufIfNeeded(bool shutdownAll, CORBA::ORB_ptr orb);
403 void killOtherServersIfNeeded() { SALOME_LifeCycleCORBA::killOmniNames(); }
404 SALOME::Session_var getSession();
405 void shutdownRemoteServersIfNeeded(bool remoteLauncher);
407 std::unique_ptr<SALOME_NamingService> _NS;
413 static constexpr bool SSL_MODE = true;
414 using NamingServiceImplementation = NewStyleNS;
415 void connectToNSIfNeeded(CORBA::ORB_ptr orb) { /*! nothing */ }
416 void shutdownCORBAStufIfNeeded(bool shutdownAll, CORBA::ORB_ptr orb) { /*! nothing */ }
417 void killOtherServersIfNeeded() { /*! nothing */ }
418 SALOME::Session_var getSession();
419 void shutdownRemoteServersIfNeeded(bool remoteLauncher) { /*! nothing */ }
422 void GUIAppOldStyle::shutdownCORBAStufIfNeeded(bool shutdownAll, CORBA::ORB_ptr orb)
430 //////////////////////////////////////////////////////////////
431 // VSR: silently skip exception:
432 // CORBA.BAD_INV_ORDER.BAD_INV_ORDER_ORBHasShutdown
433 // exception is raised when orb->destroy() is called and
434 // cpp continer is launched in the embedded mode
435 //////////////////////////////////////////////////////////////
437 SALOME_LifeCycleCORBA::killOmniNames();
438 abort(); //abort program to avoid deadlock in destructors or atexit when shutdown has been interrupted
442 ORB_INIT *init = SINGLETON_<ORB_INIT>::Instance();
444 init->explicit_destroy();
447 SALOME::Session_var GUIAppOldStyle::getSession()
449 CORBA::Object_var obj = _NS->Resolve("/Kernel/Session");
450 SALOME::Session_var session = SALOME::Session::_narrow(obj);
453 void GUIAppOldStyle::shutdownRemoteServersIfNeeded(bool remoteLauncher)
455 shutdownServers(_NS.get(), remoteLauncher);
458 SALOME::Session_var GUIAppNewStyle::getSession()
460 SALOME::Session_var session = GetSessionRefSingleton()->get_future().get();
464 // ---------------------------- MAIN -----------------------
465 template<class GUI_APP_STYLE>
466 int AbstractGUIAppMain(int argc, char **argv)
468 using NamingServiceImplementation = typename GUI_APP_STYLE::NamingServiceImplementation;
469 setSSLMode(GUI_APP_STYLE::SSL_MODE);
472 // Set-up application settings configuration (as for QSettings)
473 // Note: these are default settings which can be customized (see below)
474 QApplication::setOrganizationName("salome");
475 QApplication::setApplicationName("salome");
476 QApplication::setApplicationVersion(salomeVersion());
478 // Install Qt debug messages handler
479 MsgHandler msgHandler;
480 qInstallMessageHandler(QtxMsgHandler);
482 // Add <qtdir>/plugins dir to the pluins search path for image plugins
483 QString qtdir = Qtx::qtDir("plugins");
484 if (!qtdir.isEmpty())
485 QApplication::addLibraryPath(qtdir);
487 // Add application library path (to search style plugin etc...)
488 QString path = SUIT_Tools::addSlash(Qtx::getenv("GUI_ROOT_DIR")) + "bin/salome";
489 QApplication::addLibraryPath(QDir::toNativeSeparators(path));
491 // QSurfaceFormat should be set before creation of QApplication,
492 // so to avoid conflicts beetween SALOME and ParaView QSurfaceFormats we should merge theirs formats
493 // (see void Qtx::initDefaultSurfaceFormat()) and set the resultant format here.
494 Qtx::initDefaultSurfaceFormat();
496 // Create Qt application instance: this should be done as early as possible!
497 // Note: QApplication forces setting locale LC_ALL to system one: setlocale(LC_ALL, "").
498 SetArgcArgv(argc,argv);
499 Application app(argc, argv);
501 // Initialize Python (only once)
502 // Note: Python forces setting locale LC_CTYPE to system one: setlocale(LC_CTYPE, "").
503 char *py_argv[] = {(char *)""};
504 KERNEL_PYTHON::init_python(1, py_argv);
506 // Create auxiliary resource manager to access application settings
508 resMgr.setWorkingMode(ResourceMgr::IgnoreUserValues);
509 resMgr.loadLanguage("LightApp", "en");
510 resMgr.loadLanguage("SalomeApp", "en");
511 resMgr.loadLanguage("Session");
513 // Set-up application settings configuration possible customized via resources
514 if (resMgr.customName() != "SalomeApp")
516 QApplication::setApplicationName(resMgr.customName());
517 QApplication::setApplicationVersion(resMgr.version());
520 // Force default "C" locale if requested via user's preferences
521 // Note: this does not change whole application locale (changed via setlocale() function),
522 // but only affects GUI behavior
523 resMgr.setWorkingMode(ResourceMgr::AllowUserValues); // we must take into account user preferences
524 if (resMgr.booleanValue("language", "locale", true))
525 QLocale::setDefault(QLocale::c());
526 resMgr.setWorkingMode(ResourceMgr::IgnoreUserValues);
528 #if defined(GLOBAL_DOUBLE_CONVERSION)
529 // VSR 30/03/2021: moved here from QtxDoubleSpinBox/QtxIntSpinBox because of crash on Qt 5.12.
530 // Disable thousands separator for spin box
531 // see issue 14540 (old id 21219)
533 locale.setNumberOptions(locale.numberOptions() | QLocale::OmitGroupSeparator | QLocale::RejectGroupSeparator);
534 QLocale::setDefault(locale);
537 bool isGUI = boolCmdOption("--show-desktop", "--hide-desktop", true); // true by default
538 bool isSplash = boolCmdOption("--show-splash", "--hide-splash", true); // true by default
540 // Show splash screen (only if both the "GUI" and "SPLASH" options are true)
541 QtxSplash *splash = 0;
542 if (isGUI && isSplash)
544 splash = QtxSplash::splash(QPixmap());
545 splash->readSettings(&resMgr);
546 if (splash->pixmap().isNull())
547 splash->setPixmap(resMgr.loadPixmap("LightApp", QObject::tr("ABOUT_SPLASH")));
548 if (splash->pixmap().isNull())
555 splash->setOption("%A", QObject::tr("APP_NAME"));
556 splash->setOption("%V", QObject::tr("ABOUT_VERSION").arg(resMgr.version()));
557 splash->setOption("%L", QObject::tr("ABOUT_LICENSE"));
558 splash->setOption("%C", QObject::tr("ABOUT_COPYRIGHT"));
560 QApplication::instance()->processEvents();
568 PortableServer::POA_var poa;
570 SUIT_Session *aGUISession = 0;
571 GetInterfaceThread *guiThread = 0;
572 Session_ServerLauncher<NamingServiceImplementation> *myServerLauncher = nullptr;
574 #if defined(WIN32) && defined(UNICODE)
575 char **new_argv = NULL;
578 bool remoteLauncher = false;
582 // ...create ORB, get RootPOA object, NamingService, etc.
584 if (std::string(argv[1]).find("-ORBInitRef") != std::string::npos)
587 remoteLauncher = true;
589 SetArgcArgv(orbArgc, argv);
590 orb = KERNEL::GetRefToORB();
592 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
593 poa = PortableServer::POA::_narrow(obj);
595 PortableServer::POAManager_var pman = poa->the_POAManager();
597 MESSAGE("POA manager activated");
599 self.connectToNSIfNeeded(orb);
603 catch (SALOME_Exception &e)
605 INFOS("run(): Caught SALOME_Exception : " << e.what());
607 catch (CORBA::SystemException &e)
609 INFOS("run(): Caught CORBA::SystemException : " << handleCorbaException(e));
611 catch (CORBA::Exception &e)
613 INFOS("run(): Caught CORBA::Exception : " << handleCorbaException(e));
615 catch (std::exception &e)
617 INFOS("run(): Caught exception : " << e.what());
621 INFOS("run(): Caught unknown exception");
624 QMutex _GUIMutex, _SessionMutex, _SplashMutex;
625 QWaitCondition _ServerLaunch, _SessionStarted, _SplashStarted;
627 // lock session mutex to ensure that GetInterface is not called
628 // until all initialization is done
629 _SessionMutex.lock();
633 // Start embedded servers launcher (Registry, SALOMEDS, etc.)
634 // ...lock mutex to block embedded servers launching thread until wait( mutex )
636 // ...create launcher
637 #if defined(WIN32) && defined(UNICODE)
638 LPWSTR *szArglist = NULL;
641 szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
642 new_argv = new char *[nArgs];
643 for (i = 0; i < nArgs; i++)
645 new_argv[i] = (char *)Kernel_Utils::utf8_encode(szArglist[i]);
647 // Free memory allocated for CommandLineToArgvW arguments.
648 LocalFree(szArglist);
649 myServerLauncher = new Session_ServerLauncher<NamingServiceImplementation>(nArgs, new_argv, orb, poa, &_GUIMutex, &_ServerLaunch, &_SessionMutex, &_SessionStarted);
651 myServerLauncher = new Session_ServerLauncher<NamingServiceImplementation>(argc, argv, orb, poa, &_GUIMutex, &_ServerLaunch, &_SessionMutex, &_SessionStarted);
653 // ...block this thread until launcher is ready
654 _ServerLaunch.wait(&_GUIMutex);
656 // Start servers check thread (splash)
659 // ...lock mutex to block splash thread until wait( mutex )
661 // ...create servers checking thread
662 Session_ServerCheck<NamingServiceImplementation> sc(&_SplashMutex, &_SplashStarted);
663 // ... set initial progress
664 splash->setProgress(0, sc.totalSteps());
668 int step = sc.currentStep();
669 int total = sc.totalSteps();
670 QString msg = sc.currentMessage();
671 QString err = sc.error();
674 QtxSplash::setError(err);
675 QApplication::instance()->processEvents();
679 QtxSplash::setStatus(msg, step);
680 QApplication::instance()->processEvents();
683 // ...block this thread until servers checking is finished
684 _SplashStarted.wait(&_SplashMutex);
686 // ...unlock mutex 'cause it is no more needed
687 _SplashMutex.unlock();
690 // Finalize embedded servers launcher
691 // ...block this thread until launcher is finished
692 _ServerLaunch.wait(&_GUIMutex);
693 // ...unlock mutex 'cause it is no more needed
697 // Obtain Session interface reference
698 SALOME::Session_var session = self.getSession();
700 bool shutdownAll = false;
701 bool shutdownSession = false;
702 bool debugExceptions = boolCmdOption("--no-exception-handler") ||
703 resMgr.booleanValue("launch", "noexcepthandler", false);
707 // Launch GUI activator
711 splash->setStatus(QObject::tr("Activating desktop..."));
712 // ...create GUI launcher
713 MESSAGE("Session activated, Launch IAPP...");
714 guiThread = new GetInterfaceThread(session);
718 // Allow multiple activation/deactivation of GUI
721 MESSAGE("waiting wakeAll()");
722 _SessionStarted.wait(&_SessionMutex); // to be reseased by Launch server thread when ready:
723 // atomic operation lock - unlock on mutex
724 // unlock mutex: serverThread runs, calls _ServerLaunch->wakeAll()
725 // this thread wakes up, and lock mutex
727 _SessionMutex.unlock();
729 // Session might be shutdowning here, check status
730 SALOME::StatSession stat = session->GetStatSession();
731 shutdownSession = stat.state == SALOME::shutdown;
734 _SessionMutex.lock(); // lock mutex before leaving loop - it will be unlocked later
738 // SUIT_Session creation
739 aGUISession = new Session();
741 // Load SalomeApp dynamic library
742 MESSAGE("creation SUIT_Application");
743 SUIT_Application *aGUIApp = aGUISession->startApplication(NamingServiceImplementation::LibName, 0, 0);
746 #ifdef USE_SALOME_STYLE
747 Style_Salome::initialize(aGUIApp->resourceMgr());
748 if (aGUIApp->resourceMgr()->booleanValue("Style", "use_salome_style", true))
749 Style_Salome::apply();
750 #endif // USE_SALOME_STYLE
752 if (!debugExceptions)
753 app.setHandler(aGUISession->handler()); // after loading SalomeApp application
754 // aGUISession contains SalomeApp_ExceptionHandler
757 MESSAGE("run(): starting the main event loop");
760 splash->finish(aGUIApp->desktop());
766 if (result == SUIT_Session::NORMAL)
768 // desktop is explicitly closed by user from GUI
769 // exit flags says if it's necessary to shutdown all servers
770 // all session server only
771 shutdownAll = aGUISession->exitFlags();
775 // desktop might be closed from:
776 // - StopSesion() (temporarily) or
777 // - Shutdown() (permanently)
778 stat = session->GetStatSession();
779 shutdownSession = stat.state == SALOME::shutdown;
780 // normally "shutdown standalone servers" flag should be false here, if we come from
781 // StopSesion() or from Shutdown();
782 // but we also have to check if somebody explicitly programmatically closed session,
783 // asking to kill servers also
784 shutdownAll = aGUISession->exitFlags();
786 if (shutdownAll || shutdownSession)
788 _SessionMutex.lock(); // lock mutex before leaving loop - it will be unlocked later
796 // Prepare _GUIMutex for a new GUI activation
797 _SessionMutex.lock();
801 // unlock Session mutex
802 _SessionMutex.unlock();
804 // Shutdown embedded servers
805 if (myServerLauncher)
806 myServerLauncher->ShutdownAll();
808 // Shutdown standalone servers
810 self.shutdownRemoteServersIfNeeded(remoteLauncher);
812 // Kill embedded servers
813 if (myServerLauncher)
814 myServerLauncher->KillAll();
816 // Unregister session server
817 SALOME_Session_i *sessionServant =
818 dynamic_cast<SALOME_Session_i *>(poa->reference_to_servant(session.in()));
820 sessionServant->NSunregister();
824 delete myServerLauncher;
825 #if defined(WIN32) && defined(UNICODE)
828 self.shutdownCORBAStufIfNeeded(shutdownAll,orb);
830 if (Py_IsInitialized())
835 // Kill omniNames process
837 self.killOtherServersIfNeeded();
839 MESSAGE("Salome_Session_Server:endofserver");