]> SALOME platform Git repositories - tools/simanio.git/blobdiff - src/SimanIO_Link.cxx
Salome HOME
Improve build procedure
[tools/simanio.git] / src / SimanIO_Link.cxx
index 6542279ae17dea3e09413bcb3902fcb301aebf1a..8987a93bdad7651a59eab30409f9fd2bcc4b9e64 100644 (file)
@@ -1,3 +1,22 @@
+// Copyright (C) 2013  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
 #include "CreateConfigFile.h"
 #include "CreateConfigFileResponse.h"
 #include "GetFile.h"
 #include "PutFileResponse.h"
 #include "SimanSalomeServiceStub.h"
 
+#include "SimanIO_Link.hxx"
+
 #include <Environment.h>
+#include <ServiceClient.h>
+
 #include <iostream>
 #include <fstream>
 #include <sstream>
-#include <ServiceClient.h>
-#include <SimanIO_Link.hxx>
-
-
 #include <algorithm>
 
-
-using namespace std;
 using namespace org_splat_ws_server_service_salome;
 using namespace wso2wsf;
 
@@ -34,7 +51,7 @@ bool SimanIO_Link::IsConnected()
 }
 
 // unification of the error handling in the RetrieveConf and StoreConf  methods
-#define CONFIGURSION_ERROR(message) {cerr<<message<<endl;}
+#define CONFIGURSION_ERROR(message) {std::cerr<<message<<std::endl;}
 
 SimanIO_Configuration SimanIO_Link::RetrieveConf()
 {
@@ -49,8 +66,8 @@ SimanIO_Configuration SimanIO_Link::RetrieveConf()
     return aResult;
   }
   
-  string aSimanWSHost(aSimanHost);
-  string anEndpointUri = "http://" + aSimanWSHost + "/Siman-WS/services/SimanSalomeService";
+  std::string aSimanWSHost(aSimanHost);
+  std::string anEndpointUri = "http://" + aSimanWSHost + "/Siman-WS/services/SimanSalomeService";
   
   Environment::initialize("SimanSalomeService.log",AXIS2_LOG_LEVEL_DEBUG);
   char* aClientHomeEnv = getenv("WSFCPP_HOME");
@@ -61,7 +78,7 @@ SimanIO_Configuration SimanIO_Link::RetrieveConf()
     return aResult;
   }
   
-  string aClientHome = AXIS2_GETENV("WSFCPP_HOME");
+  std::string aClientHome = AXIS2_GETENV("WSFCPP_HOME");
   SimanSalomeServiceStub* aStub = new SimanSalomeServiceStub(aClientHome, anEndpointUri);
   ServiceClient *client = aStub->getServiceClient();
   
@@ -82,16 +99,15 @@ SimanIO_Configuration SimanIO_Link::RetrieveConf()
   aCreateConfigFileRequest->setArgs1(atoll(myScenario.c_str()));
   aCreateConfigFileRequest->setArgs2(atoll(myUser.c_str()));
   
-  //cout<<"StudyId = " << atoll(myStudy.c_str()) << "\n";
-  //cout<<"ScenarioId = " << atoll(myScenario.c_str()) << "\n";
-  //cout<<"UserId = " << atoll(myUser.c_str()) << "\n";
+  //std::cout<<"StudyId = " << atoll(myStudy.c_str()) << "\n";
+  //std::cout<<"ScenarioId = " << atoll(myScenario.c_str()) << "\n";
+  //std::cout<<"UserId = " << atoll(myUser.c_str()) << "\n";
   
   CreateConfigFileResponse* aCreateConfigFileResponse = new CreateConfigFileResponse();
   aCreateConfigFileResponse = aStub->createConfigFile(aCreateConfigFileRequest);
+  std::string aResponseFilePath = aCreateConfigFileResponse->get_return();
   
-  string aResponseFilePath = aCreateConfigFileResponse->get_return();
-  
-  string aResponseFileName = aResponseFilePath.substr(aResponseFilePath.find_last_of("/\\")+1);
+  std::string aResponseFileName = aResponseFilePath.substr(aResponseFilePath.find_last_of("/\\")+1);
   
   //Get the created config file to client
   
@@ -104,18 +120,18 @@ SimanIO_Configuration SimanIO_Link::RetrieveConf()
   aGetFileResponse = aStub->getFile(aGetFileRequest);
   
   //Parse the response and get the filename
-  string aTmpDir = "/tmp";
-  string aClientFileDir = aTmpDir + "/SimanSalome/" + myStudy + "/" + myScenario + "/" + myUser + "/";
-  //string aClientFileDir = aTmpDir + "/SimanSalome/" +  myUser + "/download/";
-  string aClientFilePath = aClientFileDir + aResponseFileName;
+  std::string aTmpDir = "/tmp";
+  std::string aClientFileDir = aTmpDir + "/SimanSalome/" + myStudy + "/" + myScenario + "/" + myUser + "/";
+  //std::string aClientFileDir = aTmpDir + "/SimanSalome/" +  myUser + "/download/";
+  std::string aClientFilePath = aClientFileDir + aResponseFileName;
   
   //Create the directories
   system(("mkdir -p " + aClientFileDir).c_str());
   system(("chmod -Rf g+w " + aTmpDir + "/SimanSalome/").c_str());
   
   //Download the siman-salome.conf file
