Back to index

salome-kernel  6.5.0
SALOME_ModuleCatalog_Acomponent_impl.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SALOME ModuleCatalog : implementation of ModuleCatalog server which parsers xml description of modules
00024 //  File   : SALOME_ModuleCatalog_Acomponent_impl.cxx
00025 //  Author : Estelle Deville
00026 //  Module : SALOME
00027 //  $Header: /home/server/cvs/KERNEL/KERNEL_SRC/src/ModuleCatalog/SALOME_ModuleCatalog_Acomponent_impl.cxx,v 1.11.2.1.10.2.12.1 2012-04-12 14:05:17 vsr Exp $
00028 //
00029 #include "SALOME_ModuleCatalog_Acomponent_impl.hxx"
00030 
00031 #include "Utils_ExceptHandlers.hxx"
00032 UNEXPECT_CATCH(MC_NotFound, SALOME_ModuleCatalog::NotFound);
00033 
00034 #include "utilities.h"
00035 
00036 #ifdef _DEBUG_
00037 static int MYDEBUG = 0;
00038 #else
00039 static int MYDEBUG = 0;
00040 #endif
00041 
00042 //----------------------------------------------------------------------
00043 // Function : SALOME_ModuleCatalog_AcomponentImpl
00044 // Purpose  : Constructor
00045 //            Affect the component name, type,icone,  a bool to define 
00046 //            if it's multistudy or not.
00047 //            Affect too the constraint and the interfaces of the component
00048 //            and the pathes prefixes for all computers
00049 //----------------------------------------------------------------------  
00050 SALOME_ModuleCatalog_AcomponentImpl::SALOME_ModuleCatalog_AcomponentImpl
00051 (SALOME_ModuleCatalog::ComponentDef &C) : _Component(C)
00052 {
00053   if(MYDEBUG) BEGIN_OF("SALOME_ModuleCatalog_AcomponentImpl");
00054 
00055   if(MYDEBUG) END_OF("SALOME_ModuleCatalog_AcomponentImpl");
00056 }
00057 
00058 //----------------------------------------------------------------------
00059 // Function : ~SALOME_ModuleCatalog_AcomponentImpl
00060 // Purpose  : Destructor 
00061 //----------------------------------------------------------------------
00062 SALOME_ModuleCatalog_AcomponentImpl::~SALOME_ModuleCatalog_AcomponentImpl()
00063 {
00064   if(MYDEBUG) BEGIN_OF("~SALOME_ModuleCatalog_AcomponentImpl");
00065 
00066 
00067   if(MYDEBUG) END_OF("~SALOME_ModuleCatalog_AcomponentImpl");
00068 }
00069 
00070 //----------------------------------------------------------------------
00071 // Function : GetInterfaceList
00072 // Purpose  : get a list of the interfaces name of a component
00073 //----------------------------------------------------------------------
00074 SALOME_ModuleCatalog::ListOfInterfaces* 
00075 SALOME_ModuleCatalog_AcomponentImpl::GetInterfaceList() 
00076 {
00077   if(MYDEBUG) BEGIN_OF("GetInterfaceList");
00078 
00079   SALOME_ModuleCatalog::ListOfInterfaces_var _list 
00080     = new SALOME_ModuleCatalog::ListOfInterfaces;
00081 
00082   // All the interfaces are defined in _list_interfaces affected at the
00083   // component creation
00084   unsigned int _length_interfaces = _Component.interfaces.length();
00085 
00086   _list->length(_length_interfaces);
00087 
00088   // Parse all the interfaces to get their name
00089   for (unsigned int ind = 0; ind < _length_interfaces; ind++)
00090     {
00091       _list[ind] = CORBA::string_dup(_Component.interfaces[ind].interfacename);
00092       if(MYDEBUG) MESSAGE("The component " << _Component.name 
00093                           << " contains " << _list[ind] << " as interface");
00094     }
00095   
00096   if(MYDEBUG) END_OF("GetInterfaceList");
00097   return _list._retn();
00098 }
00099 
00100 //----------------------------------------------------------------------
00101 // Function : GetInterface
00102 // Purpose  : get one interface of a component
00103 //----------------------------------------------------------------------
00104 SALOME_ModuleCatalog::DefinitionInterface*
00105 SALOME_ModuleCatalog_AcomponentImpl::GetInterface(const char* interfacename)
00106                                      throw(SALOME_ModuleCatalog::NotFound)
00107 {
00108   if(MYDEBUG) BEGIN_OF("GetInterface");
00109   if(MYDEBUG) SCRUTE(interfacename);
00110 
00111   SALOME_ModuleCatalog::DefinitionInterface *_interface =
00112           new SALOME_ModuleCatalog::DefinitionInterface;
00113 
00114   bool _find = false ;
00115   
00116   // looking for the specified interface
00117   for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
00118     {
00119       SALOME_ModuleCatalog::DefinitionInterface &I
00120         = _Component.interfaces[ind];
00121 
00122       if (strcmp(interfacename, I.interfacename) == 0)
00123         {
00124           // wanted interface
00125           _find = true ;
00126           duplicate(*_interface, I);
00127         }
00128     }
00129 
00130   if(MYDEBUG) SCRUTE(_find);
00131   if (!_find)
00132     {
00133       // The interface was not found, the exception should be thrown
00134               std::string message = "The interface";
00135       message += interfacename;
00136       message += " of the component ";
00137       message += _Component.name;
00138       message += " was not found"; 
00139       if(MYDEBUG) MESSAGE(message);
00140       throw SALOME_ModuleCatalog::NotFound(message.c_str());
00141     }
00142 
00143   if(MYDEBUG) END_OF("GetInterface");
00144 
00145   return _interface;
00146 }
00147 
00148 
00149 
00150 //----------------------------------------------------------------------
00151 // Function : GetServiceList
00152 // Purpose  : get a list of the services name of an interface 
00153 //            of a component
00154 //----------------------------------------------------------------------
00155 SALOME_ModuleCatalog::ListOfServices* 
00156 SALOME_ModuleCatalog_AcomponentImpl::GetServiceList(const char* interfacename)
00157                                      throw(SALOME_ModuleCatalog::NotFound)
00158 {
00159   if(MYDEBUG) BEGIN_OF("GetServiceList");
00160   if(MYDEBUG) SCRUTE(interfacename);
00161 
00162   SALOME_ModuleCatalog::ListOfServices_var _list 
00163     = new SALOME_ModuleCatalog::ListOfServices;
00164 
00165   // Variables initialisation
00166   bool _find = false ;
00167 
00168   // looking for the specified interface
00169   for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
00170     {
00171       SALOME_ModuleCatalog::DefinitionInterface & I = _Component.interfaces[ind];
00172 
00173       if (strcmp(interfacename, I.interfacename) == 0)
00174         {
00175           _find = true ;
00176           // wanted interface
00177           // Get the list of services name for this interface
00178           unsigned int _length_services = I.interfaceservicelist.length();
00179           _list->length(_length_services);
00180           for (unsigned int ind1 = 0; ind1 < _length_services ; ind1++)
00181             {
00182               _list[ind1] = CORBA::string_dup(I.interfaceservicelist[ind1].ServiceName);
00183               if(MYDEBUG) MESSAGE("The interface " << interfacename << " of the component " 
00184                                   << _Component.name << " contains " << _list[ind1] << " as a service") 
00185             }
00186         }
00187     }
00188 
00189  if (!_find)
00190     {
00191       // The interface was not found, the exception should be thrown
00192       std::string message = "The interface";
00193       message += interfacename;
00194       message += " of the component ";
00195       message += _Component.name;
00196       message += " was not found"; 
00197       if(MYDEBUG) MESSAGE(message);
00198       throw SALOME_ModuleCatalog::NotFound(message.c_str());
00199     }
00200 
00201   if(MYDEBUG) END_OF("GetServiceList");
00202   return _list._retn();
00203 }
00204 
00205     
00206 //----------------------------------------------------------------------
00207 // Function : GetService
00208 // Purpose  : get one service of an interface of a component
00209 //----------------------------------------------------------------------
00210 SALOME_ModuleCatalog::Service* 
00211 SALOME_ModuleCatalog_AcomponentImpl::GetService(const char* interfacename, 
00212                                                 const char* servicename) 
00213                                      throw(SALOME_ModuleCatalog::NotFound)
00214 {
00215   if(MYDEBUG) BEGIN_OF("GetService");
00216   if(MYDEBUG) SCRUTE(interfacename);
00217   if(MYDEBUG) SCRUTE(servicename);
00218 
00219   Unexpect aCatch( MC_NotFound );
00220   SALOME_ModuleCatalog::Service *service = new SALOME_ModuleCatalog::Service;
00221 
00222   // Variables initialization
00223   bool _find = false ;
00224   
00225 
00226   // looking for the specified interface
00227   for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
00228     {
00229       if(MYDEBUG) SCRUTE(ind);
00230       if(MYDEBUG) SCRUTE(_Component.interfaces[ind].interfacename);
00231 
00232       SALOME_ModuleCatalog::DefinitionInterface &I = _Component.interfaces[ind];
00233       if (strcmp(interfacename, I.interfacename) == 0)
00234         {
00235           // wanted interface
00236           // looking for the specified service
00237           for (unsigned int ind1 = 0; ind1 <  I.interfaceservicelist.length() ; ind1++)
00238             {
00239               SALOME_ModuleCatalog::Service &S = I.interfaceservicelist[ind1];
00240               if(MYDEBUG) SCRUTE(ind1);
00241               if(MYDEBUG) SCRUTE(S.ServiceName);
00242 
00243               if (strcmp(servicename, S.ServiceName) == 0)
00244               {
00245                 // Wanted Service
00246                 // Affect the service to be returned
00247                 _find = true ;
00248                 duplicate(*service, S);
00249               }
00250             }
00251 
00252         }
00253     }
00254   
00255   if(MYDEBUG) SCRUTE(_find);
00256   if (!_find)
00257     {
00258       // The interface was not found, the exception should be thrown
00259       std::string message = "The service";
00260       message += servicename;
00261       message += " of the interface ";
00262       message += interfacename;
00263       message += " of the component ";
00264       message += _Component.name;
00265       message += " was not found"; 
00266       if(MYDEBUG) MESSAGE(message);
00267       throw SALOME_ModuleCatalog::NotFound(message.c_str());
00268     }
00269 
00270   if(MYDEBUG) END_OF("GetService");
00271   return service;
00272 }
00273 
00274 //----------------------------------------------------------------------
00275 // Function : GetDefaultService
00276 // Purpose  : get the default service of the interface
00277 //----------------------------------------------------------------------
00278 SALOME_ModuleCatalog::Service* 
00279 SALOME_ModuleCatalog_AcomponentImpl::GetDefaultService(const char* interfacename) 
00280                                      throw(SALOME_ModuleCatalog::NotFound)
00281 {
00282   if(MYDEBUG) BEGIN_OF("GetDefaultService");
00283   if(MYDEBUG) SCRUTE(interfacename);
00284 
00285   Unexpect aCatch( MC_NotFound );
00286   SALOME_ModuleCatalog::Service *_service = new  SALOME_ModuleCatalog::Service;
00287 
00288   // Variables initialisation
00289   bool _find = false ;
00290 
00291   // looking for the specified interface
00292   for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
00293     {
00294       if (strcmp(interfacename, _Component.interfaces[ind].interfacename) == 0)
00295         {
00296           // wanted interface
00297           // looking for the defautl service of the wanted interface
00298           for (unsigned int ind1 = 0; ind1 <  _Component.interfaces[ind].interfaceservicelist.length() ; ind1++)
00299             {
00300               if (_Component.interfaces[ind].interfaceservicelist[ind1].Servicebydefault)
00301               {
00302                 // Default Service
00303                 // affect the service to be returned
00304                 _find = true ;
00305                 duplicate(*_service, _Component.interfaces[ind].interfaceservicelist[ind1]);
00306               }
00307             }
00308 
00309         }
00310     }
00311 
00312   if (!_find)
00313     {
00314       // The service was not found, the exception should be thrown
00315       std::string message = "The default service of the interface ";
00316       message += interfacename;
00317       message += " of the component ";
00318       message += _Component.name;
00319       message += " was not found";
00320       if(MYDEBUG) MESSAGE(message);
00321       throw SALOME_ModuleCatalog::NotFound(message.c_str());
00322     }
00323 
00324   if(MYDEBUG) END_OF("GetDefaultService");
00325   return _service;
00326 }
00327 
00328 //----------------------------------------------------------------------
00329 // Function : GetPathPrefix
00330 // Purpose  : get the PathPrefix of a computer
00331 //----------------------------------------------------------------------
00332 char* 
00333 SALOME_ModuleCatalog_AcomponentImpl::GetPathPrefix(const char* machinename) 
00334                                      throw(SALOME_ModuleCatalog::NotFound)
00335 {
00336   if(MYDEBUG) BEGIN_OF("GetPathPrefix");
00337   if(MYDEBUG) SCRUTE(machinename);
00338   Unexpect aCatch( MC_NotFound );
00339 
00340  // Variables initialisation
00341   char* _path = NULL;
00342   bool _find = false ;
00343 
00344   // Parse all the path prefixes
00345   // looking for the wanted computer
00346   for (unsigned int ind = 0 ; ind < _Component.paths.length() ; ind++)
00347     {
00348       if (strcmp(machinename, _Component.paths[ind].machine) == 0)
00349             {
00350               _find = true ;
00351               // Wanted computer
00352               // affect the path to be returned
00353                 const char* _temp = _Component.paths[ind].path ;
00354                 _path = new char[strlen(_temp)+1];
00355                 strcpy(_path,_temp);
00356             }
00357      }
00358 
00359    if(MYDEBUG) SCRUTE(_find);
00360    if (!_find)
00361      {
00362        // The computer was not found, the exception should be thrown
00363        std::string message = "The computer ";
00364        message += machinename;
00365        message += " was not found in the catalog associated to the component ";
00366        message += _Component.name;
00367        if(MYDEBUG) MESSAGE(message);
00368        throw SALOME_ModuleCatalog::NotFound(message.c_str());
00369      }
00370 
00371   if(MYDEBUG) END_OF("GetPathPrefix");
00372   return _path;
00373 }
00374 
00375 //----------------------------------------------------------------------
00376 // Function : constraint
00377 // Purpose  : obtain the constraint affected to a component
00378 //----------------------------------------------------------------------
00379 char* SALOME_ModuleCatalog_AcomponentImpl::constraint() 
00380 {
00381   return CORBA::string_dup(_Component.constraint);
00382 }
00383 
00384 //----------------------------------------------------------------------
00385 // Function : componentname
00386 // Purpose  : obtain the componentname
00387 //----------------------------------------------------------------------
00388 char* SALOME_ModuleCatalog_AcomponentImpl::componentname()
00389 {
00390   return CORBA::string_dup(_Component.name);
00391 }
00392 
00393 //----------------------------------------------------------------------
00394 // Function : componentusername
00395 // Purpose  : obtain the componentusername
00396 //----------------------------------------------------------------------
00397 char* SALOME_ModuleCatalog_AcomponentImpl::componentusername()
00398 {
00399   return CORBA::string_dup(_Component.username);
00400 }
00401 
00402 //----------------------------------------------------------------------
00403 // Function : multistudy
00404 // Purpose  : define if a component can be multistudy or not
00405 //----------------------------------------------------------------------
00406 CORBA::Boolean SALOME_ModuleCatalog_AcomponentImpl::multistudy()
00407 {
00408   return _Component.multistudy ;
00409 }
00410 
00411 
00412 //----------------------------------------------------------------------
00413 // Function : implementation type
00414 // Purpose  : return the implementation type :  C++ (dyn lib), Python (module) or executable
00415 //----------------------------------------------------------------------
00416 SALOME_ModuleCatalog::ImplType SALOME_ModuleCatalog_AcomponentImpl::implementation_type()
00417 {
00418   return _Component.implementationType ;
00419 }
00420 
00421 //----------------------------------------------------------------------
00422 // Function : implementation name
00423 // Purpose  : return the implementation name to exec if the default one is not convenient
00424 //----------------------------------------------------------------------
00425 char* SALOME_ModuleCatalog_AcomponentImpl::implementation_name()
00426 {
00427   return _Component.implname ;
00428 }
00429 
00430 //----------------------------------------------------------------------
00431 // Function : component_type
00432 // Purpose  : define the type of the component
00433 //----------------------------------------------------------------------
00434 SALOME_ModuleCatalog::ComponentType 
00435 SALOME_ModuleCatalog_AcomponentImpl::component_type() 
00436 {
00437   return _Component.type;
00438 }
00439 
00440 //----------------------------------------------------------------------
00441 // Function : icone
00442 // Purpose  : obtain the icone affected to a component (for IAPP)
00443 //----------------------------------------------------------------------
00444 char* SALOME_ModuleCatalog_AcomponentImpl::component_icone() 
00445 {
00446   return CORBA::string_dup(_Component.icon);
00447 }
00448 
00449 
00450 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
00451 (SALOME_ModuleCatalog::ServicesParameter & P_out,
00452  const SALOME_ModuleCatalog::ServicesParameter &P_in)
00453 {
00454   // duplicate parameter name
00455   P_out.Parametername = CORBA::string_dup(P_in.Parametername);
00456   
00457   // duplicate parameter type
00458   P_out.Parametertype = CORBA::string_dup(P_in.Parametertype);
00459 }
00460 
00461 
00462 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
00463 (SALOME_ModuleCatalog::ServicesDataStreamParameter & P_out,
00464  const SALOME_ModuleCatalog::ServicesDataStreamParameter &P_in)
00465 {
00466   // duplicate parameter name
00467   P_out.Parametername = CORBA::string_dup(P_in.Parametername);
00468   
00469   // duplicate parameter type
00470   P_out.Parametertype = P_in.Parametertype;
00471 
00472   // duplicate parameter dependency
00473   P_out.Parameterdependency = P_in.Parameterdependency;
00474 
00475 }
00476 
00477 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
00478 (SALOME_ModuleCatalog::Service & S_out,
00479  const SALOME_ModuleCatalog::Service &S_in)
00480 {
00481   // type of node
00482   S_out.TypeOfNode = S_in.TypeOfNode;
00483 
00484     // duplicate service name
00485   S_out.ServiceName = CORBA::string_dup(S_in.ServiceName);
00486   
00487   // duplicate service by default
00488   S_out.Servicebydefault = S_in.Servicebydefault;
00489 
00490   unsigned int _length;
00491 
00492   // duplicate in Parameters
00493   _length = S_in.ServiceinParameter.length();
00494   S_out.ServiceinParameter.length(_length);
00495 
00496   for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
00497     duplicate(S_out.ServiceinParameter[ind2],
00498               S_in.ServiceinParameter[ind2]);
00499   
00500   // duplicate out Parameters
00501   _length = S_in.ServiceoutParameter.length();
00502   S_out.ServiceoutParameter.length(_length);
00503 
00504   for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
00505     duplicate(S_out.ServiceoutParameter[ind2],
00506               S_in.ServiceoutParameter[ind2]);
00507   
00508   // duplicate in DataStreamParameters
00509   _length = S_in.ServiceinDataStreamParameter.length();
00510   S_out.ServiceinDataStreamParameter.length(_length);
00511 
00512   for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
00513     duplicate(S_out.ServiceinDataStreamParameter[ind2],
00514               S_in.ServiceinDataStreamParameter[ind2]);
00515   
00516   // duplicate out DataStreamParameters
00517   _length = S_in.ServiceoutDataStreamParameter.length();
00518   if(MYDEBUG) SCRUTE(_length);
00519   S_out.ServiceoutDataStreamParameter.length(_length);
00520   
00521   for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
00522     duplicate(S_out.ServiceoutDataStreamParameter[ind2],
00523               S_in.ServiceoutDataStreamParameter[ind2]);
00524 }
00525 
00526 
00527 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
00528 (SALOME_ModuleCatalog::DefinitionInterface & I_out,
00529  const SALOME_ModuleCatalog::DefinitionInterface & I_in)
00530 {
00531   //duplicate interface name
00532   I_out.interfacename = CORBA::string_dup(I_in.interfacename);
00533   
00534   // duplicate service list
00535   unsigned int _length = I_in.interfaceservicelist.length();
00536   if(MYDEBUG) SCRUTE(_length);
00537   I_out.interfaceservicelist.length(_length);
00538   
00539   for (unsigned int ind1 = 0; ind1 < _length ; ind1 ++)
00540     duplicate(I_out.interfaceservicelist[ind1],
00541               I_in.interfaceservicelist[ind1]);
00542 }
00543 
00544