X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleCatalog%2FSALOME_ModuleCatalog_impl.cxx;h=8f98f810e7c8dd78e48c921dbad7438c49b8e4e5;hb=f191001deb29798193fe252df39a5b559dc1c393;hp=7ba1b29f9539881e57c8e1b65380afcdcdce7c0f;hpb=1f742af859d50d34c63f9dc02f9a705089bf060e;p=modules%2Fkernel.git diff --git a/src/ModuleCatalog/SALOME_ModuleCatalog_impl.cxx b/src/ModuleCatalog/SALOME_ModuleCatalog_impl.cxx index 7ba1b29f9..8f98f810e 100644 --- a/src/ModuleCatalog/SALOME_ModuleCatalog_impl.cxx +++ b/src/ModuleCatalog/SALOME_ModuleCatalog_impl.cxx @@ -1,26 +1,26 @@ -// SALOME ModuleCatalog : implementation of ModuleCatalog server which parsers xml description of modules +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // -// 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 : webmaster.salome@opencascade.org +// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// SALOME ModuleCatalog : implementation of ModuleCatalog server which parsers xml description of modules // File : SALOME_ModuleCatalog_impl.cxx // Author : Estelle Deville // Module : SALOME @@ -28,14 +28,51 @@ // #include "SALOME_ModuleCatalog_impl.hxx" #include "SALOME_ModuleCatalog_Acomponent_impl.hxx" +#include #include #include +#include "utilities.h" + +#ifdef WIN32 +# include +#else +# include +#endif + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + +static const char* SEPARATOR = "::"; +static const char* OLD_SEPARATOR = ":"; -#include -#include -using namespace std; -static const char* SEPARATOR = ":"; +std::list splitStringToList(const std::string& theString, const std::string& theSeparator) +{ + std::list aList; + + int sepLen = theSeparator.length(); + int startPos = 0, sepPos = theString.find(theSeparator, startPos); + + while (1) + { + std::string anItem ; + if(sepPos != std::string::npos) + anItem = theString.substr(startPos, sepPos - startPos); + else + anItem = theString.substr(startPos); + if (anItem.length() > 0) + aList.push_back(anItem); + if(sepPos == std::string::npos) + break; + startPos = sepPos + sepLen; + sepPos = theString.find(theSeparator, startPos); + } + + return aList; +} //---------------------------------------------------------------------- // Function : SALOME_ModuleCatalogImpl @@ -43,7 +80,9 @@ static const char* SEPARATOR = ":"; //---------------------------------------------------------------------- SALOME_ModuleCatalogImpl::SALOME_ModuleCatalogImpl(int argc, char** argv, CORBA::ORB_ptr orb) : _orb(orb) { - MESSAGE("Catalog creation"); + if(MYDEBUG) MESSAGE("Catalog creation"); + /* Init libxml */ + xmlInitParser(); // Conversion rules for component types ComponentTypeConvert[GEOM] @@ -63,20 +102,7 @@ SALOME_ModuleCatalogImpl::SALOME_ModuleCatalogImpl(int argc, char** argv, CORBA: ComponentTypeConvert[OTHER] = SALOME_ModuleCatalog::OTHER; - // Conversion rules for datastream parameters type and dependency - DataStreamTypeConvert["UNKNOWN"] - = SALOME_ModuleCatalog::DATASTREAM_UNKNOWN; - DataStreamTypeConvert["INTEGER"] - = SALOME_ModuleCatalog::DATASTREAM_INTEGER; - DataStreamTypeConvert["FLOAT"] - = SALOME_ModuleCatalog::DATASTREAM_FLOAT; - DataStreamTypeConvert["DOUBLE"] - = SALOME_ModuleCatalog::DATASTREAM_DOUBLE; - DataStreamTypeConvert["STRING"] - = SALOME_ModuleCatalog::DATASTREAM_STRING; - DataStreamTypeConvert["BOOLEAN"] - = SALOME_ModuleCatalog::DATASTREAM_BOOLEAN; - + // Conversion rules for datastream parameters dependency DataStreamDepConvert["UNDEFINED"] = SALOME_ModuleCatalog::DATASTREAM_UNDEFINED; DataStreamDepConvert["T"] @@ -93,57 +119,78 @@ SALOME_ModuleCatalogImpl::SALOME_ModuleCatalogImpl(int argc, char** argv, CORBA: // Parse the arguments given at server run if (!_parseArguments(argc, argv,&_general_path,&_personal_path)) - MESSAGE( "Error while argument parsing" ); + if(MYDEBUG) MESSAGE( "Error while argument parsing" ); // Test existency of files if (_general_path == NULL) - MESSAGE( "Error the general catalog should be indicated" ) + { + if(MYDEBUG) MESSAGE( "Error the general catalog should be indicated" ); + } else + { + // Affect the _general_module_list and _general_path_list members + // with the common catalog + + std::list dirList; + +#ifdef WIN32 + dirList = splitStringToList(_general_path, SEPARATOR); +#else + //check for new format + bool isNew = (std::string( _general_path ).find(SEPARATOR) != std::string::npos); + if ( isNew ) { + //using new format + dirList = splitStringToList(_general_path, SEPARATOR); + } else { + //support old format + dirList = splitStringToList(_general_path, OLD_SEPARATOR); + } +#endif + + for (std::list::iterator iter = dirList.begin(); iter != dirList.end(); iter++) { - // Affect the _general_module_list and _general_path_list members - // with the common catalog - - QStringList dirList - = QStringList::split( SEPARATOR, _general_path, - false ); // skip empty entries - - for ( int i = 0; i < dirList.count(); i++ ) { - QFileInfo fileInfo( dirList[ i ] ); - if ( fileInfo.isFile() && fileInfo.exists() ) { - _parse_xml_file(fileInfo.filePath(), - _general_module_list, - _general_path_list); - } - } + std::string aPath = (*iter); + //remove inverted commas from filename + while (aPath.find('\"') != std::string::npos) + aPath.erase(aPath.find('\"'), 1); + + _parse_xml_file(aPath.c_str(), + _general_module_list, + _general_path_list, + _typeMap, + _typeList); + } - // Verification of _general_path_list content - if(!_verify_path_prefix(_general_path_list)) - MESSAGE( "Error while parsing the general path list, " - "differents paths are associated to the same computer," - "the first one will be choosen") - else - MESSAGE("General path list OK"); - - if(_personal_path != NULL) - { - // Initialize the _personal_module_list and - // _personal_path_list members with the personal catalog files - _parse_xml_file(_personal_path, - _personal_module_list, - _personal_path_list); - - // Verification of _general_path_list content - if(!_verify_path_prefix(_personal_path_list)) - MESSAGE("Error while parsing the personal path list, " - "differents paths are associated to the same computer, " - "the first one will be choosen" ) - else - MESSAGE("Personal path list OK"); - } - else - MESSAGE("No personal catalog indicated or error while " - "opening the personal catalog"); + // Verification of _general_path_list content + if (!_verify_path_prefix(_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"); + } else { + if(MYDEBUG) MESSAGE("General path list OK"); } + + if (_personal_path != NULL) { + // Initialize the _personal_module_list and + // _personal_path_list members with the personal catalog files + _parse_xml_file(_personal_path, + _personal_module_list, + _personal_path_list, + _typeMap, + _typeList); + + // Verification of _general_path_list content + if(!_verify_path_prefix(_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" ); + }else { + if(MYDEBUG) MESSAGE("Personal path list OK"); + } + }else + if(MYDEBUG) MESSAGE("No personal catalog indicated or error while " + "opening the personal catalog"); + } } //---------------------------------------------------------------------- @@ -152,10 +199,79 @@ SALOME_ModuleCatalogImpl::SALOME_ModuleCatalogImpl(int argc, char** argv, CORBA: //---------------------------------------------------------------------- SALOME_ModuleCatalogImpl::~SALOME_ModuleCatalogImpl() { - MESSAGE("Catalog Destruction"); + if(MYDEBUG) MESSAGE("Catalog Destruction"); } +//! Get the list of all types of the catalog +/*! + * \return the list of types + */ +SALOME_ModuleCatalog::ListOfTypeDefinition* SALOME_ModuleCatalogImpl::GetTypes() +{ + SALOME_ModuleCatalog::ListOfTypeDefinition_var type_list = new SALOME_ModuleCatalog::ListOfTypeDefinition(); + type_list->length(_typeList.size()); + + for (unsigned int ind = 0 ; ind < _typeList.size() ; ind++) + { + //no real need to call string_dup, omniorb calls it on operator= (const char *) but it is safer + type_list[ind].name=CORBA::string_dup(_typeList[ind].name.c_str()); + type_list[ind].kind=SALOME_ModuleCatalog::NONE; + if(_typeList[ind].kind=="double") + type_list[ind].kind=SALOME_ModuleCatalog::Dble; + else if(_typeList[ind].kind=="int") + type_list[ind].kind=SALOME_ModuleCatalog::Int; + else if(_typeList[ind].kind=="bool") + type_list[ind].kind=SALOME_ModuleCatalog::Bool; + else if(_typeList[ind].kind=="string") + type_list[ind].kind=SALOME_ModuleCatalog::Str; + else if(_typeList[ind].kind=="objref") + { + type_list[ind].kind=SALOME_ModuleCatalog::Objref; + type_list[ind].id=CORBA::string_dup(_typeList[ind].id.c_str()); + //bases + type_list[ind].bases.length(_typeList[ind].bases.size()); + std::vector::const_iterator miter; + miter=_typeList[ind].bases.begin(); + int n_memb=0; + while(miter != _typeList[ind].bases.end()) + { + type_list[ind].bases[n_memb]=CORBA::string_dup(miter->c_str()); + miter++; + n_memb++; + } + } + else if(_typeList[ind].kind=="sequence") + { + type_list[ind].kind=SALOME_ModuleCatalog::Seq; + type_list[ind].content=CORBA::string_dup(_typeList[ind].content.c_str()); + } + else if(_typeList[ind].kind=="array") + { + type_list[ind].kind=SALOME_ModuleCatalog::Array; + type_list[ind].content=CORBA::string_dup(_typeList[ind].content.c_str()); + } + else if(_typeList[ind].kind=="struct") + { + type_list[ind].kind=SALOME_ModuleCatalog::Struc; + //members + type_list[ind].members.length(_typeList[ind].members.size()); + + std::vector< std::pair >::const_iterator miter; + miter=_typeList[ind].members.begin(); + int n_memb=0; + while(miter != _typeList[ind].members.end()) + { + type_list[ind].members[n_memb].name=CORBA::string_dup(miter->first.c_str()); + type_list[ind].members[n_memb].type=CORBA::string_dup(miter->second.c_str()); + n_memb++; + miter++; + } + } + } + return type_list._retn(); +} + //---------------------------------------------------------------------- // Function : GetComputerList // Purpose : get a computer list @@ -174,7 +290,7 @@ SALOME_ModuleCatalogImpl::GetComputerList() //---------------------------------------------------------------------- char * SALOME_ModuleCatalogImpl::GetPathPrefix(const char* machinename) { - MESSAGE("Begin of GetPathPrefix") + if(MYDEBUG) MESSAGE("Begin of GetPathPrefix"); // Variables initialisation char* _path = NULL; bool _find = false ; @@ -184,17 +300,17 @@ SALOME_ModuleCatalogImpl::GetPathPrefix(const char* machinename) { for (unsigned int ind = 0 ; ind < _personal_path_list.size() ; ind++) { for (unsigned int ind1 = 0 ; ind1 < _personal_path_list[ind].listOfComputer.size() ; ind1++) - { - if (strcmp(machinename, _personal_path_list[ind].listOfComputer[ind1].c_str()) == 0) - { - _find = true ; - // Wanted computer - // affect the path to be returned - const char* _temp = _personal_path_list[ind].path.c_str() ; - _path = new char[strlen(_temp)+1]; - strcpy(_path,_temp); - } - } + { + if (strcmp(machinename, _personal_path_list[ind].listOfComputer[ind1].c_str()) == 0) + { + _find = true ; + // Wanted computer + // affect the path to be returned + const char* _temp = _personal_path_list[ind].path.c_str() ; + _path = new char[strlen(_temp)+1]; + strcpy(_path,_temp); + } + } } if (!_find) @@ -202,17 +318,17 @@ SALOME_ModuleCatalogImpl::GetPathPrefix(const char* machinename) { for (unsigned int ind = 0 ; ind < _general_path_list.size() ; ind++) { for (unsigned int ind1 = 0 ; ind1 < _general_path_list[ind].listOfComputer.size() ; ind1++) - { - if (strcmp(machinename, _general_path_list[ind].listOfComputer[ind1].c_str()) == 0) - { - _find = true ; - // Wanted computer - // affect the path to be returned - const char* _temp = _general_path_list[ind].path.c_str() ; - _path = new char[strlen(_temp)+1]; - strcpy(_path,_temp); - } - } + { + if (strcmp(machinename, _general_path_list[ind].listOfComputer[ind1].c_str()) == 0) + { + _find = true ; + // Wanted computer + // affect the path to be returned + const char* _temp = _general_path_list[ind].path.c_str() ; + _path = new char[strlen(_temp)+1]; + strcpy(_path,_temp); + } + } } } @@ -229,51 +345,47 @@ SALOME_ModuleCatalogImpl::GetPathPrefix(const char* machinename) { SALOME_ModuleCatalog::ListOfComponents* SALOME_ModuleCatalogImpl::GetComponentList() { - MESSAGE("Begin of GetComponentList"); + if(MYDEBUG) MESSAGE("Begin of GetComponentList"); SALOME_ModuleCatalog::ListOfComponents_var _list_components = new SALOME_ModuleCatalog::ListOfComponents; _list_components->length(_personal_module_list.size()); // All the components defined in the personal catalog are taken - for (unsigned int ind=0; ind < _personal_module_list.size();ind++) - { - _list_components[ind]=(_personal_module_list[ind].name).c_str(); - SCRUTE(_list_components[ind]) ; - } + for(unsigned int ind=0; ind < _personal_module_list.size();ind++){ + _list_components[ind]=(_personal_module_list[ind].name).c_str(); + if(MYDEBUG) SCRUTE(_list_components[ind]) ; + } int indice = _personal_module_list.size() ; bool _find = false; // The components in the general catalog are taken only if they're // not defined in the personal catalog - for (unsigned int ind=0; ind < _general_module_list.size();ind++) - { - _find = false; - for (unsigned int ind1=0; ind1 < _personal_module_list.size();ind1++) - { - // searching if the component is already defined in - // the personal catalog - if ((_general_module_list[ind].name.compare(_personal_module_list[ind1].name)) == 0) - _find = true; - } - if (!_find) - { - MESSAGE("A new component " << _general_module_list[ind].name - << " has to be to added in the list"); - _list_components->length(indice+1); - // The component is not already defined => has to be taken - _list_components[indice]=(_general_module_list[ind].name).c_str(); - SCRUTE(_list_components[indice]) ; - - indice++; - } - else - MESSAGE("The component " <<_general_module_list[ind].name - << " was already defined in the personal catalog") ; - } - - MESSAGE ( "End of GetComponentList" ) + for(unsigned int ind=0; ind < _general_module_list.size();ind++){ + _find = false; + for(unsigned int ind1=0; ind1 < _personal_module_list.size();ind1++){ + // searching if the component is already defined in + // the personal catalog + if ((_general_module_list[ind].name.compare(_personal_module_list[ind1].name)) == 0) + _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->length(indice+1); + // The component is not already defined => has to be taken + _list_components[indice]=(_general_module_list[ind].name).c_str(); + if(MYDEBUG) SCRUTE(_list_components[indice]) ; + + indice++; + }else{ + if(MYDEBUG) MESSAGE("The component " <<_general_module_list[ind].name + << " was already defined in the personal catalog") ; + } + } + + if(MYDEBUG) MESSAGE ( "End of GetComponentList" ); return _list_components._retn(); } @@ -288,7 +400,7 @@ SALOME_ModuleCatalogImpl::GetComponentList() SALOME_ModuleCatalog::ListOfIAPP_Affich* SALOME_ModuleCatalogImpl::GetComponentIconeList() { - MESSAGE("Begin of GetComponentIconeList"); + if(MYDEBUG) MESSAGE("Begin of GetComponentIconeList"); SALOME_ModuleCatalog::ListOfIAPP_Affich_var _list_components_icone = new SALOME_ModuleCatalog::ListOfIAPP_Affich; @@ -296,47 +408,47 @@ SALOME_ModuleCatalogImpl::GetComponentIconeList() _list_components_icone->length(_personal_module_list.size()); // All the components defined in the personal catalog are taken - for (unsigned int ind=0; ind < _personal_module_list.size();ind++) - { - _list_components_icone[ind].modulename=(_personal_module_list[ind].name).c_str(); - _list_components_icone[ind].moduleusername=(_personal_module_list[ind].username).c_str(); - _list_components_icone[ind].moduleicone=(_personal_module_list[ind].icon).c_str(); - //SCRUTE(_list_components_icone[ind].modulename); - //SCRUTE(_list_components_icone[ind].moduleicone); - } - + for(unsigned int ind=0; ind < _personal_module_list.size();ind++){ + _list_components_icone[ind].modulename=(_personal_module_list[ind].name).c_str(); + _list_components_icone[ind].moduleusername=(_personal_module_list[ind].username).c_str(); + _list_components_icone[ind].moduleicone=(_personal_module_list[ind].icon).c_str(); + _list_components_icone[ind].moduleversion=(_personal_module_list[ind].version).c_str(); + _list_components_icone[ind].modulecomment=(_personal_module_list[ind].comment).c_str(); + //if(MYDEBUG) SCRUTE(_list_components_icone[ind].modulename); + //if(MYDEBUG) SCRUTE(_list_components_icone[ind].moduleicone); + } + int indice = _personal_module_list.size() ; bool _find = false; // The components in the general catalog are taken only if they're // not defined in the personal catalog - for (unsigned int ind=0; ind < _general_module_list.size();ind++) - { - _find = false; - for (unsigned int ind1=0; ind1 < _personal_module_list.size();ind1++) - { - // searching if the component is aleready defined in - // the personal catalog - if ((_general_module_list[ind].name.compare(_personal_module_list[ind1].name)) == 0) - _find = true; - } - if (!_find) - { - // MESSAGE("A new component " << _general_module_list[ind].name << " has to be to added in the list"); - _list_components_icone->length(indice+1); - // The component is not already defined => has to be taken - _list_components_icone[indice].modulename=_general_module_list[ind].name.c_str(); - _list_components_icone[indice].moduleusername=_general_module_list[ind].username.c_str(); - _list_components_icone[indice].moduleicone=_general_module_list[ind].icon.c_str(); - //SCRUTE(_list_components_icone[indice].modulename) ; - //SCRUTE(_list_components_icone[indice].moduleicone); - - indice++; - } - // else - //MESSAGE("The component " <<_general_module_list[ind].name << " was already defined in the personal catalog"); - } - + for(unsigned int ind=0; ind < _general_module_list.size();ind++){ + _find = false; + for(unsigned int ind1=0; ind1 < _personal_module_list.size();ind1++){ + // searching if the component is aleready defined in + // the personal catalog + if((_general_module_list[ind].name.compare(_personal_module_list[ind1].name)) == 0) + _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); + // The component is not already defined => has to be taken + _list_components_icone[indice].modulename=_general_module_list[ind].name.c_str(); + _list_components_icone[indice].moduleusername=_general_module_list[ind].username.c_str(); + _list_components_icone[indice].moduleicone=_general_module_list[ind].icon.c_str(); + _list_components_icone[indice].moduleversion=_general_module_list[ind].version.c_str(); + _list_components_icone[indice].modulecomment=_general_module_list[ind].comment.c_str(); + //if(MYDEBUG) SCRUTE(_list_components_icone[indice].modulename) ; + //if(MYDEBUG) SCRUTE(_list_components_icone[indice].moduleicone); + + indice++; + } + // else + //if(MYDEBUG) MESSAGE("The component " <<_general_module_list[ind].name << " was already defined in the personal catalog"); + } + return _list_components_icone._retn() ; } @@ -350,7 +462,7 @@ SALOME_ModuleCatalogImpl::GetComponentIconeList() SALOME_ModuleCatalog::ListOfComponents* SALOME_ModuleCatalogImpl::GetTypedComponentList(SALOME_ModuleCatalog::ComponentType component_type) { - MESSAGE("Begin of GetTypedComponentList"); + if(MYDEBUG) MESSAGE("Begin of GetTypedComponentList"); SALOME_ModuleCatalog::ListOfComponents_var _list_typed_component = new SALOME_ModuleCatalog::ListOfComponents; int _j = 0; @@ -389,12 +501,12 @@ SALOME_ModuleCatalogImpl::GetTypedComponentList(SALOME_ModuleCatalog::ComponentT for (unsigned int ind=0; ind < _personal_module_list.size();ind++) { if (_personal_module_list[ind].type == _temp_component_type) - { - _list_typed_component->length(_j + 1); - _list_typed_component[_j] = (_moduleList[ind].name).c_str(); - //SCRUTE(_list_typed_component[_j]) - _j++; - } + { + _list_typed_component->length(_j + 1); + _list_typed_component[_j] = _personal_module_list[ind].name.c_str(); + //if(MYDEBUG) SCRUTE(_list_typed_component[_j]); + _j++; + } } int indice = _list_typed_component->length() ; @@ -407,26 +519,26 @@ SALOME_ModuleCatalogImpl::GetTypedComponentList(SALOME_ModuleCatalog::ComponentT _find = false; if(_general_module_list[ind].type == _temp_component_type) - { - for (unsigned int ind1=0; ind1 < _personal_module_list.size();ind1++) - { - // searching if the component is aleready defined in - // the personal catalog - if ((_general_module_list[ind].name.compare(_personal_module_list[ind1].name)) == 0) - _find = true; - } - if (!_find) - { - //MESSAGE("A new component " << _general_module_list[ind].name << " has to be to added in the list"); + { + for (unsigned int ind1=0; ind1 < _personal_module_list.size();ind1++) + { + // searching if the component is aleready defined in + // the personal catalog + if ((_general_module_list[ind].name.compare(_personal_module_list[ind1].name)) == 0) + _find = true; + } + if (!_find) + { + //if(MYDEBUG) 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]=(_general_module_list[ind].name).c_str(); - //SCRUTE(_list_typed_component[indice]) ; - - indice++; - } - //else - //MESSAGE("The component " <<_general_module_list[ind].name << " was already defined in the personal catalog") ; + // The component is not already defined => has to be taken + _list_typed_component[indice]=(_general_module_list[ind].name).c_str(); + //if(MYDEBUG) SCRUTE(_list_typed_component[indice]) ; + + indice++; + } + //else + //if(MYDEBUG) MESSAGE("The component " <<_general_module_list[ind].name << " was already defined in the personal catalog") ; } } @@ -453,16 +565,16 @@ SALOME_ModuleCatalogImpl::GetComponent(const char* name) std::string s(name); ParserComponent *C_parser = NULL; - ParserPathPrefixes *pp = NULL; + //ParserPathPrefixes *pp = NULL; - SALOME_ModuleCatalog::Acomponent_ptr compo = NULL; - + SALOME_ModuleCatalog::Acomponent_ptr compo + = SALOME_ModuleCatalog::Acomponent::_nil(); C_parser = findComponent(s); if (C_parser) { -// DebugParserComponent(*C_parser); + // DebugParserComponent(*C_parser); - SALOME_ModuleCatalog::Component C_corba; + SALOME_ModuleCatalog::ComponentDef C_corba; duplicate(C_corba, *C_parser); @@ -474,15 +586,14 @@ SALOME_ModuleCatalogImpl::GetComponent(const char* name) else { // Not found in the personal catalog and in the general catalog // return NULL object - MESSAGE("Component with name " << name - << " not found in catalog"); - compo = NULL; + if(MYDEBUG) MESSAGE("Component with name " << name + << " not found in catalog"); } return compo; } -SALOME_ModuleCatalog::Component * +SALOME_ModuleCatalog::ComponentDef * SALOME_ModuleCatalogImpl::GetComponentInfo(const char *name) { std::string s(name); @@ -491,8 +602,8 @@ SALOME_ModuleCatalogImpl::GetComponentInfo(const char *name) if (C_parser) { - SALOME_ModuleCatalog::Component * C_corba - = new SALOME_ModuleCatalog::Component; + SALOME_ModuleCatalog::ComponentDef * C_corba + = new SALOME_ModuleCatalog::ComponentDef; duplicate(*C_corba, *C_parser); return C_corba; } @@ -500,31 +611,48 @@ SALOME_ModuleCatalogImpl::GetComponentInfo(const char *name) return NULL; } +CORBA::Long SALOME_ModuleCatalogImpl::getPID() +{ + return +#ifndef WIN32 + (CORBA::Long)getpid(); +#else + (CORBA::Long)_getpid(); +#endif +} + +void SALOME_ModuleCatalogImpl::ShutdownWithExit() +{ + exit( EXIT_SUCCESS ); +} + ParserComponent * -SALOME_ModuleCatalogImpl::findComponent(const string & name) +SALOME_ModuleCatalogImpl::findComponent(const std::string & name) { ParserComponent * C_parser = NULL; if (!C_parser) for (unsigned int ind=0; ind < _personal_module_list.size();ind++) - if (name.compare(_personal_module_list[ind].name) == 0) - { - MESSAGE("Component named " << name - << " found in the personal catalog"); - C_parser = &(_personal_module_list[ind]); - break; - } + { + if (name.compare(_personal_module_list[ind].name) == 0) + { + if(MYDEBUG) MESSAGE("Component named " << name + << " found in the personal catalog"); + C_parser = &(_personal_module_list[ind]); + break; + } + } if (!C_parser) for (unsigned int ind=0; ind < _general_module_list.size();ind++) { - if (name.compare(_general_module_list[ind].name) == 0) - { - MESSAGE("Component named " << name - << " found in the general catalog"); - C_parser = &(_general_module_list[ind]); - break; - } + if (name.compare(_general_module_list[ind].name) == 0) + { + // if(MYDEBUG) MESSAGE("Component named " << name + // << " found in the general catalog"); + C_parser = &(_general_module_list[ind]); + break; + } } return C_parser; @@ -536,29 +664,45 @@ SALOME_ModuleCatalogImpl::findComponent(const string & name) //---------------------------------------------------------------------- void SALOME_ModuleCatalogImpl::_parse_xml_file(const char* file, - ParserComponents& modulelist, - ParserPathPrefixes& pathList) + ParserComponents& modulelist, + ParserPathPrefixes& pathList, + ParserTypes& typeMap, + TypeList& typeList) { - BEGIN_OF("_parse_xml_file"); - SCRUTE(file); + if(MYDEBUG) BEGIN_OF("_parse_xml_file"); + if(MYDEBUG) SCRUTE(file); - SALOME_ModuleCatalog_Handler* handler = new SALOME_ModuleCatalog_Handler(); - QFile xmlFile(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); - QXmlInputSource source(xmlFile); + FILE* aFile = fopen(file, "r"); - QXmlSimpleReader reader; - reader.setContentHandler( handler ); - reader.setErrorHandler( handler ); - reader.parse( source ); - xmlFile.close(); + if (aFile != NULL) + { + xmlDocPtr aDoc = xmlReadFile(file, NULL, 0); + + if (aDoc != NULL) + handler->ProcessXmlDocument(aDoc); + else + MESSAGE("ModuleCatalog: could not parse file "<::const_iterator it_type; - std::map < std::string, SALOME_ModuleCatalog::DataStreamDependency >::const_iterator it_dep; // duplicate parameter name P_corba.Parametername = CORBA::string_dup(P_parser.name.c_str()); - // doesn't work ??? - // it_type = DataStreamTypeConvert.find(P_parser.type); - // P_corba.Parametertype - // = (it_type == DataStreamTypeConvert.end()) - // ? it_type->second : SALOME_ModuleCatalog::DATASTREAM_UNKNOWN; - - SCRUTE(P_parser.type); - P_corba.Parametertype = SALOME_ModuleCatalog::DATASTREAM_UNKNOWN; - for (it_type = DataStreamTypeConvert.begin(); - it_type != DataStreamTypeConvert.end(); - it_type++) - if (P_parser.type.compare(it_type->first) == 0) { - P_corba.Parametertype = it_type->second; - break; - } - SCRUTE(P_corba.Parametertype); - // duplicate parameter type // doesn't work ??? @@ -741,8 +873,12 @@ void SALOME_ModuleCatalogImpl::duplicate // P_corba.Parametertype // = (it_type == DataStreamTypeConvert.end()) // ? it_type->second : SALOME_ModuleCatalog::DATASTREAM_UNKNOWN; + + P_corba.Parametertype = CORBA::string_dup(P_parser.type.c_str()); + + // duplicate parameter dependency - SCRUTE(P_parser.dependency); + if(MYDEBUG) SCRUTE(P_parser.dependency); P_corba.Parameterdependency = SALOME_ModuleCatalog::DATASTREAM_UNDEFINED; for (it_dep = DataStreamDepConvert.begin(); it_dep != DataStreamDepConvert.end(); @@ -752,7 +888,7 @@ void SALOME_ModuleCatalogImpl::duplicate break; } - SCRUTE(P_corba.Parameterdependency); + if(MYDEBUG) SCRUTE(P_corba.Parameterdependency); } //---------------------------------------------------------------------- @@ -761,7 +897,7 @@ void SALOME_ModuleCatalogImpl::duplicate //---------------------------------------------------------------------- void SALOME_ModuleCatalogImpl::duplicate(ParserPathPrefixes &L_out, - const ParserPathPrefixes &L_in) + const ParserPathPrefixes &L_in) { L_out = L_in; } @@ -777,15 +913,15 @@ bool SALOME_ModuleCatalogImpl::_verify_path_prefix(ParserPathPrefixes & pathList) { bool _return_value = true; - vector _machine_list; + std::vector _machine_list; // Fill a list of all computers indicated in the path list for (unsigned int ind = 0; ind < pathList.size(); ind++) { for (unsigned int ind1 = 0 ; ind1 < pathList[ind].listOfComputer.size(); ind1++) - { - _machine_list.push_back(pathList[ind].listOfComputer[ind1]); - } + { + _machine_list.push_back(pathList[ind].listOfComputer[ind1]); + } } // Parse if a computer name is twice in the list of computers @@ -793,11 +929,11 @@ SALOME_ModuleCatalogImpl::_verify_path_prefix(ParserPathPrefixes & pathList) { for (unsigned int ind1 = ind+1 ; ind1 < _machine_list.size(); ind1++) { - if(_machine_list[ind].compare(_machine_list[ind1]) == 0) - { - MESSAGE( "The computer " << _machine_list[ind] << " is indicated more than once in the path list") - _return_value = false; - } + 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"); + _return_value = false; + } } } return _return_value; @@ -810,8 +946,8 @@ SALOME_ModuleCatalogImpl::_verify_path_prefix(ParserPathPrefixes & pathList) //---------------------------------------------------------------------- bool SALOME_ModuleCatalogImpl::_parseArguments(int argc, char **argv, - char **_general, - char** _personal) + char **_general, + char** _personal) { bool _return_value = true; *_general = NULL; @@ -820,32 +956,30 @@ SALOME_ModuleCatalogImpl::_parseArguments(int argc, char **argv, { if (strcmp(argv[ind],"-help") == 0) - { - INFOS( "Usage: " << argv[0] - << " -common 'path to general catalog' " - " -personal 'path to personal catalog' " - " -ORBInitRef NameService=corbaname::localhost"); - _return_value = false ; - } + { + INFOS( "Usage: " << argv[0] + << " -common 'path to general catalog' " + " -personal 'path to personal catalog' " + " -ORBInitRef NameService=corbaname::localhost"); + _return_value = false ; + } if (strcmp(argv[ind],"-common") == 0) - { - if (ind + 1 < argc) - { - // General catalog file - *_general = argv[ind + 1] ; - } - } + { + if (ind + 1 < argc) + { + // General catalog file + *_general = argv[ind + 1] ; + } + } else if (strcmp(argv[ind],"-personal") == 0) - { - if (ind + 1 < argc) - { - // Personal catalog file - *_personal = argv[ind + 1] ; - } - } + { + if (ind + 1 < argc) + { + // Personal catalog file + *_personal = argv[ind + 1] ; + } + } } return _return_value; } - -