-  ofstream outputStream;
-  outputStream.open(aClientFilePath.c_str(), ofstream::binary);
+  std::ofstream outputStream;
+  outputStream.open(aClientFilePath.c_str(), std::ofstream::binary);
   int aBufferSize = axutil_base64_binary_get_decoded_binary_len(aGetFileResponse->get_return(), Environment::getEnv());
   int* aBufSize = new int[aBufferSize];
   unsigned char* aCopyBuffer = axutil_base64_binary_get_plain_binary(aGetFileResponse->get_return(), Environment::getEnv(), aBufSize);
@@ -135,13 +151,13 @@ SimanIO_Configuration SimanIO_Link::RetrieveConf()
       /*const*/ SimanIO_Document& aDoc = aDocIter.Document();
       SimanIO_Document::FilesIterator aFileIter(aDoc);
       for(; aFileIter.More(); aFileIter.Next()) {
-        string aURL = aFileIter.URL();
-        string aFileName = aURL.substr(aURL.find_last_of("/\\")+1);
+        std::string aURL = aFileIter.URL();
+        std::string aFileName = aURL.substr(aURL.find_last_of("/\\")+1);
         int startUnderlineIndex = aFileName.find_first_of("_") + 1;
-        string aSourceFileName = aFileName.substr(startUnderlineIndex);
+        std::string aSourceFileName = aFileName.substr(startUnderlineIndex);
         
-        //cout << "aURL = " << aURL << "\n";
-        string aPathToVault = aResponseFilePath.substr(0, aResponseFilePath.find("download")) + "vault/";
+        //std::cout << "aURL = " << aURL << "\n";
+        std::string aPathToVault = aResponseFilePath.substr(0, aResponseFilePath.find("download")) + "vault/";
         
         //only for test only for WIN
         //replace(aURL.begin(),aURL.end(),'/','\\');
@@ -152,7 +168,7 @@ SimanIO_Configuration SimanIO_Link::RetrieveConf()
         aGetFileRequest->setArgs0(aPathToVault + aURL);
         aGetFileResponse = aStub->getFile(aGetFileRequest);
         
-        outputStream.open((aClientFileDir + aSourceFileName).c_str(), ofstream::binary);
+        outputStream.open((aClientFileDir + aSourceFileName).c_str(), std::ofstream::binary);
         int aBufferSize = axutil_base64_binary_get_decoded_binary_len(aGetFileResponse->get_return(), Environment::getEnv());
         int* aBufSize = new int[aBufferSize];
         unsigned char* aCopyBuffer = axutil_base64_binary_get_plain_binary(aGetFileResponse->get_return(), Environment::getEnv(), aBufSize);
@@ -163,7 +179,7 @@ SimanIO_Configuration SimanIO_Link::RetrieveConf()
 
         //Set new URLs
         aFileIter.SetURL((aClientFileDir + aSourceFileName).c_str());
-        //cout << "New location of the files " << aClientFileDir + aFileName << "\n";
+        //std::cout << "New location of the files " << aClientFileDir + aFileName << "\n";
       }//aFileIter
     }//aDocIter
   }//actIter
@@ -183,15 +199,15 @@ SimanIO_Configuration SimanIO_Link::RetrieveConf()
 
 void SimanIO_Link::StoreConf(/*const*/ SimanIO_Configuration& theConf)
 {
-  cout << "StoreConf method is started\n";
+  std::cout << "StoreConf method is started\n";
   char* aSimanHost = getenv("SIMAN_WS_HOST");
   if (aSimanHost == NULL)
   {
     CONFIGURSION_ERROR("The SIMAN_WS_HOST variable does not exist. Please set it.\n");
   }
   
-  string aSimanWSHost(aSimanHost);
-  string anEndpointUri = "http://" + aSimanWSHost + "/Siman-WS/services/SimanSalomeService";
+  std::string aSimanWSHost(aSimanHost);
+  std::string anEndpointUri = "http://" + aSimanWSHost + "/Siman-WS/services/SimanSalomeService";
   
   Environment::initialize("SimanSalomeService.log",AXIS2_LOG_LEVEL_DEBUG);
   char* aClientHomeEnv = getenv("WSFCPP_HOME");
@@ -201,7 +217,7 @@ void SimanIO_Link::StoreConf(/*const*/ SimanIO_Configuration& theConf)
     CONFIGURSION_ERROR("The WSFCPP_HOME variable does not exist. Please set it.\n");
   }
   
