-// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
#include "SALOME_ModuleCatalog_impl.hxx"
#include "SALOME_ModuleCatalog_Acomponent_impl.hxx"
#include "SALOME_ModuleCatalog_Handler.hxx"
+#include "SALOME_Fake_NamingService.hxx"
+
#include <libxml/parser.h>
#include <fstream>
#include <map>
#include "utilities.h"
+#include <Basics_Utils.hxx>
+
#ifdef WIN32
# include <process.h>
+# include <windows.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <io.h>
+#include <stdio.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <wchar.h>
#else
# include <unistd.h>
#endif
-#ifdef _DEBUG_
-static int MYDEBUG = 0;
-#else
-static int MYDEBUG = 0;
-#endif
static const char* SEPARATOR = "::";
static const char* OLD_SEPARATOR = ":";
+const char SALOME_ModuleCatalogImpl::ENTRY_IN_NS[] = "/Kernel/ModulCatalog";
+
+SALOME_ModuleCatalog::ModuleCatalog_ptr KERNEL::getModuleComponentServantSA(const char *listOfCatalogs)
+{
+ static SALOME_ModuleCatalog::ModuleCatalog_var moduleCata;
+ if(CORBA::is_nil(moduleCata))
+ {
+ CORBA::ORB_ptr orb = KERNEL::getORB();
+ constexpr int NB_OF_ELT_IN_CMD = 3;
+ char *argv[NB_OF_ELT_IN_CMD] = {"SALOME_ModuleCatalog_Server","-common",nullptr};
+ if(listOfCatalogs)
+ argv[2] = const_cast<char*>(listOfCatalogs);
+ SALOME_ModuleCatalogImpl *servant = new SALOME_ModuleCatalogImpl(NB_OF_ELT_IN_CMD,argv,orb);
+ moduleCata = servant->_this();
+ SALOME_Fake_NamingService NS;
+ NS.Register(moduleCata,SALOME_ModuleCatalogImpl::ENTRY_IN_NS);
+ }
+ return SALOME_ModuleCatalog::ModuleCatalog::_duplicate(moduleCata);
+}
std::list<std::string> splitStringToList(const std::string& theString, const std::string& theSeparator)
{
std::list<std::string> aList;
- int sepLen = theSeparator.length();
- int startPos = 0, sepPos = theString.find(theSeparator, startPos);
+ size_t sepLen = theSeparator.length();
+ size_t startPos = 0, sepPos = theString.find(theSeparator, startPos);
while (1)
{
\param pathlist ParserPathPrefixes arguments
\param typeMap ParserTypes arguments
*/
- virtual void _parse_xml_file(const char* file,
- ParserComponents & modulelist,
- ParserPathPrefixes & pathlist,
- ParserTypes& typeMap,
- TypeList& typeList);
+ void _parse_xml_file(const char* file,
+ ParserComponents & modulelist,
+ ParserPathPrefixes & pathlist,
+ ParserTypes& typeMap,
+ TypeList& typeList);
//! method to find component in the parser list
/*!
//! method to create the path prefix structures from the catalog parsing
/*!
- \param pathes ParserPathPrefixes arguments
- \return the pathes
+ \param paths ParserPathPrefixes arguments
+ \return the paths
*/
void duplicate(ParserPathPrefixes & p_out, const ParserPathPrefixes & P_in);
//! method to verify path prefix content
/*!
\param pathlist ListOfParserPathPrefix arguments
- \return true if verfication is OK
+ \return true if verification is OK
*/
- virtual bool _verify_path_prefix(ParserPathPrefixes & pathlist);
+ bool _verify_path_prefix(ParserPathPrefixes & pathlist);
// Theses variables will contain the path to the general and personal catalogs
char* _general_path;
char* _personal_path;
- // These variables will contain the informations on the general common catalog
+ // These variables will contain the information on the general common catalog
ParserComponents _general_module_list ;
ParserPathPrefixes _general_path_list ;
ParserTypes _typeMap;
TypeList _typeList;
- // These variables will contain the informations on the personal catalog
+ // These variables will contain the information on the personal catalog
ParserComponents _personal_module_list ;
ParserPathPrefixes _personal_path_list ;
SALOME_ModuleCatalogImpl::SALOME_ModuleCatalogImpl(int argc, char** argv, CORBA::ORB_ptr orb) : _orb(orb)
{
myPrivate = new Private;
- if(MYDEBUG) MESSAGE("Catalog creation");
+ MESSAGE("Catalog creation");
/* Init libxml */
xmlInitParser();
// Parse the arguments given at server run
if (!_parseArguments(argc, argv,&myPrivate->_general_path,&myPrivate->_personal_path))
- if(MYDEBUG) MESSAGE( "Error while argument parsing" );
+ MESSAGE( "Error while argument parsing" );
// Test existency of files
if (myPrivate->_general_path == NULL)
{
- if(MYDEBUG) MESSAGE( "Error the general catalog should be indicated" );
+ MESSAGE( "Error the general catalog should be indicated" );
}
else
{
// Verification of _general_path_list content
if (!myPrivate->_verify_path_prefix(myPrivate->_general_path_list)) {
- if(MYDEBUG) MESSAGE( "Error while parsing the general path list, "
- "differents paths are associated to the same computer,"
- "the first one will be choosen");
+ MESSAGE( "Error while parsing the general path list, "
+ "different paths are associated to the same computer,"
+ "the first one will be chosen");
} else {
- if(MYDEBUG) MESSAGE("General path list OK");
+ MESSAGE("General path list OK");
}
if (myPrivate->_personal_path != NULL) {
// Verification of _general_path_list content
if(!myPrivate->_verify_path_prefix(myPrivate->_personal_path_list)){
- if(MYDEBUG) MESSAGE("Error while parsing the personal path list, "
- "differents paths are associated to the same computer, "
- "the first one will be choosen" );
+ MESSAGE("Error while parsing the personal path list, "
+ "different paths are associated to the same computer, "
+ "the first one will be chosen" );
}else {
- if(MYDEBUG) MESSAGE("Personal path list OK");
+ MESSAGE("Personal path list OK");
}
}else
- if(MYDEBUG) MESSAGE("No personal catalog indicated or error while "
+ MESSAGE("No personal catalog indicated or error while "
"opening the personal catalog");
}
}
//----------------------------------------------------------------------
SALOME_ModuleCatalogImpl::~SALOME_ModuleCatalogImpl()
{
- if(MYDEBUG) MESSAGE("Catalog Destruction");
+ MESSAGE("Catalog Destruction");
delete myPrivate;
}
SALOME_ModuleCatalog::ListOfTypeDefinition* SALOME_ModuleCatalogImpl::GetTypes()
{
SALOME_ModuleCatalog::ListOfTypeDefinition_var type_list = new SALOME_ModuleCatalog::ListOfTypeDefinition();
- type_list->length(myPrivate->_typeList.size());
+ type_list->length((CORBA::ULong)myPrivate->_typeList.size());
for (unsigned int ind = 0 ; ind < myPrivate->_typeList.size() ; ind++)
{
type_list[ind].kind=SALOME_ModuleCatalog::Objref;
type_list[ind].id=CORBA::string_dup(myPrivate->_typeList[ind].id.c_str());
//bases
- type_list[ind].bases.length(myPrivate->_typeList[ind].bases.size());
+ type_list[ind].bases.length((CORBA::ULong)myPrivate->_typeList[ind].bases.size());
std::vector<std::string>::const_iterator miter;
miter=myPrivate->_typeList[ind].bases.begin();
int n_memb=0;
{
type_list[ind].kind=SALOME_ModuleCatalog::Struc;
//members
- type_list[ind].members.length(myPrivate->_typeList[ind].members.size());
+ type_list[ind].members.length((CORBA::ULong)myPrivate->_typeList[ind].members.size());
std::vector< std::pair<std::string,std::string> >::const_iterator miter;
miter=myPrivate->_typeList[ind].members.begin();
// Function : GetPathPrefix
// Purpose : get the PathPrefix of a computer
//----------------------------------------------------------------------
-char *
+char*
SALOME_ModuleCatalogImpl::GetPathPrefix(const char* machinename) {
- if(MYDEBUG) MESSAGE("Begin of GetPathPrefix");
+ MESSAGE("Begin of GetPathPrefix");
// Variables initialisation
- char* _path = NULL;
- bool _find = false ;
+ std::string _path;
+ bool _find = false;
// Parse all the path prefixes
// looking for the wanted computer
- for (unsigned int ind = 0 ; ind < myPrivate->_personal_path_list.size() ; ind++)
+ for (unsigned int ind = 0; ind < myPrivate->_personal_path_list.size() && !_find; ind++)
+ {
+ for (unsigned int ind1 = 0; ind1 < myPrivate->_personal_path_list[ind].listOfComputer.size() && !_find; ind1++)
{
- for (unsigned int ind1 = 0 ; ind1 < myPrivate->_personal_path_list[ind].listOfComputer.size() ; ind1++)
- {
- if (strcmp(machinename, myPrivate->_personal_path_list[ind].listOfComputer[ind1].c_str()) == 0)
- {
- _find = true ;
- // Wanted computer
- // affect the path to be returned
- const char* _temp = myPrivate->_personal_path_list[ind].path.c_str() ;
- _path = new char[strlen(_temp)+1];
- strcpy(_path,_temp);
- }
- }
+ if ( myPrivate->_personal_path_list[ind].listOfComputer[ind1] == machinename )
+ {
+ _find = true;
+ // Wanted computer
+ // affect the path to be returned
+ _path = myPrivate->_personal_path_list[ind].path;
+ }
}
+ }
- if (!_find)
+ for (unsigned int ind = 0; ind < myPrivate->_general_path_list.size() && !_find; ind++)
+ {
+ for (unsigned int ind1 = 0; ind1 < myPrivate->_general_path_list[ind].listOfComputer.size() && !_find; ind1++)
{
- for (unsigned int ind = 0 ; ind < myPrivate->_general_path_list.size() ; ind++)
+ if (myPrivate->_general_path_list[ind].listOfComputer[ind1] == machinename)
{
- for (unsigned int ind1 = 0 ; ind1 < myPrivate->_general_path_list[ind].listOfComputer.size() ; ind1++)
- {
- if (strcmp(machinename, myPrivate->_general_path_list[ind].listOfComputer[ind1].c_str()) == 0)
- {
- _find = true ;
- // Wanted computer
- // affect the path to be returned
- const char* _temp = myPrivate->_general_path_list[ind].path.c_str() ;
- _path = new char[strlen(_temp)+1];
- strcpy(_path,_temp);
- }
- }
+ _find = true;
+ // Wanted computer
+ // affect the path to be returned
+ _path = myPrivate->_general_path_list[ind].path;
}
}
-
- return _path;
+ }
+ return CORBA::string_dup(_path.c_str()) ;
}
//----------------------------------------------------------------------
SALOME_ModuleCatalog::ListOfComponents*
SALOME_ModuleCatalogImpl::GetComponentList()
{
- if(MYDEBUG) MESSAGE("Begin of GetComponentList");
+ MESSAGE("Begin of GetComponentList");
SALOME_ModuleCatalog::ListOfComponents_var _list_components =
new SALOME_ModuleCatalog::ListOfComponents;
- _list_components->length(myPrivate->_personal_module_list.size());
+ _list_components->length((CORBA::ULong)myPrivate->_personal_module_list.size());
// All the components defined in the personal catalog are taken
for(unsigned int ind=0; ind < myPrivate->_personal_module_list.size();ind++){
_list_components[ind]=(myPrivate->_personal_module_list[ind].name).c_str();
- if(MYDEBUG) SCRUTE(_list_components[ind]) ;
+ SCRUTE(_list_components[ind]) ;
}
- int indice = myPrivate->_personal_module_list.size() ;
+ size_t indice = myPrivate->_personal_module_list.size();
bool _find = false;
// The components in the general catalog are taken only if they're
_find = true;
}
if(!_find){
- if(MYDEBUG) MESSAGE("A new component " << myPrivate->_general_module_list[ind].name
+ MESSAGE("A new component " << myPrivate->_general_module_list[ind].name
<< " has to be to added in the list");
- _list_components->length(indice+1);
+ _list_components->length((CORBA::ULong)indice+1);
// The component is not already defined => has to be taken
- _list_components[indice]=(myPrivate->_general_module_list[ind].name).c_str();
- if(MYDEBUG) SCRUTE(_list_components[indice]) ;
+ _list_components[(CORBA::ULong)indice]=(myPrivate->_general_module_list[ind].name).c_str();
+ SCRUTE(_list_components[(CORBA::ULong)indice]) ;
indice++;
}else{
- if(MYDEBUG) MESSAGE("The component " <<myPrivate->_general_module_list[ind].name
+ MESSAGE("The component " <<myPrivate->_general_module_list[ind].name
<< " was already defined in the personal catalog") ;
}
}
- if(MYDEBUG) MESSAGE ( "End of GetComponentList" );
+ MESSAGE("End of GetComponentList");
return _list_components._retn();
}
SALOME_ModuleCatalog::ListOfIAPP_Affich*
SALOME_ModuleCatalogImpl::GetComponentIconeList()
{
- if(MYDEBUG) MESSAGE("Begin of GetComponentIconeList");
+ MESSAGE("Begin of GetComponentIconeList");
SALOME_ModuleCatalog::ListOfIAPP_Affich_var _list_components_icone =
new SALOME_ModuleCatalog::ListOfIAPP_Affich;
- _list_components_icone->length(myPrivate->_personal_module_list.size());
+ _list_components_icone->length((CORBA::ULong)myPrivate->_personal_module_list.size());
// All the components defined in the personal catalog are taken
for(unsigned int ind=0; ind < myPrivate->_personal_module_list.size();ind++){
_list_components_icone[ind].moduleicone=(myPrivate->_personal_module_list[ind].icon).c_str();
_list_components_icone[ind].moduleversion=(myPrivate->_personal_module_list[ind].version).c_str();
_list_components_icone[ind].modulecomment=(myPrivate->_personal_module_list[ind].comment).c_str();
- //if(MYDEBUG) SCRUTE(_list_components_icone[ind].modulename);
- //if(MYDEBUG) SCRUTE(_list_components_icone[ind].moduleicone);
+ //SCRUTE(_list_components_icone[ind].modulename);
+ //SCRUTE(_list_components_icone[ind].moduleicone);
}
- int indice = myPrivate->_personal_module_list.size() ;
+ size_t indice = myPrivate->_personal_module_list.size();
bool _find = false;
// The components in the general catalog are taken only if they're
_find = true;
}
if(!_find){
- // if(MYDEBUG) MESSAGE("A new component " << _general_module_list[ind].name << " has to be to added in the list");
- _list_components_icone->length(indice+1);
+ //MESSAGE("A new component " << _general_module_list[ind].name << " has to be to added in the list");
+ _list_components_icone->length((CORBA::ULong)indice+1);
// The component is not already defined => has to be taken
- _list_components_icone[indice].modulename=myPrivate->_general_module_list[ind].name.c_str();
- _list_components_icone[indice].moduleusername=myPrivate->_general_module_list[ind].username.c_str();
- _list_components_icone[indice].moduleicone=myPrivate->_general_module_list[ind].icon.c_str();
- _list_components_icone[indice].moduleversion=myPrivate->_general_module_list[ind].version.c_str();
- _list_components_icone[indice].modulecomment=myPrivate->_general_module_list[ind].comment.c_str();
- //if(MYDEBUG) SCRUTE(_list_components_icone[indice].modulename) ;
- //if(MYDEBUG) SCRUTE(_list_components_icone[indice].moduleicone);
+ _list_components_icone[(CORBA::ULong)indice].modulename=myPrivate->_general_module_list[ind].name.c_str();
+ _list_components_icone[(CORBA::ULong)indice].moduleusername=myPrivate->_general_module_list[ind].username.c_str();
+ _list_components_icone[(CORBA::ULong)indice].moduleicone=myPrivate->_general_module_list[ind].icon.c_str();
+ _list_components_icone[(CORBA::ULong)indice].moduleversion=myPrivate->_general_module_list[ind].version.c_str();
+ _list_components_icone[(CORBA::ULong)indice].modulecomment=myPrivate->_general_module_list[ind].comment.c_str();
+ //SCRUTE(_list_components_icone[(CORBA::ULong)indice].modulename) ;
+ //SCRUTE(_list_components_icone[(CORBA::ULong)indice].moduleicone);
indice++;
}
// else
- //if(MYDEBUG) MESSAGE("The component " <<_general_module_list[ind].name << " was already defined in the personal catalog");
+ //MESSAGE("The component " <<_general_module_list[ind].name << " was already defined in the personal catalog");
}
return _list_components_icone._retn() ;
SALOME_ModuleCatalog::ListOfComponents*
SALOME_ModuleCatalogImpl::GetTypedComponentList(SALOME_ModuleCatalog::ComponentType component_type)
{
- if(MYDEBUG) MESSAGE("Begin of GetTypedComponentList");
+ MESSAGE("Begin of GetTypedComponentList");
SALOME_ModuleCatalog::ListOfComponents_var _list_typed_component =
new SALOME_ModuleCatalog::ListOfComponents;
int _j = 0;
_list_typed_component->length(0);
// Transform SALOME_ModuleCatalog::ComponentType in ParserComponentType
- ParserComponentType _temp_component_type;
+ ParserComponentType _temp_component_type = OTHER;
switch(component_type){
case SALOME_ModuleCatalog::GEOM:
_temp_component_type = GEOM ;
{
_list_typed_component->length(_j + 1);
_list_typed_component[_j] = myPrivate->_personal_module_list[ind].name.c_str();
- //if(MYDEBUG) SCRUTE(_list_typed_component[_j]);
+ //SCRUTE(_list_typed_component[_j]);
_j++;
}
}
}
if (!_find)
{
- //if(MYDEBUG) MESSAGE("A new component " << _general_module_list[ind].name << " has to be to added in the list");
+ //MESSAGE("A new component " << _general_module_list[ind].name << " has to be to added in the list");
_list_typed_component->length(indice+1);
// The component is not already defined => has to be taken
_list_typed_component[indice]=(myPrivate->_general_module_list[ind].name).c_str();
- //if(MYDEBUG) SCRUTE(_list_typed_component[indice]) ;
+ //SCRUTE(_list_typed_component[indice]) ;
indice++;
}
//else
- //if(MYDEBUG) MESSAGE("The component " <<_general_module_list[ind].name << " was already defined in the personal catalog") ;
+ //MESSAGE("The component " <<_general_module_list[ind].name << " was already defined in the personal catalog") ;
}
}
else {
// Not found in the personal catalog and in the general catalog
// return NULL object
- if(MYDEBUG) MESSAGE("Component with name " << name
+ MESSAGE("Component with name " << name
<< " not found in catalog");
}
void SALOME_ModuleCatalogImpl::shutdown()
{
if (!CORBA::is_nil(_orb)) _orb->shutdown(0);
-};
+}
{
if (name.compare(_personal_module_list[ind].name) == 0)
{
- if(MYDEBUG) MESSAGE("Component named " << name
+ MESSAGE("Component named " << name
<< " found in the personal catalog");
C_parser = &(_personal_module_list[ind]);
break;
{
if (name.compare(_general_module_list[ind].name) == 0)
{
- // if(MYDEBUG) MESSAGE("Component named " << name
+ //MESSAGE("Component named " << name
// << " found in the general catalog");
C_parser = &(_general_module_list[ind]);
break;
ParserTypes& typeMap,
TypeList& typeList)
{
- if(MYDEBUG) BEGIN_OF("_parse_xml_file");
- if(MYDEBUG) SCRUTE(file);
+ BEGIN_OF("_parse_xml_file");
+ SCRUTE(file);
//Local path and module list for the file to parse
ParserPathPrefixes _pathList;
ParserComponents _moduleList;
SALOME_ModuleCatalog_Handler* handler = new SALOME_ModuleCatalog_Handler(_pathList,_moduleList,typeMap,typeList);
-
+#if defined(WIN32)
+ const wchar_t* w_file = Kernel_Utils::utf8_decode(file);
+ FILE* aFile = _wfopen(w_file, L"r");
+#else
FILE* aFile = fopen(file, "r");
-
+#endif
+
if (aFile != NULL)
{
xmlDocPtr aDoc = xmlReadFile(file, NULL, 0);
{
C_corba.name = CORBA::string_dup(C_parser.name.c_str());
C_corba.username = CORBA::string_dup(C_parser.username.c_str());
- C_corba.multistudy = C_parser.multistudy;
C_corba.icon = CORBA::string_dup(C_parser.icon.c_str());
C_corba.type = ComponentTypeConvert[C_parser.type];
if(C_parser.implementationType == "EXE")
C_corba.implementationType=SALOME_ModuleCatalog::SO;
C_corba.implname = CORBA::string_dup(C_parser.implementationName.c_str());
- unsigned int _length = C_parser.interfaces.size();
- C_corba.interfaces.length(_length);
+ size_t _length = C_parser.interfaces.size();
+ C_corba.interfaces.length((CORBA::ULong)_length);
for (unsigned int ind = 0; ind < _length; ind++)
duplicate(C_corba.interfaces[ind], C_parser.interfaces[ind]);
I_corba.interfacename = CORBA::string_dup(I_parser.name.c_str());
// duplicate service list
- unsigned int _length = I_parser.services.size();
- // if(MYDEBUG) SCRUTE(_length);
+ size_t _length = I_parser.services.size();
+ // SCRUTE(_length);
// I_corba.interfaceservicelist
// = new SALOME_ModuleCatalog::ListOfInterfaceService;
- I_corba.interfaceservicelist.length(_length);
+ I_corba.interfaceservicelist.length((CORBA::ULong)_length);
for (unsigned int ind1 = 0; ind1 < _length ; ind1 ++)
duplicate(I_corba.interfaceservicelist[ind1],
S_corba.TypeOfNode = S_parser.typeOfNode;
- unsigned int _length;
+ size_t _length;
// duplicate in Parameters
_length = S_parser.inParameters.size();
- S_corba.ServiceinParameter.length(_length);
+ S_corba.ServiceinParameter.length((CORBA::ULong)_length);
for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
duplicate(S_corba.ServiceinParameter[ind2],
// duplicate out Parameters
_length = S_parser.outParameters.size();
- S_corba.ServiceoutParameter.length(_length);
+ S_corba.ServiceoutParameter.length((CORBA::ULong)_length);
for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
duplicate(S_corba.ServiceoutParameter[ind2],
// duplicate in DataStreamParameters
_length = S_parser.inDataStreamParameters.size();
- S_corba.ServiceinDataStreamParameter.length(_length);
+ S_corba.ServiceinDataStreamParameter.length((CORBA::ULong)_length);
for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
duplicate(S_corba.ServiceinDataStreamParameter[ind2],
// duplicate out DataStreamParameters
_length = S_parser.outDataStreamParameters.size();
- // if(MYDEBUG) SCRUTE(_length);
- S_corba.ServiceoutDataStreamParameter.length(_length);
+ // SCRUTE(_length);
+ S_corba.ServiceoutDataStreamParameter.length((CORBA::ULong)_length);
for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
duplicate(S_corba.ServiceoutDataStreamParameter[ind2],
// duplicate parameter dependency
- if(MYDEBUG) SCRUTE(P_parser.dependency);
+ SCRUTE(P_parser.dependency);
P_corba.Parameterdependency = SALOME_ModuleCatalog::DATASTREAM_UNDEFINED;
for (it_dep = DataStreamDepConvert.begin();
it_dep != DataStreamDepConvert.end();
break;
}
- if(MYDEBUG) SCRUTE(P_corba.Parameterdependency);
+ SCRUTE(P_corba.Parameterdependency);
}
//----------------------------------------------------------------------
{
if(_machine_list[ind].compare(_machine_list[ind1]) == 0)
{
- if(MYDEBUG) MESSAGE( "The computer " << _machine_list[ind] << " is indicated more than once in the path list");
+ MESSAGE( "The computer " << _machine_list[ind] << " is indicated more than once in the path list");
_return_value = false;
}
}