]> SALOME platform Git repositories - modules/gui.git/blob - src/SUIT/SUIT_Session.h
Salome HOME
505f00c1a5f2df98751b4d49271b7f1a3ec3b735
[modules/gui.git] / src / SUIT / SUIT_Session.h
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/
18 //
19 #ifndef SUIT_SESSION_H
20 #define SUIT_SESSION_H
21
22 #include "SUIT.h"
23
24 #include "SUIT_Application.h"
25 #include "SUIT_ResourceMgr.h"
26
27 #include <qobject.h>
28 #include <qptrlist.h>
29 #include <qptrvector.h>
30 #include <qstringlist.h>
31
32 #ifdef WIN32
33 #define LIB_HANDLE HINSTANCE
34 #else
35 #define LIB_HANDLE void*
36 #endif
37
38 class SUIT_ResourceMgr;
39 class SUIT_ExceptionHandler;
40
41 #ifdef WNT
42 #pragma warning( disable:4251 )
43 #endif
44 /*!
45   The class Sesssion manages launching of Applications. Application must be returned \n
46   by static function "createApplication" in external library. The Library must be loaded with \n
47   loadLibrary method and after that application can be started.
48 */
49 class SUIT_EXPORT SUIT_Session: public QObject
50 {
51   Q_OBJECT
52
53 public:
54   typedef LIB_HANDLE AppLib;
55
56   enum { ASK = 0, SAVE, DONT_SAVE } CloseMode;
57   enum { FROM_GUI = 0, FROM_CORBA_SESSION } ExitStatus;
58
59 public:
60   SUIT_Session();
61   virtual ~SUIT_Session();
62
63   static SUIT_Session*         session();
64
65   SUIT_Application*            startApplication( const QString&, int = 0, char** = 0 );
66
67   QPtrList<SUIT_Application>   applications() const;
68   SUIT_Application*            activeApplication() const;
69
70   SUIT_ResourceMgr*            resourceMgr() const;
71
72   void                         closeSession( int mode = ASK );
73
74   SUIT_ExceptionHandler*       handler() const;
75
76 signals:
77   void                         applicationClosed( SUIT_Application* );
78
79 protected:
80   virtual SUIT_ResourceMgr*    createResourceMgr( const QString& ) const;
81
82 private slots:
83   void                         onApplicationClosed( SUIT_Application* );
84   void                         onApplicationActivated( SUIT_Application* ); 
85
86 private:
87   typedef QPtrList<SUIT_Application>         AppList;
88   typedef QMap<QString, AppLib>              AppLibMap;
89   typedef QPtrListIterator<SUIT_Application> AppListIterator;
90
91 private:
92   QString                      lastError() const;
93   AppLib                       loadLibrary( const QString&, QString& );
94   QString                      applicationName( const QString& ) const;
95
96 private:
97   SUIT_ResourceMgr*            myResMgr;
98   AppList                      myAppList;
99   AppLibMap                    myAppLibs;
100   SUIT_Application*            myActiveApp;
101
102   SUIT_ExceptionHandler*       myHandler;
103   static SUIT_Session*         mySession;
104
105   int                          myExitStatus;
106 };
107
108 #endif