#ifndef _SALOME_COMPONENT_IDL_
#define _SALOME_COMPONENT_IDL_
+
/*!
This is a package of interfaces used for connecting new components to %SALOME
application. It also contains a set of interfaces used for management of %MED
typedef sequence<KeyValuePair> FieldsDict;
interface Component ;
+ interface fileRef ;
+ interface fileTransfer ;
/*! \brief Interface of the %Container
This interface defines the process of loading and registration
*/
boolean Kill_impl() ;
- // -------------------------- removed -------------------------------
-
/*!
- Loads into the container a new component, registers it and starts it's
- CORBA servant.
- \param nameToRegister Name used to register in Naming Service,
- the component instance
- \param componentName Name of the %component
- \return a new instance of the component or the registered component
- if already registered or Nil if not possible
+ returns a fileRef object if origFileName exists and is readable
+ else returns null object. Only one fileRef is created for a given
+ file name, so, several calls with the same file name returns the
+ same object.
*/
- // Component instance(in string nameToRegister, in string componentName);
-
+ fileRef createFileRef(in string origFileName);
/*!
- Name of the machine containing this container (location of the container).
+ returns a fileTransfer object used to copy files from the container
+ machine to the clients machines. Only one fileTransfer instance is
+ created in a container.
*/
- // readonly attribute string machineName ;
-
+ fileTransfer getFileTransfer();
};
out boolean isValidScript);
} ;
+
+ typedef sequence<octet> fileBlock;
+
+ /*!
+ file transfer object. open method returns a key (fileId) that identifies
+ the structure (ex: C FILE) on the server, created for transfer.
+ */
+ interface fileTransfer
+ {
+ long open(in string fileName);
+
+ void close(in long fileId);
+
+ fileBlock getBlock(in long fileId);
+ };
+
+ /*!
+ A fileRef object is associated to an original file (origFileName) on a
+ machine (refMachine).
+ It is created by a container (factoryServer) on refMachine,
+ with createFileRef(in string origFileName) method.
+ fileRef object maintains a list of (machine,filename) for copies.
+ If a copy exists on myMachine, getRef(myMachine) returns the file name
+ of the copy on myMachine, else returns empy string.
+ If there is no copy on myMachine, method getFileTransfer() from container
+ factoryServer on refMachine provides a fileTransfer object dedicated to
+ CORBA file copy.
+ After the copy, addRef(myMachine, localFileNameOnMyMachine) registers
+ the file name of the copy on myMachine.
+ */
+ interface fileRef
+ {
+ readonly attribute string origFileName;
+ readonly attribute string refMachine;
+
+ Container getContainer();
+
+ boolean addRef(in string machine,
+ in string fileName);
+
+ string getRef(in string machine);
+ };
+
} ;
#endif
#include <pthread.h> // must be before Python.h !
#include "SALOME_Container_i.hxx"
#include "SALOME_Component_i.hxx"
+#include "SALOME_FileRef_i.hxx"
+#include "SALOME_FileTransfer_i.hxx"
#include "SALOME_NamingService.hxx"
#include "OpUtil.hxx"
PyRun_SimpleString((char*)myCommand.c_str());
Py_RELEASE_NEW_THREAD;
}
+
+ fileTransfer_i* aFileTransfer = new fileTransfer_i();
+ _fileTransfer = Engines::fileTransfer::_narrow(aFileTransfer->_this());
}
}
return false;
}
+//=============================================================================
+/*!
+ * CORBA method: get or create a fileRef object associated to a local file
+ * (a file on the computer on which runs the container server), which stores
+ * a list of (machine, localFileName) corresponding to copies already done.
+ *
+ * \param origFileName absolute path for a local file to copy on other
+ * computers
+ * \return a fileRef object associated to the file.
+ */
+//=============================================================================
+
+Engines::fileRef_ptr
+Engines_Container_i::createFileRef(const char* origFileName)
+{
+ string origName(origFileName);
+ Engines::fileRef_var theFileRef = Engines::fileRef::_nil();
+
+ if (origName[0] != '/')
+ {
+ INFOS("path of file to copy must be an absolute path begining with '/'");
+ return Engines::fileRef::_nil();
+ }
+
+ if (CORBA::is_nil(_fileRef_map[origName]))
+ {
+ CORBA::Object_var obj=_poa->id_to_reference(*_id);
+ Engines::Container_var pCont = Engines::Container::_narrow(obj);
+ fileRef_i* aFileRef = new fileRef_i(pCont, origFileName);
+ theFileRef = Engines::fileRef::_narrow(aFileRef->_this());
+ _fileRef_map[origName] = theFileRef;
+ }
+
+ theFileRef = Engines::fileRef::_duplicate(_fileRef_map[origName]);
+ ASSERT(! CORBA::is_nil(theFileRef));
+ return theFileRef._retn();
+}
+
+//=============================================================================
+/*!
+ * CORBA method:
+ * \return a reference to the fileTransfer object
+ */
+//=============================================================================
+
+Engines::fileTransfer_ptr
+Engines_Container_i::getFileTransfer()
+{
+ Engines::fileTransfer_var aFileTransfer
+ = Engines::fileTransfer::_duplicate(_fileTransfer);
+ return aFileTransfer._retn();
+}
+
+
//=============================================================================
/*!
* C++ method: Finds an already existing servant instance of a component, or
salomeinclude_HEADERS = \
SALOME_Component_i.hxx \
SALOME_Container_i.hxx \
+ SALOME_FileTransfer_i.hxx \
+ SALOME_FileRef_i.hxx \
SALOME_ContainerManager.hxx \
Container_init_python.hxx
libSalomeContainer_la_SOURCES=\
Component_i.cxx \
Container_i.cxx \
+ SALOME_FileTransfer_i.cxx \
+ SALOME_FileRef_i.cxx \
SALOME_ContainerManager.cxx \
Container_init_python.cxx
char* getHostName();
CORBA::Long getPID();
//! Kill current container
- bool Kill_impl() ;
+ bool Kill_impl();
+
+ Engines::fileRef_ptr createFileRef(const char* origFileName);
+ Engines::fileTransfer_ptr getFileTransfer();
- //Engines::Component_ptr instance(const char* nameToRegister,
- // const char* componentName);
// --- local C++ methods
PortableServer::ObjectId * _id ;
int _numInstance ;
std::map<std::string,Engines::Component_var> _listInstances_map;
+ std::map<std::string,Engines::fileRef_var> _fileRef_map;
+ Engines::fileTransfer_var _fileTransfer;
int _argc ;
char** _argv ;
--- /dev/null
+// Copyright (C) 2006 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+//
+//
+//
+// File : SALOME_FileRef_i.cxx
+// Author : Paul RASCLE, EDF
+// Module : SALOME
+// $Header$
+
+#include "SALOME_FileRef_i.hxx"
+#include "utilities.h"
+#include "OpUtil.hxx"
+#include <string>
+
+using namespace std;
+
+//=============================================================================
+/*!
+ * Default constructor, not for use
+ */
+//=============================================================================
+
+fileRef_i::fileRef_i()
+{
+ ASSERT(0);
+}
+//=============================================================================
+/*!
+ * Constructor to use
+ */
+//=============================================================================
+
+fileRef_i::fileRef_i(Engines::Container_ptr container,
+ const char* origFileName)
+{
+ MESSAGE("fileRef_i::fileRef_i "<< origFileName);
+ _container = Engines::Container::_duplicate(container);
+ _origFileName = origFileName;
+ _machine = GetHostname();
+ int OK = addRef(_machine.c_str(), _origFileName.c_str());
+ SCRUTE(OK);
+}
+
+
+//=============================================================================
+/*!
+ * Destructor
+ */
+//=============================================================================
+
+fileRef_i::~fileRef_i()
+{
+ MESSAGE("fileRef_i::~fileRef_i");
+}
+
+//=============================================================================
+/*!
+ * CORBA method:
+ * \return the file name (absolute path) on the computer which runs the
+ * container server
+ */
+//=============================================================================
+
+char* fileRef_i::origFileName()
+{
+ MESSAGE("fileRef_i::origFileName " << _origFileName);
+ return CORBA::string_dup(_origFileName.c_str());
+}
+
+//=============================================================================
+/*!
+ * CORBA method:
+ * \return the hostname of the computer which runs the container server
+ */
+//=============================================================================
+
+char* fileRef_i::refMachine()
+{
+ MESSAGE("fileRef_i::refMachine " << _machine);
+ return CORBA::string_dup(_machine.c_str());
+}
+
+//=============================================================================
+/*!
+ * CORBA method:
+ * \return the container reference
+ */
+//=============================================================================
+
+Engines::Container_ptr fileRef_i::getContainer()
+{
+ MESSAGE("fileRef_i::getContainer");
+ Engines::Container_var theContainer =
+ Engines::Container::_duplicate(_container);
+ return theContainer._retn();
+}
+
+//=============================================================================
+/*!
+ * CORBA method: after a file transfer on a client computer, registers
+ * hostname of client and file path of the copied file.
+ * \param machine client hostname
+ * \param fileName asolute path of the transfered file on client computer
+ */
+//=============================================================================
+
+CORBA::Boolean fileRef_i::addRef(const char* machine,
+ const char* fileName)
+{
+ MESSAGE("fileRef_i::addRef " << machine << " " << fileName);
+ string theMachine = machine;
+ string theFileName = fileName;
+
+ if (theFileName[0] != '/')
+ {
+ INFOS("destination file path must be absolute, begining with '/'");
+ return 0;
+ }
+
+ if (theMachine.empty())
+ {
+ INFOS("provide a hostname for the copy destination");
+ return 0;
+ }
+
+ if (! _copies[theMachine].empty())
+ {
+ INFOS("there is already a copy on " << theMachine << " under the path "
+ << _copies[theMachine] << " new ref not added! ");
+ return 0;
+ }
+
+ _copies[theMachine] = theFileName;
+ return 1;
+}
+
+//=============================================================================
+/*!
+ * CORBA method: check if a copy of the file referenced by fileRef is
+ * available on the client computer.
+ * \param machine hostname of the client computer
+ * \return path of the copy on the client computer, if the copy exists,
+ * else empty string
+ */
+//=============================================================================
+
+char* fileRef_i::getRef(const char* machine)
+{
+ MESSAGE("fileRef_i::getRef "<< machine);
+ string theMachine = machine;
+ string theFileName = _copies[theMachine];
+ if (_copies[theMachine].empty())
+ {
+ MESSAGE("no copy of " << _machine << _origFileName << " available on "
+ << theMachine);
+ }
+ else
+ {
+ MESSAGE("a copy of " << _machine << _origFileName << "is available on "
+ << theMachine << _copies[theMachine]);
+ }
+ return CORBA::string_dup(_copies[theMachine].c_str());
+}
+
--- /dev/null
+// Copyright (C) 2006 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+//
+//
+//
+// File : SALOME_FileRef_i.hxx
+// Author : Paul RASCLE, EDF
+// Module : SALOME
+// $Header$
+
+#ifndef _SALOME_FILEREF_I_HXX_
+#define _SALOME_FILEREF_I_HXX_
+
+#include <SALOMEconfig.h>
+#include CORBA_SERVER_HEADER(SALOME_Component)
+
+#include <string>
+#include <map>
+
+class fileRef_i:
+ public virtual POA_Engines::fileRef,
+ public virtual PortableServer::RefCountServantBase
+{
+public:
+ fileRef_i();
+ fileRef_i(Engines::Container_ptr container,
+ const char* origFileName);
+ virtual ~fileRef_i();
+
+ char* origFileName();
+
+ char* refMachine();
+
+ Engines::Container_ptr getContainer();
+
+ CORBA::Boolean addRef(const char* machine,
+ const char* fileName);
+
+ char* getRef(const char* machine);
+
+protected:
+ Engines::Container_var _container;
+ std::string _origFileName;
+ std::string _machine;
+ std::map<std::string, std::string> _copies;
+};
+
+#endif
--- /dev/null
+
+// Copyright (C) 2006 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+//
+//
+//
+// File : SALOME_FileTransfer_i.cxx
+// Author : Paul RASCLE, EDF
+// Module : SALOME
+// $Header$
+
+#include "SALOME_FileTransfer_i.hxx"
+#include "utilities.h"
+
+//=============================================================================
+/*!
+ * Default constructor,
+ */
+//=============================================================================
+
+fileTransfer_i::fileTransfer_i()
+{
+ MESSAGE("fileTransfer_i::fileTransfer_i");
+ _fileKey=1;
+}
+
+//=============================================================================
+/*!
+ * Destructor
+ */
+//=============================================================================
+
+fileTransfer_i::~fileTransfer_i()
+{
+ MESSAGE("fileTransfer_i::~fileTransfer_i");
+}
+
+
+//=============================================================================
+/*!
+ * CORBA method: try to open the file given. If the file is readable, return
+ * a positive integer else return 0;
+ * \param fileName path to the file to be transfered
+ * \return fileId = positive integer > 0 if open OK.
+ */
+//=============================================================================
+
+CORBA::Long fileTransfer_i::open(const char* fileName)
+{
+ MESSAGE(" fileTransfer_i::open " << fileName);
+ int aKey = _fileKey++;
+ _ctr=0;
+ FILE* fp;
+ if ((fp = fopen(fileName,"rb")) == NULL)
+ {
+ INFOS("file " << fileName << " is not readable");
+ return 0;
+ }
+ _fileAccess[aKey] = fp;
+ return aKey;
+}
+
+//=============================================================================
+/*!
+ * CORBA method: close the file associated to the fileId given at open.
+ * \param fileId got in return from open method
+ */
+//=============================================================================
+
+void fileTransfer_i::close(CORBA::Long fileId)
+{
+ MESSAGE("fileTransfer_i::close");
+ FILE* fp;
+ if (! (fp = _fileAccess[fileId]) )
+ {
+ INFOS(" no FILE structure associated to fileId " <<fileId);
+ }
+ else fclose(fp);
+}
+
+//=============================================================================
+/*!
+ * CORBA method: get a block of data from the file associated to the fileId
+ * given at open.
+ * \param fileId got in return from open method
+ * \return an octet sequence. Last one is empty.
+ */
+//=============================================================================
+
+#define FILEBLOCK_SIZE 256*1024
+
+Engines::fileBlock* fileTransfer_i::getBlock(CORBA::Long fileId)
+{
+ MESSAGE("fileTransfer_i::getBlock");
+ Engines::fileBlock* aBlock = new Engines::fileBlock;
+
+ FILE* fp;
+ if (! (fp = _fileAccess[fileId]) )
+ {
+ INFOS(" no FILE structure associated to fileId " <<fileId);
+ return aBlock;
+ }
+
+ // use replace member function for sequence to avoid copy
+ // see Advanced CORBA Programming with C++ pp 187-194
+
+ CORBA::Octet *buf;
+ buf = Engines::fileBlock::allocbuf(FILEBLOCK_SIZE);
+ int nbRed = fread(buf, sizeof(CORBA::Octet), FILEBLOCK_SIZE, fp);
+ SCRUTE(nbRed);
+ aBlock->replace(nbRed, nbRed, buf, 1); // 1 means give ownership
+ return aBlock;
+}
+
--- /dev/null
+// Copyright (C) 2006 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+//
+//
+//
+// File : SALOME_FileTransfer_i.hxx
+// Author : Paul RASCLE, EDF
+// Module : SALOME
+// $Header$
+
+
+#ifndef _SALOME_FILETRANSFER_I_HXX_
+#define _SALOME_FILETRANSFER_I_HXX_
+
+#include <SALOMEconfig.h>
+#include CORBA_SERVER_HEADER(SALOME_Component)
+#include <map>
+#include <cstdio>
+
+class fileTransfer_i:
+ public virtual POA_Engines::fileTransfer,
+ public virtual PortableServer::RefCountServantBase
+{
+public:
+ fileTransfer_i();
+ virtual ~fileTransfer_i();
+
+ CORBA::Long open(const char* fileName);
+
+ void close(CORBA::Long fileId);
+
+ Engines::fileBlock* getBlock(CORBA::Long fileId);
+
+protected:
+ int _fileKey;
+ std::map<int, FILE*> _fileAccess;
+ int _ctr;
+};
+
+#endif
#
# header files
salomeinclude_HEADERS = \
- SALOME_LifeCycleCORBA.hxx
+ SALOME_LifeCycleCORBA.hxx \
+ SALOME_FileTransferCORBA.hxx
# Scripts to be installed
-dist_salomescript_DATA =\
- Launchers.py
+#dist_salomescript_DATA =\
+# Launchers.py
#
# ===============================================================
lib_LTLIBRARIES = libSalomeLifeCycleCORBA.la
libSalomeLifeCycleCORBA_la_SOURCES = \
SALOME_LifeCycleCORBA.cxx \
- Launchers.cxx \
- Launchers.hxx
+ SALOME_FileTransferCORBA.cxx
libSalomeLifeCycleCORBA_la_CPPFLAGS = \
$(COMMON_CPPFLAGS) \
@PYTHON_INCLUDES@ \
--- /dev/null
+// Copyright (C) 2006 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+//
+//
+//
+// File : SALOME_FileTransferCORBA.cxx
+// Author : Paul RASCLE, EDF
+// Module : SALOME
+// $Header$
+
+#include "SALOME_FileTransferCORBA.hxx"
+#include "SALOME_LifeCycleCORBA.hxx"
+#include "utilities.h"
+#include "OpUtil.hxx"
+
+using namespace std;
+
+//=============================================================================
+/*!
+ * Default constructor, not for use
+ */
+//=============================================================================
+
+SALOME_FileTransferCORBA::SALOME_FileTransferCORBA()
+{
+ ASSERT(0);
+}
+
+//=============================================================================
+/*!
+ * Constructor to use when we get a fileRef CORBA object from a component
+ * \param aFileRef file reference CORBA object
+ */
+//=============================================================================
+
+SALOME_FileTransferCORBA::SALOME_FileTransferCORBA(Engines::fileRef_ptr
+ aFileRef)
+{
+ MESSAGE("SALOME_FileTransferCORBA::SALOME_FileTransferCORBA(aFileRef)");
+ _theFileRef = aFileRef;
+}
+
+//=============================================================================
+/*!
+ * Constructor to use we the file name and machine from which to copy, plus
+ * an optional Container name on the machine
+ * \param refMachine the machine on which is the file to transfer
+ * \param origFileName abolute file path on refMachine
+ * \param containerName default container name used (FactoryServer) if empty
+ */
+//=============================================================================
+
+SALOME_FileTransferCORBA::SALOME_FileTransferCORBA(string refMachine,
+ string origFileName,
+ string containerName)
+{
+ MESSAGE("SALOME_FileTransferCORBA::SALOME_FileTransferCORBA"
+ << refMachine << " " << origFileName << " " << containerName);
+ _refMachine = refMachine;
+ _origFileName = origFileName;
+ _containerName = containerName;
+ if (_refMachine.empty() or _origFileName.empty())
+ {
+ INFOS("bad parameters: machine and file name must be given");
+ }
+}
+
+//=============================================================================
+/*!
+ * Destructor
+ */
+//=============================================================================
+
+SALOME_FileTransferCORBA::~SALOME_FileTransferCORBA()
+{
+ MESSAGE("SALOME_FileTransferCORBA::~SALOME_FileTransferCORBA");
+}
+
+//=============================================================================
+/*!
+ * CORBA method: get a local copy of the reference file
+ * \param localFile optional absolute path to store the copt
+ * \return the file name (absolute path) of the copy, may be different from
+ * localFile parameter if the copy was already done before the call
+ */
+//=============================================================================
+
+string SALOME_FileTransferCORBA::getLocalFile(string localFile)
+{
+ MESSAGE("SALOME_FileTransferCORBA::getLocalFile");
+
+ Engines::Container_var container;
+
+ if (CORBA::is_nil(_theFileRef))
+ {
+ if (_refMachine.empty() or _origFileName.empty())
+ {
+ INFOS("not enough parameters: machine and file name must be given");
+ return "";
+ }
+
+ SALOME_LifeCycleCORBA LCC;
+ Engines::ContainerManager_var contManager = LCC.getContainerManager();
+
+ Engines::MachineParameters params;
+ LCC.preSet(params);
+ params.container_name = _containerName.c_str();
+ params.hostname = _refMachine.c_str();
+
+ Engines::MachineList_var listOfMachines =
+ contManager->GetFittingResources(params, "");
+
+ container = contManager->FindOrStartContainer(params,
+ listOfMachines);
+ if (CORBA::is_nil(container))
+ {
+ INFOS("machine " << _refMachine << " unreachable");
+ return "";
+ }
+
+ _theFileRef = container->createFileRef(_origFileName.c_str());
+ if (CORBA::is_nil(_theFileRef))
+ {
+ INFOS("imposssible to create fileRef on " << _refMachine);
+ return "";
+ }
+ }
+
+ container = _theFileRef->getContainer();
+ ASSERT(! CORBA::is_nil(container));
+
+ string myMachine = GetHostname();
+ string localCopy = _theFileRef->getRef(myMachine.c_str());
+
+ if (localCopy.empty())
+ {
+ if (localFile.empty())
+ {
+ char bufName[256];
+ localCopy = tmpnam(bufName);
+ localFile = bufName;
+ SCRUTE(localFile);
+ }
+
+ FILE* fp;
+ if ((fp = fopen(localFile.c_str(),"wb")) == NULL)
+ {
+ INFOS("file " << localFile << " cannot be open for writing");
+ return "";
+ }
+
+ Engines::fileTransfer_var fileTransfer = container->getFileTransfer();
+ ASSERT(! CORBA::is_nil(fileTransfer));
+
+ CORBA::Long fileId = fileTransfer->open(_origFileName.c_str());
+ if (fileId > 0)
+ {
+ Engines::fileBlock* aBlock;
+ int toFollow = 1;
+ int ctr=0;
+ while (toFollow)
+ {
+ ctr++;
+ SCRUTE(ctr);
+ aBlock = fileTransfer->getBlock(fileId);
+ toFollow = aBlock->length();
+ SCRUTE(toFollow);
+ CORBA::Octet *buf = aBlock->get_buffer();
+ int nbWri = fwrite(buf, sizeof(CORBA::Octet), toFollow, fp);
+ ASSERT(nbWri == toFollow);
+ }
+ MESSAGE("end of transfer");
+ fileTransfer->close(fileId);
+ _theFileRef->addRef(myMachine.c_str(), localFile.c_str());
+ }
+ else
+ {
+ INFOS("open reference file for copy impossible");
+ return "";
+ }
+
+ }
+ SCRUTE(localCopy);
+ return localCopy;
+}
--- /dev/null
+// Copyright (C) 2006 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+//
+//
+//
+// File : SALOME_FileTransferCORBA.hxx
+// Author : Paul RASCLE, EDF
+// Module : SALOME
+// $Header$
+
+#ifndef _SALOME_FILETRANSFERCORBA_HXX_
+#define _SALOME_FILETRANSFERCORBA_HXX_
+
+
+#include <SALOMEconfig.h>
+#include <Utils_SALOME_Exception.hxx>
+
+#include CORBA_CLIENT_HEADER(SALOME_Component)
+
+#include <string>
+
+class SALOME_FileTransferCORBA
+{
+public:
+ SALOME_FileTransferCORBA();
+ SALOME_FileTransferCORBA(Engines::fileRef_ptr aFileRef);
+ SALOME_FileTransferCORBA(std::string refMachine,
+ std::string origFileName,
+ std::string containerName="");
+
+ virtual ~SALOME_FileTransferCORBA();
+
+ std::string getLocalFile(std::string localFile = "");
+
+protected:
+ Engines::fileRef_var _theFileRef;
+ std::string _refMachine;
+ std::string _origFileName;
+ std::string _containerName;
+};
+
+#endif
#include "SALOME_ContainerManager.hxx"
#include "SALOME_Component_i.hxx"
#include "SALOME_NamingService.hxx"
-#include "Launchers.hxx"
using namespace std;
return params.nb_node * params.nb_proc_per_node;
}
+//=============================================================================
+/*! Public -
+ * \return the container Manager
+ */
+//=============================================================================
+
+Engines::ContainerManager_ptr SALOME_LifeCycleCORBA::getContainerManager()
+{
+ Engines::ContainerManager_var contManager =
+ Engines::ContainerManager::_duplicate(_ContManager);
+ return contManager._retn();
+}
+
+
//=============================================================================
/*! Protected -
* Find and aready existing and registered component instance.
void preSet(Engines::MachineParameters& params);
+ Engines::ContainerManager_ptr getContainerManager();
+
protected:
/*! Establish if a component called "componentName" in a container called
#include "LifeCycleCORBATest.hxx"
#include "SALOME_LifeCycleCORBA.hxx"
+#include "SALOME_FileTransferCORBA.hxx"
#include "Utils_ORB_INIT.hxx"
#include "Utils_SINGLETON.hxx"
#include "OpUtil.hxx"
CPPUNIT_ASSERT_EQUAL(hostname1, remoteHost);
}
+// ============================================================================
+/*!
+ * Check SALOME_FileTransferCORBA on local machine
+ */
+// ============================================================================
+
+void LifeCycleCORBATest::testgetLocalFile_localComputer()
+{
+ SALOME_LifeCycleCORBA _LCC(&_NS);
+ string origFileName = getenv("KERNEL_ROOT_DIR");
+ origFileName += "/lib/salome/libSalomeLifeCycleCORBA.so.0.0.0";
+ SALOME_FileTransferCORBA transfer( GetHostname(),
+ origFileName);
+ string local = transfer.getLocalFile();
+ CPPUNIT_ASSERT(!local.empty());
+ CPPUNIT_ASSERT_EQUAL(local, origFileName);
+}
+
+// ============================================================================
+/*!
+ * Check SALOME_FileTransferCORBA on remote machine
+ */
+// ============================================================================
+void LifeCycleCORBATest::testgetLocalFile_remoteComputer()
+{
+ SALOME_LifeCycleCORBA _LCC(&_NS);
+ string origFileName = getenv("KERNEL_ROOT_DIR");
+ origFileName += "/lib/salome/libSalomeContainer.so.0.0.0";
+ SALOME_FileTransferCORBA transfer( GetRemoteHost(),
+ origFileName);
+ string local = transfer.getLocalFile();
+ CPPUNIT_ASSERT(!local.empty());
+ string local2 = transfer.getLocalFile();
+ CPPUNIT_ASSERT(!local2.empty());
+ CPPUNIT_ASSERT_EQUAL(local, local2);
+}
// ============================================================================
/*!
-
-
-
-
// ============================================================================
/*!
* Get a remote HostName in the Resource Catalog
CPPUNIT_TEST( testFindOrLoad_Component_RemoteComputer );
CPPUNIT_TEST( testFindOrLoad_Component_ParamsRemoteComputer );
CPPUNIT_TEST( testFindOrLoad_Component_ParamsRemoteComputer2 );
-// CPPUNIT_TEST( testFindOrLoad_Component_ );
+ CPPUNIT_TEST( testgetLocalFile_localComputer );
+ CPPUNIT_TEST( testgetLocalFile_remoteComputer );
// CPPUNIT_TEST( testFindOrLoad_Component_ );
// CPPUNIT_TEST( );
// CPPUNIT_TEST( );
void testFindOrLoad_Component_RemoteComputer();
void testFindOrLoad_Component_ParamsRemoteComputer();
void testFindOrLoad_Component_ParamsRemoteComputer2();
+ void testgetLocalFile_localComputer();
+ void testgetLocalFile_remoteComputer();
// void testFindOrLoad_Component_();
// void testFindOrLoad_Component_();
#endif
#include "SALOME_NamingService.hxx"
#include "SALOME_LifeCycleCORBA.hxx"
+#include "SALOME_FileTransferCORBA.hxx"
#include "utilities.h"
#include <OpUtil.hxx>
try
{
- // Initializing omniORB
+ // --- Initialize omniORB
+
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
- // LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
- // Obtain a reference to the root POA
+ // --- Obtain a reference to the root POA
+
CORBA::Object_var obj = orb->resolve_initial_references("RootPOA") ;
PortableServer::POA_var poa = PortableServer::POA::_narrow(obj) ;
+
+ // --- Naming Service and LifeCycleCORBA interfaces
SALOME_NamingService _NS(orb) ;
-
SALOME_LifeCycleCORBA _LCC(&_NS) ;
- // get a local container (with a name based on local hostname),
- // load an engine, and invoque methods on that engine
-
- string containerName = GetHostname();
+ // --- get a local container,
+ // load an engine, and invoque methods on that engine
- cout << containerName << endl;
- cout << "FindOrLoadComponent " + containerName + "/" + "SalomeTestComponent" << endl;
+ string containerName = "myServer";
MESSAGE("FindOrLoadComponent " + containerName + "/" + "SalomeTestComponent" );
Engines::Component_var mycompo =
_LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent");
-
ASSERT(!CORBA::is_nil(mycompo));
-
Engines::TestComponent_var m1;
m1 = Engines::TestComponent::_narrow(mycompo);
-
ASSERT(!CORBA::is_nil(m1));
-
SCRUTE(m1->instanceName());
MESSAGE("Coucou " << m1->Coucou(1L));
- // get another container (with a fixed name),
- // load an engine, and invoque methods on that engine
+ // --- get another container,
+ // load an engine, and invoque methods on that engine
- string containerName2 = "FactoryServerPy";
+ string containerName2 = "otherServer";
Engines::Component_var mycompo2 =
_LCC.FindOrLoad_Component(containerName2.c_str(),"SALOME_TestComponentPy");
-
ASSERT(!CORBA::is_nil(mycompo2));
-
Engines::TestComponent_var m2;
m2 = Engines::TestComponent::_narrow(mycompo2);
-
ASSERT(!CORBA::is_nil(m2));
-
SCRUTE(m2->instanceName());
cout << m2->instanceName() << endl;
MESSAGE("Coucou " << m2->Coucou(1L));
- Engines::Component_var mycompo3 = _LCC.FindOrLoad_Component("totoPy","SALOME_TestComponentPy");
+ // --- get a third container,
+ // load an engine, and invoque methods on that engine
+
+ Engines::Component_var mycompo3 =
+ _LCC.FindOrLoad_Component("totoPy","SALOME_TestComponentPy");
ASSERT(!CORBA::is_nil(mycompo3));
Engines::TestComponent_var m3 = Engines::TestComponent::_narrow(mycompo3);
ASSERT(!CORBA::is_nil(m3));
cout << m3->instanceName() << endl;
- string containerName4 = containerName + "/titiPy";
- Engines::Component_var mycompo4 = _LCC.FindOrLoad_Component(containerName4.c_str(),"SALOME_TestComponentPy");
+ // --- yet another container, with hostname,
+ // load an engine, and invoque methods on that engine
+
+ string containerName4 = GetHostname();
+ containerName4 += "/titiPy";
+ Engines::Component_var mycompo4 =
+ _LCC.FindOrLoad_Component(containerName4.c_str(),"SALOME_TestComponentPy");
ASSERT(!CORBA::is_nil(mycompo4));
Engines::TestComponent_var m4 = Engines::TestComponent::_narrow(mycompo4);
ASSERT(!CORBA::is_nil(m4));
cout << m4->instanceName() << endl;
+ // --- try a local file transfer
+
+ string origFileName = "/home/prascle/petitfichier";
+ SALOME_FileTransferCORBA transfer( GetHostname(),
+ origFileName);
+ string local = transfer.getLocalFile();
+ SCRUTE(local);
+
+ // --- try a file transfer from another computer
+
+ origFileName = "/home/prascle/occ60.tgz";
+ SALOME_FileTransferCORBA transfer2( "cli76ce",
+ origFileName);
+ local = transfer2.getLocalFile();
+ SCRUTE(local);
+ local = transfer2.getLocalFile();
+ SCRUTE(local);
+
}
catch(CORBA::SystemException& ex)
{