Salome HOME
PR: merge from branch BR_3_1_0deb tag mergeto_trunk_22dec05
[modules/yacs.git] / src / ModuleCatalog / SALOME_ModuleCatalog_impl.cxx
index 7ba1b29f9539881e57c8e1b65380afcdcdce7c0f..b6def6a59e20e95c81f827f6a31af45655768a89 100644 (file)
 #include <qfileinfo.h>
 using namespace std;
 
+#include "utilities.h"
+
+#ifdef _DEBUG_
+static int MYDEBUG = 1;
+#else
+static int MYDEBUG = 1;
+#endif
+
 static const char* SEPARATOR    = ":";
 
 //----------------------------------------------------------------------
@@ -43,7 +51,7 @@ 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");
 
   // Conversion rules for component types
   ComponentTypeConvert[GEOM]
@@ -93,57 +101,56 @@ 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" )
-  else
-    {
-      // 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);
-       }
+  if (_general_path == NULL){
+    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
+    
+    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);
       }
-
-      // 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);
+      
+      // 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,7 +159,7 @@ SALOME_ModuleCatalogImpl::SALOME_ModuleCatalogImpl(int argc, char** argv, CORBA:
 //----------------------------------------------------------------------
 SALOME_ModuleCatalogImpl::~SALOME_ModuleCatalogImpl()
 {
-  MESSAGE("Catalog Destruction");
+  if(MYDEBUG) MESSAGE("Catalog Destruction");
 }
 
 
