1 // Copyright (C) 2006 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : SALOME_FileRef_i.cxx
22 // Author : Paul RASCLE, EDF
26 #include "SALOME_FileRef_i.hxx"
27 #include "utilities.h"
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 = GetHostname();
56 int OK = addRef(_machine.c_str(), _origFileName.c_str());
61 //=============================================================================
65 //=============================================================================
67 fileRef_i::~fileRef_i()
69 MESSAGE("fileRef_i::~fileRef_i");
72 //=============================================================================
75 * \return the file name (absolute path) on the computer which runs the
78 //=============================================================================
80 char* fileRef_i::origFileName()
82 MESSAGE("fileRef_i::origFileName " << _origFileName);
83 return CORBA::string_dup(_origFileName.c_str());
86 //=============================================================================
89 * \return the hostname of the computer which runs the container server
91 //=============================================================================
93 char* fileRef_i::refMachine()
95 MESSAGE("fileRef_i::refMachine " << _machine);
96 return CORBA::string_dup(_machine.c_str());
99 //=============================================================================
102 * \return the container reference
104 //=============================================================================
106 Engines::Container_ptr fileRef_i::getContainer()
108 MESSAGE("fileRef_i::getContainer");
109 Engines::Container_var theContainer =
110 Engines::Container::_duplicate(_container);
111 return theContainer._retn();
114 //=============================================================================
116 * CORBA method: after a file transfer on a client computer, registers
117 * hostname of client and file path of the copied file.
118 * \param machine client hostname
119 * \param fileName asolute path of the transfered file on client computer
121 //=============================================================================
123 CORBA::Boolean fileRef_i::addRef(const char* machine,
124 const char* fileName)
126 MESSAGE("fileRef_i::addRef " << machine << " " << fileName);
127 string theMachine = machine;
128 string theFileName = fileName;
130 if (theFileName[0] != '/')
132 INFOS("destination file path must be absolute, begining with '/'");
136 if (theMachine.empty())
138 INFOS("provide a hostname for the copy destination");
142 if (! _copies[theMachine].empty())
144 INFOS("there is already a copy on " << theMachine << " under the path "
145 << _copies[theMachine] << " new ref not added! ");
149 _copies[theMachine] = theFileName;
153 //=============================================================================
155 * CORBA method: check if a copy of the file referenced by fileRef is
156 * available on the client computer.
157 * \param machine hostname of the client computer
158 * \return path of the copy on the client computer, if the copy exists,
161 //=============================================================================
163 char* fileRef_i::getRef(const char* machine)
165 MESSAGE("fileRef_i::getRef "<< machine);
166 string theMachine = machine;
167 string theFileName = _copies[theMachine];
168 if (_copies[theMachine].empty())
170 MESSAGE("no copy of " << _machine << _origFileName << " available on "
175 MESSAGE("a copy of " << _machine << _origFileName << "is available on "
176 << theMachine << _copies[theMachine]);
178 return CORBA::string_dup(_copies[theMachine].c_str());