1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SALOME_FileRef_i.cxx
24 // Author : Paul RASCLE, EDF
28 #include "SALOME_FileRef_i.hxx"
29 #include "utilities.h"
30 #include "Basics_Utils.hxx"
33 //=============================================================================
35 * Default constructor, not for use
37 //=============================================================================
39 fileRef_i::fileRef_i()
43 //=============================================================================
47 //=============================================================================
49 fileRef_i::fileRef_i(Engines::Container_ptr container,
50 const char* origFileName)
52 MESSAGE("fileRef_i::fileRef_i "<< origFileName);
53 _container = Engines::Container::_duplicate(container);
54 _origFileName = origFileName;
55 _machine = Kernel_Utils::GetHostname();
56 #if defined(_DEBUG_) || defined(_DEBUG)
57 int OK = addRef(_machine.c_str(), _origFileName.c_str());
60 addRef(_machine.c_str(), _origFileName.c_str());
65 //=============================================================================
69 //=============================================================================
71 fileRef_i::~fileRef_i()
73 MESSAGE("fileRef_i::~fileRef_i");
76 //=============================================================================
79 * \return the file name (absolute path) on the computer which runs the
82 //=============================================================================
84 char* fileRef_i::origFileName()
86 MESSAGE("fileRef_i::origFileName " << _origFileName);
87 return CORBA::string_dup(_origFileName.c_str());
90 //=============================================================================
93 * \return the hostname of the computer which runs the container server
95 //=============================================================================
97 char* fileRef_i::refMachine()
99 MESSAGE("fileRef_i::refMachine " << _machine);
100 return CORBA::string_dup(_machine.c_str());
103 //=============================================================================
106 * \return the container reference
108 //=============================================================================
110 Engines::Container_ptr fileRef_i::getContainer()
112 MESSAGE("fileRef_i::getContainer");
113 Engines::Container_var theContainer =
114 Engines::Container::_duplicate(_container);
115 return theContainer._retn();
118 //=============================================================================
120 * CORBA method: after a file transfer on a client computer, registers
121 * hostname of client and file path of the copied file.
122 * \param machine client hostname
123 * \param fileName asolute path of the transfered file on client computer
125 //=============================================================================
127 CORBA::Boolean fileRef_i::addRef(const char* machine,
128 const char* fileName)
130 MESSAGE("fileRef_i::addRef " << machine << " " << fileName);
131 std::string theMachine = machine;
132 std::string theFileName = fileName;
134 if (theFileName[0] != '/')
136 INFOS("destination file path must be absolute, begining with '/'");
140 if (theMachine.empty())
142 INFOS("provide a hostname for the copy destination");
146 if (! _copies[theMachine].empty())
148 INFOS("there is already a copy on " << theMachine << " under the path "
149 << _copies[theMachine] << " new ref not added! ");
153 _copies[theMachine] = theFileName;
157 //=============================================================================
159 * CORBA method: check if a copy of the file referenced by fileRef is
160 * available on the client computer.
161 * \param machine hostname of the client computer
162 * \return path of the copy on the client computer, if the copy exists,
165 //=============================================================================
167 char* fileRef_i::getRef(const char* machine)
169 MESSAGE("fileRef_i::getRef "<< machine);
170 std::string theMachine = machine;
171 std::string theFileName = _copies[theMachine];
172 if (_copies[theMachine].empty())
174 MESSAGE("no copy of " << _machine << _origFileName << " available on "
179 MESSAGE("a copy of " << _machine << _origFileName << "is available on "
180 << theMachine << _copies[theMachine]);
182 return CORBA::string_dup(_copies[theMachine].c_str());