@@ -174,7 +181,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 ;
@@ -229,51 +236,51 @@ 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" )
+#ifndef WNT
+  for(unsigned int ind=0; ind < _general_module_list.size();ind++){
+#else
+  for(ind=0; ind < _general_module_list.size();ind++){
+#endif
+    _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 +295,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 +303,51 @@ 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"); 
-     }
-
+#ifndef WNT
+  for(unsigned int ind=0; ind < _general_module_list.size();ind++){
+#else
+  for(ind=0; ind < _general_module_list.size();ind++){
+#endif
+    _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 +361,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;
@@ -392,7 +403,7 @@ SALOME_ModuleCatalogImpl::GetTypedComponentList(SALOME_ModuleCatalog::ComponentT
        {
          _list_typed_component->length(_j + 1); 
          _list_typed_component[_j] = (_moduleList[ind].name).c_str();
-         //SCRUTE(_list_typed_component[_j])
+         //if(MYDEBUG) SCRUTE(_list_typed_component[_j]);
          _j++;
        }
     }
@@ -402,7 +413,11 @@ SALOME_ModuleCatalogImpl::GetTypedComponentList(SALOME_ModuleCatalog::ComponentT
   
   // The components in the general catalog are taken only if they're
   // not defined in the personal catalog
+#ifndef WNT
   for (unsigned int ind=0; ind < _general_module_list.size();ind++)
+#else
+  for (ind=0; ind < _general_module_list.size();ind++)
+#endif
     {
       _find = false;
 
@@ -417,16 +432,16 @@ SALOME_ModuleCatalogImpl::GetTypedComponentList(SALOME_ModuleCatalog::ComponentT
            }
          if (!_find)
            {
-             //MESSAGE("A new component " << _general_module_list[ind].name << " has to be to added in the list");
+             //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]) ;
+             //if(MYDEBUG) SCRUTE(_list_typed_component[indice]) ;
 
              indice++;
            }
          //else 
-           //MESSAGE("The component " <<_general_module_list[ind].name << " was already defined in the personal catalog") ;
+           //if(MYDEBUG) MESSAGE("The component " <<_general_module_list[ind].name << " was already defined in the personal catalog") ;
         }
     }
 
@@ -455,12 +470,12 @@ SALOME_ModuleCatalogImpl::GetComponent(const char* name)
   ParserComponent *C_parser = 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;
     duplicate(C_corba, *C_parser);
@@ -474,9 +489,8 @@ 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;
@@ -507,21 +521,23 @@ SALOME_ModuleCatalogImpl::findComponent(const string & name)
 
   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");
+           //      if(MYDEBUG) MESSAGE("Component named " << name 
+           //                  << " found in the general catalog");
            C_parser = &(_general_module_list[ind]);
            break;
          }
@@ -539,8 +555,8 @@ SALOME_ModuleCatalogImpl::_parse_xml_file(const char* file,
                                          ParserComponents& modulelist, 
                                          ParserPathPrefixes& pathList)
 {
-  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);
@@ -622,7 +638,7 @@ void SALOME_ModuleCatalogImpl::duplicate
   
   // duplicate service list
   unsigned int _length = I_parser.services.size();
-  SCRUTE(_length);
+  //  if(MYDEBUG) SCRUTE(_length);
   //  I_corba.interfaceservicelist 
   //  = new SALOME_ModuleCatalog::ListOfInterfaceService;
   I_corba.interfaceservicelist.length(_length);
@@ -661,25 +677,37 @@ void SALOME_ModuleCatalogImpl::duplicate
   // duplicate out Parameters
   _length = S_parser.outParameters.size();
   S_corba.ServiceoutParameter.length(_length);
-  
+
+#ifndef WNT
   for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
+#else
+  for (ind2 = 0; ind2 < _length ; ind2 ++)
+#endif
     duplicate(S_corba.ServiceoutParameter[ind2],
              S_parser.outParameters[ind2]);
   
   // duplicate in DataStreamParameters
   _length = S_parser.inDataStreamParameters.size();
   S_corba.ServiceinDataStreamParameter.length(_length);
-  
+
+#ifndef WNT
   for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
+#else
+  for (ind2 = 0; ind2 < _length ; ind2 ++)
+#endif
     duplicate(S_corba.ServiceinDataStreamParameter[ind2],
              S_parser.inDataStreamParameters[ind2]);
   
   // duplicate out DataStreamParameters
   _length = S_parser.outDataStreamParameters.size();
-  SCRUTE(_length);
+  //  if(MYDEBUG) SCRUTE(_length);
   S_corba.ServiceoutDataStreamParameter.length(_length);
-  
+
+#ifndef WNT
   for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
+#else
+  for (ind2 = 0; ind2 < _length ; ind2 ++)
+#endif
     duplicate(S_corba.ServiceoutDataStreamParameter[ind2],
              S_parser.outDataStreamParameters[ind2]);
 }
@@ -723,7 +751,7 @@ void SALOME_ModuleCatalogImpl::duplicate
   //     = (it_type == DataStreamTypeConvert.end()) 
   //     ? it_type->second : SALOME_ModuleCatalog::DATASTREAM_UNKNOWN;
 
-  SCRUTE(P_parser.type);
+  if(MYDEBUG) SCRUTE(P_parser.type);
   P_corba.Parametertype = SALOME_ModuleCatalog::DATASTREAM_UNKNOWN;
   for (it_type = DataStreamTypeConvert.begin(); 
        it_type != DataStreamTypeConvert.end(); 
@@ -732,7 +760,7 @@ void SALOME_ModuleCatalogImpl::duplicate
       P_corba.Parametertype = it_type->second;
       break;
     }
-  SCRUTE(P_corba.Parametertype);
+  if(MYDEBUG) SCRUTE(P_corba.Parametertype);
 
   // duplicate parameter type
 
@@ -742,7 +770,7 @@ void SALOME_ModuleCatalogImpl::duplicate
   //     = (it_type == DataStreamTypeConvert.end()) 
   //     ? it_type->second : SALOME_ModuleCatalog::DATASTREAM_UNKNOWN;
   
-  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 +780,7 @@ void SALOME_ModuleCatalogImpl::duplicate
       break;
     }
 
-  SCRUTE(P_corba.Parameterdependency);
+  if(MYDEBUG) SCRUTE(P_corba.Parameterdependency);
 }
 
 //----------------------------------------------------------------------
@@ -789,13 +817,17 @@ SALOME_ModuleCatalogImpl::_verify_path_prefix(ParserPathPrefixes & pathList)
     }
 
   // Parse if a computer name is twice in the list of computers
+#ifndef WNT
   for (unsigned int ind = 0; ind < _machine_list.size(); ind++)
+#else
+  for (ind = 0; ind < _machine_list.size(); ind++)
+#endif
     {
      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")
+            if(MYDEBUG) MESSAGE( "The computer " << _machine_list[ind] << " is indicated more than once in the path list");
             _return_value = false; 
           }
        }