<commit_before>//  SALOME Session : implementation of Session.idl
//
//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, <NAME> 
// 
//  This library is free software; you can redistribute it and/or 
//  modify it under the terms of the GNU Lesser General Public 
//  License as published by the Free Software Foundation; either 
//  version 2.1 of the License. 
// 
//  This library is distributed in the hope that it will be useful, 
//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
//  Lesser General Public License for more details. 
// 
//  You should have received a copy of the GNU Lesser General Public 
//  License along with this library; if not, write to the Free Software 
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
// 
//  See http://www.opencascade.org/SALOME/ or email : <EMAIL> 
//
//
//
//  File   : SALOME_Session_Server.cxx
//  Author : <NAME>, EDF
//  Module : SALOME
//  $Header$

#include <Container_init_python.hxx>
#include "Utils_ORB_INIT.hxx"
#include "Utils_SINGLETON.hxx"
#include "SALOME_NamingService.hxx"
#include "SALOMETraceCollector.hxx"

#include <iostream>
#include <unistd.h>

#include <qdir.h>
#include <qfile.h>
#include <qapplication.h>
#include <qwaitcondition.h>

#include "Utils_SALOME_Exception.hxx"
#include "Utils_CorbaException.hxx"
#include "SALOME_Event.hxx"

#include <SALOMEconfig.h>
#include CORBA_SERVER_HEADER(SALOME_Session)
#include CORBA_SERVER_HEADER(SALOMEDS)

#include <utilities.h>
#include "Session_Session_i.hxx"
#include "Session_ServerLauncher.hxx"

#include "SUIT_Session.h"
#include "SUIT_Application.h"
#include "SUIT_MessageBox.h"


#include "SUIT_ExceptionHandler.h"
using namespace std;

extern "C" int HandleSignals(QApplication *theQApplication);

/*! - read arguments, define list of server to launch with their arguments.
 *  - wait for naming service
 *  - create and run a thread for launch of all servers
 *  
 */

//! CORBA server for SALOME Session
/*!
 *  SALOME_Session Server launches a SALOME session servant.
 *  The servant registers to the Naming Service.
 *  See SALOME_Session.idl for interface specification.
 *
 *  Main services offered by the servant are:
 *   - launch GUI
 *   - stop Session (must be idle)
 *   - get session state
 */

QString salomeVersion()
{
  QString path( ::getenv( "GUI_ROOT_DIR" ) );
  if ( !path.isEmpty() )
    path += QDir::separator();
  path += QString( "bin/salome/VERSION" );

  QFile vf( path );
  if ( !vf.open( IO_ReadOnly ) )
    return QString::null;

  QString line;
  vf.readLine( line, 1024 );
  vf.close();

  if ( line.isEmpty() )
    return QString::null;

  while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
    line.remove( line.length() - 1, 1 );

  QString ver;
  int idx = line.findRev( ":" );
  if ( idx != -1 )
    ver = line.mid( idx + 1 ).stripWhiteSpace();

  return ver;
}

PyObject *salome_shared_modules_module = NULL;

void MessageOutput( QtMsgType type, const char *msg )
{
  switch ( type ) {
  case QtDebugMsg:
    MESSAGE( "Debug: " << msg );
    break;
  case QtWarningMsg:
    MESSAGE( "Warning: " << msg );
    break;
  case QtFatalMsg:
    MESSAGE( "Fatal: " << msg );
    break;
  }
}

class SALOME_Session : public SUIT_Session
{
public:
  SALOME_Session() : SUIT_Session() {}
  virtual ~SALOME_Session() {}

protected:
  virtual SUIT_ResourceMgr* createResourceMgr( const QString& appName ) const
  {
    SUIT_ResourceMgr* resMgr = new SUIT_ResourceMgr( appName, QString( "%1Config" ) );
    resMgr->setVersion( salomeVersion() );
    resMgr->setCurrentFormat( "xml" );
    return resMgr;
  }
};

class SALOME_QApplication : public QApplication 
{
public:
  SALOME_QApplication( int& argc, char** argv ) : QApplication( argc, argv ) 
  {
    myHandler = 0;
  }
  
  virtual bool notify( QObject* receiver, QEvent* e ) 
  {
    return myHandler ? myHandler->handle( receiver, e ) :
                       QApplication::notify( receiver, e );
  }
  SUIT_ExceptionHandler*  handler() const { return myHandler; }
  void setHandler( SUIT_ExceptionHandler* h ) { myHandler = h; }

private:
  SUIT_ExceptionHandler*  myHandler;
};