-  string aClientHome = AXIS2_GETENV("WSFCPP_HOME");
+  std::string aClientHome = AXIS2_GETENV("WSFCPP_HOME");
   SimanSalomeServiceStub* aStub = new SimanSalomeServiceStub(aClientHome, anEndpointUri);
   ServiceClient *client = aStub->getServiceClient();
   
@@ -220,11 +236,11 @@ void SimanIO_Link::StoreConf(/*const*/ SimanIO_Configuration& theConf)
   PutFileResponse* aPutFileResponse = new PutFileResponse();
   
   //Prepare salome-siman.conf file
-  string aTmpDir = "/tmp";
-  string aClientFileDir = aTmpDir + "/SimanSalome/" + myStudy + "/" + myScenario + "/" + myUser + "/";
-  //string aClientFileDir = aTmpDir + "/SimanSalome/" +  myUser + "/download/";
-  string aClientFilePath = aClientFileDir + "salome-siman.conf";
-  ofstream aSalomeSimanFile;
+  std::string aTmpDir = "/tmp";
+  std::string aClientFileDir = aTmpDir + "/SimanSalome/" + myStudy + "/" + myScenario + "/" + myUser + "/";
+  //std::string aClientFileDir = aTmpDir + "/SimanSalome/" +  myUser + "/download/";
+  std::string aClientFilePath = aClientFileDir + "salome-siman.conf";
+  std::ofstream aSalomeSimanFile;
   aSalomeSimanFile.open(aClientFilePath.c_str());
   
   //Get the actual file URLs and put these files onto server.
@@ -236,13 +252,13 @@ void SimanIO_Link::StoreConf(/*const*/ SimanIO_Configuration& theConf)
       /*const*/ SimanIO_Document& aDoc = aDocIter.Document();
       SimanIO_Document::FilesIterator aFileIter(aDoc);
       for(; aFileIter.More(); aFileIter.Next()) {
-        string aURL = aFileIter.URL();
-        string aFileName = aURL.substr(aURL.find_last_of("/\\")+1);
-        cout << "aURL = " << aURL << "\n";
-        cout << " aFileName= " << aFileName << "\n";
+        std::string aURL = aFileIter.URL();
+        std::string aFileName = aURL.substr(aURL.find_last_of("/\\")+1);
+        std::cout << "aURL = " << aURL << "\n";
+        std::cout << "aFileName= " << aFileName << "\n";
         //get size of the input file
-        ifstream inputStream (aURL.c_str(), ifstream::binary);
-        inputStream.seekg(0,ifstream::end);
+       std::ifstream inputStream (aURL.c_str(), std::ifstream::binary);
+        inputStream.seekg(0,std::ifstream::end);
         int aSize = inputStream.tellg();
         inputStream.seekg(0);
         
@@ -250,6 +266,7 @@ void SimanIO_Link::StoreConf(/*const*/ SimanIO_Configuration& theConf)
         char* aCopyBuffer;
         aCopyBuffer = new char [aSize];
         inputStream.read(aCopyBuffer,aSize);
+        std::cout << "Upload a file with the size" << aSize << "\n";
         axutil_base64_binary_t* aRequestDH = axutil_base64_binary_create_with_plain_binary(Environment::getEnv(), reinterpret_cast<unsigned char*>(aCopyBuffer), aSize);
         inputStream.close();
         delete[] aCopyBuffer;
@@ -261,12 +278,16 @@ void SimanIO_Link::StoreConf(/*const*/ SimanIO_Configuration& theConf)
         
         aPutFileResponse = aStub->putFile(aPutFileRequest);
         
+        std::cout << "End of upload. New file locaton is: " << aPutFileResponse->get_return() << "\n";
+        
         //Write information into salome-siman.conf file
-        ostringstream activityId;
-        ostringstream documentId;
+       std::ostringstream activityId;
+       std::ostringstream documentId;
         activityId << actIter.ActivityId();
         documentId << aDocIter.DocId();
         aSalomeSimanFile << myScenario +  "," +  myUser + "," + activityId.str() +  "," + documentId.str() + "," + aPutFileResponse->get_return() + "\n";
+       std::cout << "Line in the SalomeSimanFile " << myScenario +  "," +  myUser + "," + activityId.str() +  "," + documentId.str() + "," + aPutFileResponse->get_return() <<"\n";
+        std::cout <<"==========\n";
 
       }//aFileIter
     }//aDocIter
@@ -275,8 +296,8 @@ void SimanIO_Link::StoreConf(/*const*/ SimanIO_Configuration& theConf)
   aSalomeSimanFile.close();
   
   //Put the salome-siman.conf file onto server
-  ifstream inputStream (aClientFilePath.c_str(), ifstream::binary);
-  inputStream.seekg(0,ifstream::end);
+  std::ifstream inputStream (aClientFilePath.c_str(), std::ifstream::binary);
+  inputStream.seekg(0,std::ifstream::end);
   int aSize = inputStream.tellg();
   inputStream.seekg(0);