00001 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE 00002 // 00003 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, 00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 00005 // 00006 // This library is free software; you can redistribute it and/or 00007 // modify it under the terms of the GNU Lesser General Public 00008 // License as published by the Free Software Foundation; either 00009 // version 2.1 of the License. 00010 // 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 // Lesser General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU Lesser General Public 00017 // License along with this library; if not, write to the Free Software 00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 // 00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com 00021 // 00022 00023 #ifndef SUIT_SESSION_H 00024 #define SUIT_SESSION_H 00025 00026 #include "SUIT.h" 00027 #include "SUIT_Application.h" 00028 00029 #include <QList> 00030 #include <QObject> 00031 #include <QString> 00032 00033 #ifdef WIN32 00034 #include <windows.h> 00035 #endif 00036 00037 #ifdef WIN32 00038 #define LIB_HANDLE HINSTANCE 00039 #else 00040 #define LIB_HANDLE void* 00041 #endif 00042 00043 class SUIT_ResourceMgr; 00044 class SUIT_ExceptionHandler; 00045 00046 #ifdef WIN32 00047 #pragma warning( disable:4251 ) 00048 #endif 00049 00054 class SUIT_EXPORT SUIT_Session : public QObject 00055 { 00056 Q_OBJECT 00057 00058 public: 00059 typedef LIB_HANDLE AppLib; 00060 00061 enum { ASK = 0, SAVE, DONT_SAVE } CloseMode; 00062 enum { NORMAL = 0, FORCED } ExitStatus; 00063 00064 public: 00065 SUIT_Session(); 00066 virtual ~SUIT_Session(); 00067 00068 static SUIT_Session* session(); 00069 00070 SUIT_Application* startApplication( const QString&, int = 0, char** = 0 ); 00071 00072 QList<SUIT_Application*> applications() const; 00073 SUIT_Application* activeApplication() const; 00074 00075 SUIT_ResourceMgr* resourceMgr() const; 00076 00077 void closeSession( int mode = ASK, int flags = 0 ); 00078 int exitFlags() const; 00079 00080 SUIT_ExceptionHandler* handler() const; 00081 00082 void insertApplication( SUIT_Application* ); 00083 00084 signals: 00085 void applicationClosed( SUIT_Application* ); 00086 00087 protected: 00088 virtual SUIT_ResourceMgr* createResourceMgr( const QString& ) const; 00089 00090 private slots: 00091 void onApplicationClosed( SUIT_Application* ); 00092 void onApplicationActivated( SUIT_Application* ); 00093 00094 private: 00095 typedef QList<SUIT_Application*> AppList; 00096 typedef QMap<QString, AppLib> AppLibMap; 00097 00098 private: 00099 QString lastError() const; 00100 AppLib loadLibrary( const QString&, QString& ); 00101 QString applicationName( const QString& ) const; 00102 00103 private: 00104 SUIT_ResourceMgr* myResMgr; 00105 AppList myAppList; 00106 AppLibMap myAppLibs; 00107 SUIT_Application* myActiveApp; 00108 00109 SUIT_ExceptionHandler* myHandler; 00110 static SUIT_Session* mySession; 00111 00112 int myExitStatus; 00113 int myExitFlags; 00114 }; 00115 00116 #endif