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