1 // Copyright (C) 2003 CEA/DEN, EDF R&D
5 // File : InquireServersQThread.cxx
6 // Author : Vasily RUSYAEV
10 #include "InquireServersQThread.h"
12 #include <qapplication.h>
13 #include <qpushbutton.h>
14 #include <qabstractlayout.h>
18 #include <qmessagebox.h>
20 #include <qfileinfo.h>
21 #include <qstringlist.h>
23 #include <qprogressbar.h>
25 //VRV: porting on Qt 3.0.5
26 #if QT_VERSION >= 0x030005
27 #include <qdesktopwidget.h>
29 //VRV: porting on Qt 3.0.5
33 #include <SALOMEconfig.h>
35 #include "Utils_ORB_INIT.hxx"
36 #include "Utils_SINGLETON.hxx"
37 #include "SALOME_NamingService.hxx"
38 #include "utilities.h"
43 #include CORBA_CLIENT_HEADER(SALOME_Session)
44 #include CORBA_CLIENT_HEADER(SALOME_Registry)
45 #include CORBA_CLIENT_HEADER(SALOMEDS)
46 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
47 #include CORBA_CLIENT_HEADER(SALOME_Component)
50 #define SPACING_SIZE 3
55 InquireServersGUI::InquireServersGUI()
56 : QVBox(0, "SFA splash", Qt::WDestructiveClose | Qt::WStyle_Customize | Qt::WStyle_NoBorder | WType_TopLevel | WStyle_StaysOnTop | WX11BypassWM )
59 myThread = new InquireServersQThread( this );
61 // 1. Polish the appearance
62 setMargin( MARGIN_SIZE );
63 setSpacing( SPACING_SIZE );
64 setFrameStyle( QFrame::Plain | QFrame::Box );
66 setMinimumSize( 200, 150 );
69 QPalette pal = palette();
70 QColorGroup cg = pal.active();
71 cg.setColor( QColorGroup::Foreground, Qt::darkBlue );
72 cg.setColor( QColorGroup::Background, Qt::white );
73 pal.setActive( cg ); pal.setInactive( cg ); pal.setDisabled( cg );
77 mySplashFrame = new QFrame( this );
78 mySplashFrame->setFrameStyle( QFrame::Box | QFrame::Raised );
79 QHBoxLayout* frmLayout = new QHBoxLayout( mySplashFrame );
80 frmLayout->setMargin( MARGIN_SIZE );
81 mySplash = new QLabel( mySplashFrame, "splash" );
82 frmLayout->addWidget( mySplash );
85 //QPixmap pix = SUIT_ResourceMgr( "SalomeApp" ).loadPixmap( "SalomeApp", tr( "ABOUT" ) );
86 //splash->setPixmap( pix );
89 myPrgBar = new QProgressBar( this, "QProgressBar" );
90 myPrgBar->setFixedWidth( 180 );
91 //Sets the total number of steps .
92 myPrgBar->setPercentageVisible( false );
93 myPrgBar->setIndicatorFollowsStyle( false );
94 myPrgBar->setFixedHeight( 8 );
95 myPrgBar->setFrameStyle( QFrame::Box | QFrame::Plain );
96 myPrgBar->setMargin( 0 );
97 pal = myPrgBar->palette(); cg = pal.active();
98 cg.setColor( QColorGroup::Highlight, Qt::red );
99 pal.setActive( cg ); pal.setInactive( cg ); pal.setDisabled( cg ); myPrgBar->setPalette( pal );
100 myPrgBar->setTotalSteps ( myThread->getInquiredServers() );
101 myPrgBar->setProgress( 0 );
104 QWidget* aWgt1 = new QWidget( this );
105 QHBoxLayout* aHBoxLayout1 = new QHBoxLayout( aWgt1 );
106 myLabel = new QLabel( tr( "Loading:" ), aWgt1 );
107 myLabel->setFixedWidth( 180 );
108 myLabel->setAlignment( AlignLeft );
109 QFont theFont = myLabel->font();
110 theFont.setBold(true);
111 myLabel->setFont( theFont );
112 aHBoxLayout1->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
113 aHBoxLayout1->addWidget( myLabel );
114 aHBoxLayout1->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
116 // 5. <Cancel> button
117 QWidget* aWgt = new QWidget( this );
118 QHBoxLayout* aHBoxLayout = new QHBoxLayout( aWgt );
119 QPushButton* myCancelBtn = new QPushButton( tr( "Cancel" ), aWgt );
120 connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
121 aHBoxLayout->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
122 aHBoxLayout->addWidget( myCancelBtn );
123 aHBoxLayout->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
126 #if QT_VERSION >= 0x030005
127 QDesktopWidget *d = QApplication::desktop();
129 QWidget *d = QApplication::desktop();
131 //VRV: porting on Qt 3.0.5
133 int w = d->width(); // returns desktop width
134 int h = d->height(); // returns desktop height
135 QSize mySize = sizeHint (); // returns widget size
136 int Xc = ( w - mySize.width() ) / 2;
137 int Yc = ( h - mySize.height() ) / 2;
144 Sets pixmap of splash screen
145 \param pix - new pixmap
147 void InquireServersGUI::setPixmap( QPixmap pix )
151 mySplash->setPixmap( pix );
152 int w = mySplash->sizeHint().width() + MARGIN_SIZE*2;
153 myPrgBar->setFixedWidth( w );
154 myLabel->setFixedWidth( w );
161 InquireServersGUI::~InquireServersGUI()
167 Gets parameters from qApp
168 \param _argc - variable to return number of arguments
169 \param _argv - variable to return array of arguments
171 void InquireServersGUI::getArgs( int& _argc, char *** _argv)
173 _argc = qApp->argc();
174 *_argv = qApp->argv();
178 Cancel loading of SALOME
180 void InquireServersGUI::ClickOnCancel()
182 myThread->stop(); //it's necessary to stop asking servers
190 void InquireServersGUI::customEvent( QCustomEvent* pe )
194 case InquireEvent::ProgressEvent:
196 int* value = ( int* )(( InquireEvent*)pe)->data();
197 myPrgBar->setProgress( *value );
200 case InquireEvent::ProgressEventLabel:
202 QString* myString = ( QString* )(( InquireEvent*)pe)->data();
203 myLabel->setText( *myString );
206 case InquireEvent::ProgressEventError:
208 QString* myErrDesc = ( QString* )(( InquireEvent*)pe)->data();
209 QString appName = "SALOME Professional";
210 QString error = "An internal error occurred.\n"+ *myErrDesc + "\n";
211 QMessageBox myMsgBox(appName,error,QMessageBox::Critical,QMessageBox::Ok,QMessageBox::NoButton,
212 QMessageBox::NoButton,0,"MY",TRUE,WStyle_DialogBorder|WStyle_StaysOnTop);
225 \return status of thread exit
227 int InquireServersGUI::getExitStatus()
229 return myThread->getExitStatus();
235 InquireServersQThread::InquireServersQThread( InquireServersGUI* r )
236 : receiver(r), myExitStatus(0)
242 //how many times we should repeat attempts to get response from all needed for launching SALOME servers
243 myRepeat = 30; // default value, user can change it by setting CSF_RepeatServerRequest env.variable
244 cenv = getenv( "CSF_RepeatServerRequest" );
246 int val = atoi( cenv );
250 //define delay time between two attempts
251 myDelay = 1000000; // 1 second
252 QString str = "Loading: ";
253 myMessages[0] = "Checking naming service...";
254 myMessages[1] = str + "SALOME_Registry_Server" + "...";
255 myMessages[2] = str + "SALOMEDS_Server" + "...";
256 myMessages[3] = str + "SALOME_ModuleCatalog_Server" + "...";
257 myMessages[4] = str + "SALOME_Session_Server" + "...";
262 r->getArgs( _argc, &_argv);
264 // NRI : Temporary solution for SuperVisionContainer
265 for ( int i=1; i<=(_argc-1); i++) {
266 if (strcmp(_argv[i],"CPP")==0) {
267 myMessages[5] = str + "SALOME_Container FactoryServer" + "...";
270 if (strcmp(_argv[i],"PY")==0) {
271 myMessages[6] = str + "SALOME_ContainerPy.py FactoryServerPy" + "...";
274 if (strcmp(_argv[i],"SUPERV")==0) {
275 myMessages[7] = str + "SALOME_Container SuperVisionContainer" + "...";
278 // if (strcmp(_argv[i],"GUI")==0) {
285 The main loop of this thread
287 void InquireServersQThread::run()
289 while ( IsChecking && receiver )
291 for (int i=1; i<=8; i++)
293 if ( myMessages[i-1].isEmpty() )
298 myExitStatus = 0; //myExitStatus should be 0 because all servers exist and work
299 sleep( 1 ); // sleep( 1 second ) in order to see 100%. in other case it closes on 85%..
305 QString *message = new QString(myMessages[i-1]);
306 QThread::postEvent( receiver, new InquireEvent( ( QEvent::Type )InquireEvent::ProgressEventLabel, message ) );
307 QThread::usleep(200000);
309 bool result = AskServer(i,&errMsg);
312 QThread::postEvent( receiver, new InquireEvent( ( QEvent::Type )InquireEvent::ProgressEvent, new int( i ) ) );
316 myExitStatus = 0; //myExitStatus should be 0 because all servers exist and work
317 sleep( 1 ); // sleep( 1 second ) in order to see 100%. in other case it closes on 85%..
323 QThread::postEvent( receiver, new InquireEvent( ( QEvent::Type )InquireEvent::ProgressEventError, errMsg ) );
331 qApp->exit( myExitStatus );
337 void InquireServersQThread::stop()
346 InquireServersQThread::~InquireServersQThread()
350 bool InquireServersQThread::AskServer(int iteration, QString ** errMessage)
352 if ( iteration > myServersCount )
353 return true; // we did not launch server with number iteration, so checking for it is not neccessary
355 ASSERT(iteration<=myServersCount);
357 //will be set true if we get response from server
358 bool IsPassed = false;
359 QString errDescription;
366 //First checking - existence of Naming Service
368 for (int i = myRepeat; i ; i--)
370 for (i = myRepeat; i ; i--)
375 CORBA::ORB_var orb = CORBA::ORB_init(_argc,_argv) ;
376 CORBA::Object_var obj = orb->resolve_initial_references("NameService");
377 CosNaming::NamingContext_var _root_context = CosNaming::NamingContext::_narrow(obj);
378 if (CORBA::is_nil(_root_context))
384 catch(CORBA::COMM_FAILURE&)
386 MESSAGE("CORBA::COMM_FAILURE: unable to contact the naming service");
390 MESSAGE("Unknown Exception: unable to contact the naming service");
392 QThread::usleep(myDelay);
395 *errMessage = new QString("unable to contact the naming service");
398 //checking - existence of SALOME_Registry_Server
400 //checking - existence of SALOMEDS_Server
402 //checking - existence of SALOME_ModuleCatalog_Server
404 //checking - existence of SALOME_Session_Server
406 //checking - existence of SALOME_Container FactoryServer
408 //checking - existence of SALOME_ContainerPy.py FactoryServerPy
410 //checking - existence of SALOME_Container SuperVisionContainer
413 IsPassed = pingServer(iteration, errDescription);
415 *errMessage = new QString(errDescription);
421 bool InquireServersQThread::pingServer(int iteration, QString& errMessage)
423 ASSERT(iteration<=myServersCount);
426 for (int i = myRepeat; i ; i--)
430 CORBA::ORB_var orb = CORBA::ORB_init(_argc,_argv) ;
431 SALOME_NamingService &NS = *SINGLETON_<SALOME_NamingService>::Instance() ;
432 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting()) ;
438 CORBA::Object_var obj = NS.Resolve("/Registry");
439 Registry::Components_var registry = Registry::Components::_narrow(obj) ;
440 if (!CORBA::is_nil(registry))
442 MESSAGE("/Registry is found");
445 MESSAGE("Registry was activated");
452 CORBA::Object_var obj = NS.Resolve("/myStudyManager");
453 SALOMEDS::StudyManager_var studyManager = SALOMEDS::StudyManager::_narrow(obj) ;
454 if (!CORBA::is_nil(studyManager))
461 MESSAGE("/myStudyManager is found");
462 studyManager->ping();
464 MESSAGE("StudyManager was activated");
471 CORBA::Object_var obj = NS.Resolve("/Kernel/ModulCatalog");
472 SALOME_ModuleCatalog::ModuleCatalog_var catalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj) ;
473 if (!CORBA::is_nil(catalog))
475 MESSAGE("/Kernel/ModulCatalog is found");
478 MESSAGE("ModuleCatalog was activated");
485 CORBA::Object_var obj = NS.Resolve("/Kernel/Session");
486 SALOME::Session_var session = SALOME::Session::_narrow(obj) ;
487 if (!CORBA::is_nil(session))
489 MESSAGE("/Kernel/Session is found");
492 MESSAGE("SALOME_Session was activated");
499 string hostname = GetHostname();
500 string containerName = "/Containers/";
501 containerName += hostname;
502 containerName += "/FactoryServer";
504 CORBA::Object_var obj = NS.Resolve(containerName.c_str());
505 Engines::Container_var FScontainer = Engines::Container::_narrow(obj) ;
506 if (!CORBA::is_nil(FScontainer))
510 MESSAGE("FactoryServer container was activated");
517 string hostname = GetHostname();
518 string containerName = "/Containers/";
519 containerName += hostname;
520 containerName += "/FactoryServerPy";
522 CORBA::Object_var obj = NS.Resolve(containerName.c_str());
523 Engines::Container_var FSPcontainer = Engines::Container::_narrow(obj) ;
524 if (!CORBA::is_nil(FSPcontainer))
526 FSPcontainer->ping();
528 MESSAGE("FactoryServerPy container was activated");
535 string hostname = GetHostname();
536 string containerName = "/Containers/";
537 containerName += hostname;
538 containerName += "/SuperVisionContainer";
540 CORBA::Object_var obj = NS.Resolve(containerName.c_str());
541 Engines::Container_var SVcontainer = Engines::Container::_narrow(obj) ;
542 if (!CORBA::is_nil(SVcontainer))
547 MESSAGE("SuperVisionContainer container was activated");
554 catch (ServiceUnreachable&)
556 MESSAGE("Caught exception: Naming Service Unreachable");
557 errorDescr = "Caught exception: Naming Service Unreachable";
559 catch (CORBA::COMM_FAILURE&)
561 MESSAGE("Caught CORBA::SystemException CommFailure.");
562 errorDescr = "Caught CORBA::SystemException CommFailure";
564 catch (CORBA::SystemException&)
566 MESSAGE("Caught CORBA::SystemException.");
567 errorDescr = "Caught CORBA::SystemException";
569 catch (CORBA::Exception&)
571 MESSAGE("Caught CORBA::Exception.");
572 errorDescr = "Caught CORBA::Exception";
576 MESSAGE("Caught unknown exception.");
577 errorDescr = "Caught unknown exception";
579 QThread::usleep(myDelay);
587 serverName = "SALOME_Registry_Server is not loaded. ";
590 serverName = "SALOMEDS_Server is not loaded. ";
593 serverName = "SALOME_ModuleCatalog_Server is not loaded. ";
596 serverName = "SALOME_Session_Server is not loaded. ";
599 serverName = "SALOME_Container FactoryServer is not loaded. ";
602 serverName = "SALOME_ContainerPy.py FactoryServerPy is not loaded. ";
605 serverName = "SALOME_Container SuperVisionContainer is not loaded. ";
608 errMessage = serverName + errorDescr;