Back to index

salome-kernel  6.5.0
SALOME_FileRef_i.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 //  File   : SALOME_FileRef_i.cxx
00024 //  Author : Paul RASCLE, EDF
00025 //  Module : SALOME
00026 //  $Header: /home/server/cvs/KERNEL/KERNEL_SRC/src/Container/SALOME_FileRef_i.cxx,v 1.5.2.1.14.2.12.1 2012-04-12 14:05:03 vsr Exp $
00027 //
00028 #include "SALOME_FileRef_i.hxx"
00029 #include "utilities.h"
00030 #include "Basics_Utils.hxx"
00031 #include <string>
00032 
00033 //=============================================================================
00037 //=============================================================================
00038 
00039 fileRef_i::fileRef_i()
00040 {
00041   ASSERT(0);
00042 }
00043 //=============================================================================
00047 //=============================================================================
00048 
00049 fileRef_i::fileRef_i(Engines::Container_ptr container,
00050                      const char* origFileName)
00051 {
00052   MESSAGE("fileRef_i::fileRef_i "<< origFileName);
00053   _container =  Engines::Container::_duplicate(container);
00054   _origFileName = origFileName;
00055   _machine = Kernel_Utils::GetHostname();
00056 #if defined(_DEBUG_) || defined(_DEBUG)
00057   int OK = addRef(_machine.c_str(), _origFileName.c_str());
00058   SCRUTE(OK);
00059 #else
00060   addRef(_machine.c_str(), _origFileName.c_str());
00061 #endif
00062 }
00063 
00064 
00065 //=============================================================================
00069 //=============================================================================
00070 
00071 fileRef_i::~fileRef_i()
00072 {
00073   MESSAGE("fileRef_i::~fileRef_i");
00074 }
00075 
00076 //=============================================================================
00082 //=============================================================================
00083 
00084 char* fileRef_i::origFileName()
00085 {
00086   MESSAGE("fileRef_i::origFileName " << _origFileName);
00087   return CORBA::string_dup(_origFileName.c_str());
00088 }
00089 
00090 //=============================================================================
00095 //=============================================================================
00096 
00097 char* fileRef_i::refMachine()
00098 {
00099   MESSAGE("fileRef_i::refMachine " << _machine);
00100   return CORBA::string_dup(_machine.c_str());
00101 }
00102 
00103 //=============================================================================
00108 //=============================================================================
00109 
00110 Engines::Container_ptr fileRef_i::getContainer()
00111 {
00112   MESSAGE("fileRef_i::getContainer");
00113  Engines::Container_var theContainer = 
00114    Engines::Container::_duplicate(_container);
00115  return theContainer._retn();
00116 }
00117 
00118 //=============================================================================
00125 //=============================================================================
00126 
00127 CORBA::Boolean fileRef_i::addRef(const char* machine,
00128                                  const char* fileName)
00129 {
00130   MESSAGE("fileRef_i::addRef " << machine << " " << fileName);
00131   std::string theMachine = machine;
00132   std::string theFileName = fileName;
00133 
00134   if (theFileName[0] != '/')
00135     {
00136       INFOS("destination file path must be absolute, begining with '/'");
00137       return 0;
00138     }
00139 
00140   if (theMachine.empty())
00141     {
00142       INFOS("provide a hostname for the copy destination");
00143       return 0;
00144     }
00145 
00146   if (! _copies[theMachine].empty())
00147     {
00148       INFOS("there is already a copy on " << theMachine << " under the path "
00149             <<  _copies[theMachine] << " new ref not added! ");
00150       return 0;
00151     }
00152 
00153   _copies[theMachine] = theFileName;
00154   return 1;
00155 }
00156 
00157 //=============================================================================
00165 //=============================================================================
00166 
00167 char* fileRef_i::getRef(const char* machine)
00168 {
00169   MESSAGE("fileRef_i::getRef "<< machine);
00170   std::string theMachine = machine;
00171   std::string theFileName = _copies[theMachine];
00172   if (_copies[theMachine].empty())
00173     {
00174       MESSAGE("no copy of " << _machine << _origFileName << " available on "
00175               << theMachine);
00176     }
00177   else
00178     {
00179       MESSAGE("a copy of " << _machine << _origFileName << "is available on "
00180               << theMachine << _copies[theMachine]);
00181     }
00182   return CORBA::string_dup(_copies[theMachine].c_str());
00183 }
00184