int main(int argc, char **argv)
{
  qInstallMsgHandler( MessageOutput );

  /*
  char* _argv_0[512];
  strcpy( (char*)_argv_0, (char*)argv[0] );
  */

  // QApplication should be create before all other operations
  // When uses QApplication::libraryPaths() (example, QFile::encodeName())
  // qApp used for detection of the executable dir path.
  SALOME_QApplication _qappl( argc, argv );
  ASSERT( QObject::connect(&_qappl, SIGNAL( lastWindowClosed() ), &_qappl, SLOT( quit() ) ) );
  _qappl.setStyle( "salome" );
  /*
  QStringList lst = _qappl.libraryPaths();
  for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
    printf( "=====> Library path: %s\n", (*it).latin1() );
  */

  /*<commit_msg>Fixing a bug : Salome GUI style needs addLibraryPath() method to be called<commit_after>//  SALOME Session : implementation of Session.idl
//
//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
// 
//  This library is free software; you can redistribute it and/or 
//  modify it under the terms of the GNU Lesser General Public 
//  License as published by the Free Software Foundation; either 
//  version 2.1 of the License. 
// 
//  This library is distributed in the hope that it will be useful, 
//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
//  Lesser General Public License for more details. 
// 
//  You should have received a copy of the GNU Lesser General Public 
//  License along with this library; if not, write to the Free Software 
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
// 
//  See http://www.opencascade.org/SALOME/ or email : <EMAIL> 
//
//
//
//  File   : SALOME_Session_Server.cxx
//  Author : <NAME>, EDF
//  Module : SALOME
//  $Header$

#include <Container_init_python.hxx>
#include "Utils_ORB_INIT.hxx"
#include "Utils_SINGLETON.hxx"
#include "SALOME_NamingService.hxx"
#include "SALOMETraceCollector.hxx"

#include <iostream>
#include <unistd.h>

#include <qdir.h>
#include <qfile.h>
#include <qapplication.h>
#include <qwaitcondition.h>

#include "Utils_SALOME_Exception.hxx"
#include "Utils_CorbaException.hxx"
#include "SALOME_Event.hxx"

#include <SALOMEconfig.h>
#include CORBA_SERVER_HEADER(SALOME_Session)
#include CORBA_SERVER_HEADER(SALOMEDS)

#include <utilities.h>
#include "Session_Session_i.hxx"
#include "Session_ServerLauncher.hxx"

#include "SUIT_Session.h"
#include "SUIT_Application.h"
#include "SUIT_MessageBox.h"


#include "SUIT_ExceptionHandler.h"
using namespace std;

extern "C" int HandleSignals(QApplication *theQApplication);

/*! - read arguments, define list of server to launch with their arguments.
 *  - wait for naming service
 *  - create and run a thread for launch of all servers
 *  
 */

//! CORBA server for SALOME Session
/*!
 *  SALOME_Session Server launches a SALOME session servant.
 *  The servant registers to the Naming Service.
 *  See SALOME_Session.idl for interface specification.
 *
 *  Main services offered by the servant are:
 *   - launch GUI
 *   - stop Session (must be idle)
 *   - get session state
 */

QString salomeVersion()
{
  QString path( ::getenv( "GUI_ROOT_DIR" ) );
  if ( !path.isEmpty() )
    path += QDir::separator();
  path += QString( "bin/salome/VERSION" );

  QFile vf( path );
  if ( !vf.open( IO_ReadOnly ) )
    return QString::null;

  QString line;
  vf.readLine( line, 1024 );
  vf.close();

  if ( line.isEmpty() )
    return QString::null;

  while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
    line.remove( line.length() - 1, 1 );

  QString ver;
  int idx = line.findRev( ":" );
  if ( idx != -1 )
    ver = line.mid( idx + 1 ).stripWhiteSpace();

  return ver;
}

PyObject *salome_shared_modules_module = NULL;

void MessageOutput( QtMsgType type, const char *msg )
{
  switch ( type ) {
  case QtDebugMsg:
    MESSAGE( "Debug: " << msg );
    break;
  case QtWarningMsg:
    MESSAGE( "Warning: " << msg );
    break;
  case QtFatalMsg:
    MESSAGE( "Fatal: " << msg );
    break;
  }
}

class SALOME_Session : public SUIT_Session
{
public:
  SALOME_Session() : SUIT_Session() {}
  virtual ~SALOME_Session() {}

protected:
  virtual SUIT_ResourceMgr* createResourceMgr( const QString& appName ) const
  {
    SUIT_ResourceMgr* resMgr = new SUIT_ResourceMgr( appName, QString( "%1Config" ) );
    resMgr->setVersion( salomeVersion() );
    resMgr->setCurrentFormat( "xml" );
    return resMgr;
  }
};

class SALOME_QApplication : public QApplication 
{
public:
  SALOME_QApplication( int& argc, char** argv ) : QApplication( argc, argv ) 
  {
    myHandler = 0;
  }
  
  virtual bool notify( QObject* receiver, QEvent* e ) 
  {
    return myHandler ? myHandler->handle( receiver, e ) :
                       QApplication::notify( receiver, e );
  }
  SUIT_ExceptionHandler*  handler() const { return myHandler; }
  void setHandler( SUIT_ExceptionHandler* h ) { myHandler = h; }

private:
  SUIT_ExceptionHandler*  myHandler;
};

int main(int argc, char **argv)
{
  qInstallMsgHandler( MessageOutput );

  /*
  char* _argv_0[512];
  strcpy( (char*)_argv_0, (char*)argv[0] );
  */

  // QApplication should be create before all other operations
  // When uses QApplication::libraryPaths() (example, QFile::encodeName())
  // qApp used for detection of the executable dir path.
  SALOME_QApplication _qappl( argc, argv );
  ASSERT( QObject::connect(&_qappl, SIGNAL( lastWindowClosed() ), &_qappl, SLOT( quit() ) ) );
  QString path( ::getenv( "GUI_ROOT_DIR" ) );
  if ( !path.isEmpty() )
    path += QDir::separator();
  path += QString( "bin/salome" );
  _qappl.addLibraryPath( path );
  _qappl.setStyle( "salome" );

  /*
{'fraction_non_alphanumeric': 0.12687382110592674, 'fraction_numerical': 0.007644197359277276, 'mean_word_length': 3.5770104497955475, 'pattern_counts': {'":': 2, '<': 38, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2961993', 'n_tokens_mistral': 3569, 'n_tokens_neox': 3416, 'n_words': 986}