From: Anthony GEAY Date: Fri, 19 Feb 2021 10:40:18 +0000 (+0100) Subject: WIP X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d906963914bc4f98913e4312b8276754b49af3bd;p=modules%2Fkernel.git WIP --- diff --git a/src/Container/Container_i.cxx b/src/Container/Container_i.cxx index 582cd1d7a..4aff5403f 100644 --- a/src/Container/Container_i.cxx +++ b/src/Container/Container_i.cxx @@ -1900,54 +1900,18 @@ void Engines_Container_i::clearTemporaryFiles() _tmp_files.clear(); } -/* -std::string Engines_Container_i::AnotherMethodeToReplace_PyString_AsString(PyObject * result) -{ - std::string my_result = ""; - if (PyUnicode_Check(result)) { - // Convert string to bytes. - // strdup() bytes into my_result. - PyObject * temp_bytes = PyUnicode_AsEncodedString(result, "ASCII", "strict"); // Owned reference - if (temp_bytes != NULL) { - my_result = PyBytes_AS_STRING(temp_bytes); // Borrowed pointer - my_result = strdup(my_result); - Py_DECREF(temp_bytes); - } else { - // TODO PY3: Handle encoding error. - Py_DECREF(temp_bytes); - } +static Engines_Container_i *_container_singleton_ssl = nullptr; - } else if (PyBytes_Check(result)) { - // strdup() bytes into my_result. - my_result = PyBytes_AS_STRING(result); // Borrowed pointer - my_result = strdup(my_result); - } else { - // Convert into your favorite string representation. - // Convert string to bytes if it is not already. - // strdup() bytes into my_result. - // TODO PY3: Check if only bytes is ok. - PyObject * temp_bytes = PyObject_Bytes(result); // Owned reference - if (temp_bytes != NULL) { - my_result = PyBytes_AS_STRING(temp_bytes); // Borrowed pointer - my_result = strdup(my_result); - Py_DECREF(temp_bytes); - } else { - // TODO PY3: Handle error. - Py_DECREF(temp_bytes); - } - } - return my_result; -} -*/ +static PortableServer::ObjectId_var _container_id_singleton_ssl; -static Engines_Container_i *_container_singleton_ssl = nullptr; +static Engines::Container_var _container_ref_singleton_ssl; -Engines_Container_i *KERNEL::getContainerIdSA() +Engines_Container_i *KERNEL::getContainerSA() { - if(!_container_singleton_ssl) { - int argc(0); orb = CORBA::ORB_init(argc,nullptr); } + int argc(0); + CORBA::ORB_var orb = CORBA::ORB_init(argc,nullptr); CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow(obj); PortableServer::POAManager_var pman = poa->the_POAManager(); @@ -1955,13 +1919,29 @@ Engines_Container_i *KERNEL::getContainerIdSA() policies.length(0); PortableServer::ObjectId_var conId; // - { - char *argv[4] = {"Container","FactoryServer","toto",nullptr}; - _container_singleton_ssl = new Engines_Container_i(orb,poa,"FactoryServer",2,argv,false,false); - conId = poa->activate_object(_container_singleton_ssl); - } + char *argv[4] = {"Container","FactoryServer","toto",nullptr}; + _container_singleton_ssl = new Engines_Container_i(orb,poa,"FactoryServer",2,argv,false,false); + _container_id_singleton_ssl = poa->activate_object(_container_singleton_ssl); + // + CORBA::Object_var zeRef = poa->id_to_reference(_container_id_singleton_ssl); + _container_ref_singleton_ssl = Engines::Container::_narrow(zeRef); } -CORBA::ORB_var orb; + return _container_singleton_ssl; +} + +PortableServer::ObjectId_var KERNEL::getContainerIdSA() +{ + getContainerSA(); + return _container_id_singleton_ssl; +} + +Engines::Container_var KERNEL::getContainerRefSA() +{ + getContainerSA(); + return _container_ref_singleton_ssl; +} + +/*CORBA::ORB_var orb; { int argc(0); orb = CORBA::ORB_init(argc,nullptr); } CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow(obj); @@ -1997,4 +1977,4 @@ PortableServer::ObjectId_var KERNEL::getContainerIdSA() Engines::Container_var KERNEL::getContainerRefSA() { -} +}*/ diff --git a/src/Container/SALOME_Container_i.hxx b/src/Container/SALOME_Container_i.hxx index 047d9dfb3..42564975b 100644 --- a/src/Container/SALOME_Container_i.hxx +++ b/src/Container/SALOME_Container_i.hxx @@ -178,7 +178,7 @@ protected: */ namespace KERNEL { - CONTAINER_EXPORT Engines_Container_i *getContainerIdSA(); + CONTAINER_EXPORT Engines_Container_i *getContainerSA(); CONTAINER_EXPORT PortableServer::ObjectId_var getContainerIdSA(); CONTAINER_EXPORT Engines::Container_var getContainerRefSA(); } diff --git a/src/DSC/DSC_User/DSC_Exception.hxx b/src/DSC/DSC_User/DSC_Exception.hxx index b9c498c03..b44f5c842 100644 --- a/src/DSC/DSC_User/DSC_Exception.hxx +++ b/src/DSC/DSC_User/DSC_Exception.hxx @@ -81,7 +81,7 @@ public: return oss_.str(); } - // Surtout ne pas écrire le code suivant: + // Surtout ne pas �crire le code suivant: // car oss_.str() renvoie une string temporaire // operator const char*() // { @@ -91,32 +91,25 @@ public: }; /* end class OSS */ #endif - -// Cette fonction provient de Utils_SALOME_Exception -// Solution pas très élégante mais contrainte par les manques de la classe SALOME_Exception -const char *makeText( const char *text, const char *fileName, const unsigned int lineNumber); - struct DSC_Exception : public SALOME_Exception { - // Attention, en cas de modification des paramètres par défaut + // Attention, en cas de modification des param�tres par d�faut // il est necessaire de les repporter dans la macro DSC_EXCEPTION ci-dessous // Le constructeur de la SALOME_Exception demande une chaine non vide - // Du coup on est obliger de la désallouer avant d'y mettre la notre + // Du coup on est obliger de la d�sallouer avant d'y mettre la notre // car le what n'est pas virtuel donc il faut que le contenu de SALOME_Exception::_text // soit utilisable. - // Ne pas mettre lineNumber=0 à cause du calcul log dans la SALOME_Exception si fileName est défini + // Ne pas mettre lineNumber=0 � cause du calcul log dans la SALOME_Exception si fileName est d�fini DSC_Exception( const std::string & text, const char *fileName="", const unsigned int lineNumber=0, const char *funcName="" ): - SALOME_Exception(text.c_str()) , + SALOME_Exception(text) , _dscText(text), _filefuncName(setFileFuncName(fileName?fileName:"",funcName?funcName:"")), _lineNumber(lineNumber), _exceptionName("DSC_Exception") { - // Mise en cohérence avec l'exception SALOME (à revoir) - delete [] ((char*)SALOME_Exception::_text); if (! _filefuncName.empty() ) SALOME_Exception::_text = makeText(text.c_str(),_filefuncName.c_str(),lineNumber) ; else @@ -135,10 +128,10 @@ struct DSC_Exception : public SALOME_Exception { return _what.c_str() ; } - // L'opérateur = de SALOME_Exception n'est pas défini - // problème potentiel concernant la recopie de son pointeur _text + // L'op�rateur = de SALOME_Exception n'est pas d�fini + // probl�me potentiel concernant la recopie de son pointeur _text - // Le destructeur de la SALOME_Exception devrait être virtuel + // Le destructeur de la SALOME_Exception devrait �tre virtuel // sinon pb avec nos attributs de type pointeur. virtual ~DSC_Exception(void) noexcept {}; @@ -173,8 +166,8 @@ protected: virtual ~Derived(void) noexcept;\ };\ -//Sert à eviter le problème d'identification RTTI des exceptions -//Crée un unique typeInfo pour tous les bibliothèques composants SALOME +//Sert � eviter le probl�me d'identification RTTI des exceptions +//Cr�e un unique typeInfo pour tous les biblioth�ques composants SALOME //dans un fichier cxx #define DSC_EXCEPTION_CXX(NameSpace,Derived) NameSpace::Derived::~Derived(void) noexcept {} diff --git a/src/NamingService/SALOME_Fake_NamingService.cxx b/src/NamingService/SALOME_Fake_NamingService.cxx index 75c7e911b..026c22493 100644 --- a/src/NamingService/SALOME_Fake_NamingService.cxx +++ b/src/NamingService/SALOME_Fake_NamingService.cxx @@ -18,6 +18,7 @@ // #include "SALOME_Fake_NamingService.hxx" +#include "Utils_SALOME_Exception.hxx" SALOME_Fake_NamingService::SALOME_Fake_NamingService(CORBA::ORB_ptr orb):_orb(CORBA::ORB::_duplicate(orb)) { @@ -33,5 +34,8 @@ void SALOME_Fake_NamingService::Register(CORBA::Object_ptr ObjRef, const char* P CORBA::Object_ptr SALOME_Fake_NamingService::Resolve(const char* Path) { std::string pathCpp(Path); - if(pathCpp == ) + auto it = _map.find(pathCpp); + if( it != _map.end() ) + return (*it).second; + THROW_SALOME_EXCEPTION("SALOME_Fake_NamingService::Resolve : no such entry \"" << Path << "\" !"); } diff --git a/src/Utils/Utils_Identity.cxx b/src/Utils/Utils_Identity.cxx index 7747f5ce4..dbdcf4f10 100644 --- a/src/Utils/Utils_Identity.cxx +++ b/src/Utils/Utils_Identity.cxx @@ -29,11 +29,10 @@ # include # include "utilities.h" # include "Utils_Identity.hxx" +# include extern "C" { -# include - #ifndef WIN32 /* unix functionality */ # include #endif diff --git a/src/Utils/Utils_SALOME_Exception.cxx b/src/Utils/Utils_SALOME_Exception.cxx index 999afd652..99dcb283a 100644 --- a/src/Utils/Utils_SALOME_Exception.cxx +++ b/src/Utils/Utils_SALOME_Exception.cxx @@ -26,7 +26,6 @@ // Module : SALOME // $Header$ // -#include #include "Utils_SALOME_Exception.hxx" #include "utilities.h" @@ -41,82 +40,36 @@ extern "C" } #endif - -const char* duplicate( const char *const str ) ; - -SALOME_Exception::SALOME_Exception( void ): exception() , _text(0) +std::string makeText(const char *text, const char *fileName, const unsigned int lineNumber) { - MESSAGE( "You must use the standard builder: SALOME_Exception::SALOME_Exception( const char *text )" ) ; - INTERRUPTION(1) ; + constexpr char prefix[] = "Salome Exception"; + std::ostringstream oss; + if (fileName) + { + oss << prefix << " in " << fileName << "[" << lineNumber << "] : " << text; + } + else + { + oss << prefix << " : " << text; + } + return oss.str(); } - - -const char *makeText( const char *text, const char *fileName, const unsigned int lineNumber ) +SALOME_Exception::SALOME_Exception(const char *text, const char *fileName, const unsigned int lineNumber) : _text(makeText(text, fileName, lineNumber)) { - char *newText = 0 ; - - ASSERT(text) ; - const size_t l1 = 1+strlen(text) ; - ASSERT(l1>1) ; - - const char* prefix = "Salome Exception" ; - const size_t l0 = 2+strlen(prefix) ; - - if ( fileName ) - { - const size_t l2 = 4+strlen(fileName) ; - ASSERT(l2>4) ; - - ASSERT(lineNumber>=1) ; - const size_t l3 = 4+int(log10(float(lineNumber))) ; - - newText = new char [ 1+l0+l1+l2+l3 ] ; - sprintf( newText , "%s in %s [%u] : %s" , prefix, fileName, lineNumber, text ) ; - } - else - { - newText = new char [ 1+l0+l1 ] ; - sprintf( newText , "%s : %s" , prefix, text ) ; - } - ASSERT(newText) ; - return newText ; } - -SALOME_Exception::SALOME_Exception( const char *text, const char *fileName, const unsigned int lineNumber ) : exception(), _text( makeText( text , fileName , lineNumber ) ) -{ -} - - SALOME_Exception::~SALOME_Exception() noexcept { - if ( _text ) - { - delete [] ((char*)_text); - char** pRef = (char**)&_text; - *pRef = 0; - } - ASSERT(_text==NULL) ; -} - - - -SALOME_Exception::SALOME_Exception( const SALOME_Exception &ex ): _text(duplicate(ex._text)) -{ - ; } - -std::ostream & operator<<( std::ostream &os , const SALOME_Exception &ex ) +std::ostream &operator<<(std::ostream &os, const SALOME_Exception &ex) { - os << ex._text ; - return os ; + os << ex._text; + return os; } - - -const char* SALOME_Exception::what( void ) const noexcept +const char *SALOME_Exception::what(void) const noexcept { - return _text ; + return _text.c_str(); } diff --git a/src/Utils/Utils_SALOME_Exception.hxx b/src/Utils/Utils_SALOME_Exception.hxx index d4d94d568..6c69e83bf 100644 --- a/src/Utils/Utils_SALOME_Exception.hxx +++ b/src/Utils/Utils_SALOME_Exception.hxx @@ -26,60 +26,57 @@ // Module : SALOME // $Header$ // -#if !defined( __Utils_SALOME_Exception_hxx__ ) -#define __Utils_SALOME_Exception_hxx__ +#pragma once -//#include "SALOME_Utils.hxx" - -# include -# include +#include +#include +#include #ifdef LOCALIZED #undef LOCALIZED #endif #if defined(_DEBUG_) || defined(_DEBUG) -# define LOCALIZED(message) #message , __FILE__ , __LINE__ +#define LOCALIZED(message) #message, __FILE__, __LINE__ #else -# define LOCALIZED(message) #message +#define LOCALIZED(message) #message #endif //swig tool on Linux doesn't pass defines from header SALOME_Utils.hxx //therefore (temporary solution) defines are placed below #ifdef WIN32 -# if defined UTILS_EXPORTS || defined OpUtil_EXPORTS -# define UTILS_EXPORT __declspec( dllexport ) -# else -# define UTILS_EXPORT __declspec( dllimport ) -# undef LOCALIZED -# define LOCALIZED(message) #message -# endif +#if defined UTILS_EXPORTS || defined OpUtil_EXPORTS +#define UTILS_EXPORT __declspec(dllexport) +#else +#define UTILS_EXPORT __declspec(dllimport) +#undef LOCALIZED +#define LOCALIZED(message) #message +#endif #else -# define UTILS_EXPORT +#define UTILS_EXPORT #endif class SALOME_Exception; -UTILS_EXPORT std::ostream& operator<<( std::ostream&, const SALOME_Exception& ); +UTILS_EXPORT std::ostream &operator<<(std::ostream &, const SALOME_Exception &); -UTILS_EXPORT const char *makeText( const char *text, const char *fileName, const unsigned int lineNumber ); +UTILS_EXPORT std::string makeText(const char *text, const char *fileName, const unsigned int lineNumber); class UTILS_EXPORT SALOME_Exception : public std::exception { +protected: + std::string _text; +public: + SALOME_Exception() = delete; + SALOME_Exception(const std::string& text):_text(text) { } + SALOME_Exception(const char *text, const char *fileName = nullptr, const unsigned int lineNumber = 0); + virtual ~SALOME_Exception() noexcept; + UTILS_EXPORT friend std::ostream &operator<<(std::ostream &os, const SALOME_Exception &ex); + virtual const char *what(void) const noexcept; +}; -private : - SALOME_Exception( void ); - -protected : - const char* _text ; // non constant pointer but read only char variable - -public : - SALOME_Exception( const char *text, const char *fileName=0, const unsigned int lineNumber=0 ); - SALOME_Exception( const SALOME_Exception &ex ); - virtual ~SALOME_Exception() noexcept; - UTILS_EXPORT friend std::ostream & operator<<( std::ostream &os , const SALOME_Exception &ex ); - virtual const char *what( void ) const noexcept; -} ; - - -#endif /* #if !defined( __Utils_SALOME_Exception_hxx__ ) */ +#define THROW_SALOME_EXCEPTION(text) \ +{ \ + std::ostringstream oss; oss << text; \ + throw SALOME_Exception(oss.str()); \ +}