Salome HOME
NRI : VISU dependence.
[modules/kernel.git] / src / Session / InquireServersQThread.h
1 #include <qapplication.h>
2 #include <qthread.h> 
3 #include <qvbox.h> 
4 #include <qprogressbar.h> 
5 #include <qlabel.h> 
6
7 /**********************************************************
8 **  Class:   InquireEvent
9 **  Descr:   Contains QCustomEvents for posting to InquireServersQThread
10 **  Level:   Private
11 ***********************************************************/
12
13 class InquireEvent : public QCustomEvent
14 {
15 public:
16
17   enum myCustomEvents{ ProgressEvent = QEvent::User + 10, ProgressEventLabel, ProgressEventError };
18   
19   InquireEvent( QEvent::Type type , void* data = 0 )
20         : QCustomEvent( type, data ) {}
21   ~InquireEvent() 
22       {
23         type() == (QEvent::Type)ProgressEvent ?
24           delete ( int* )data() : delete ( QString* )data();
25       }
26 };
27
28 class InquireServersGUI;
29
30 class InquireServersQThread : public QThread
31 {
32 public:
33   InquireServersQThread( InquireServersGUI* r );
34
35   //the main loop of this thread
36   virtual void run() ;
37   //stop to ask servers
38   void stop() 
39     {
40       IsChecking = false;
41       myExitStatus = 1;
42     }
43   //return exit status: 0 - OK, >0 - BAD (some servers doesn't exists or user click cancel button) 
44   int getExitStatus() { return myExitStatus;}
45   //return count of inquired servers
46   int getInquiredServers() { return myServersCount; }
47
48 private:
49
50 //functions:
51
52   bool AskServer(int iteration, QString ** message);
53   bool pingServer(int iteration, QString& errMessage);
54
55 //variables:
56
57   InquireServersGUI* receiver;
58   int _argc ;
59   char ** _argv;
60   //this variable is true if we are checking servers
61   bool IsChecking;
62   //count of inquired servers
63   int myServersCount;
64   //how many times we should repeat attempt to get response from all needed for launching SALOME servers
65   int myRepeat;
66   //define delay time between two attempts in microseconds
67   int myDelay;
68   //this strings' array contains messages for each server (e.g. "Loading: SALOMEDS_Server") 
69   QString myMessages[8];
70   //exit status: 0 - OK, >0 - BAD (some servers doesn't exists or user click cancel button) 
71   int myExitStatus;
72
73 } ;
74
75 class InquireServersGUI : public QVBox
76 {
77     Q_OBJECT
78
79 public:
80   InquireServersGUI() ;
81   ~InquireServersGUI();
82
83   //returns arguments of QApplication
84   //they are needed for CORBA servers initialization
85   void getArgs(  int& _argc, char *** _argv);
86   //return exit status: 0 - OK, >0 - BAD (some servers doesn't exists or user click cancel button) 
87   int getExitStatus();
88
89 protected:
90   virtual void customEvent( QCustomEvent* ); 
91   virtual void closeEvent ( QCloseEvent * );
92
93 private:
94   InquireServersQThread* myThread;
95   QProgressBar* myPrgBar;
96   //this string contains description of currently asked server
97   QLabel* myLabel;
98
99 private slots:
100
101     void ClickOnCancel();
102 } ;