Skip to content

Commit aae72dc

Browse files
committed
Add FileTransferClient
1 parent a7206c9 commit aae72dc

File tree

5 files changed

+87
-99
lines changed

5 files changed

+87
-99
lines changed

src/Core/Services/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ SET(Core_Services_SRCS
3737
ServiceClient.cc
3838
#SimpleService.cc
3939
#FileTransfer.cc
40-
#FileTransferClient.cc
40+
FileTransferClient.cc
4141
)
4242

4343
SET(Core_Services_HEADERS

src/Core/Services/FileTransferClient.cc

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,29 @@
2727
*/
2828

2929
#include <Core/Services/FileTransferClient.h>
30+
#include <Core/Services/FileTransfer.h>
31+
#include <Core/SystemCall/TempFileManager.h>
32+
#include <Core/Services/Service.h>
33+
#include <Core/ICom/IComPacket.h>
3034

3135
namespace SCIRun {
3236

3337

3438
FileTransferClient::FileTransferClient() :
35-
fileidcnt_(1),
36-
buffersize_(1000000)
39+
tfm_(new TempFileManager),
40+
fileidcnt_(1),
41+
buffersize_(1000000)
3742
{
3843
}
3944

4045
FileTransferClient::~FileTransferClient()
4146
{
42-
if (tempdir_ != "") tfm_.delete_tempdir(tempdir_);
47+
if (tempdir_ != "") tfm_->delete_tempdir(tempdir_);
4348
tempdir_ = "";
4449
}
4550

4651

47-
bool FileTransferClient::open(IComAddress address, std::string servicename, int session, std::string passwd)
52+
bool FileTransferClient::open(IComAddressHandle address, std::string servicename, int session, std::string passwd)
4853
{
4954
if(!(ServiceClient::open(address,servicename,session,passwd)))
5055
{
@@ -73,8 +78,8 @@ bool FileTransferClient::open(IComAddress address, std::string servicename, int
7378
remote_homedirid_ = data[0];
7479
remote_scirun_tempdir_ = data[1];
7580

76-
local_homedirid_ = tfm_.get_homedirID();
77-
local_scirun_tempdir_ = tfm_.get_scirun_tmp_dir();
81+
local_homedirid_ = tfm_->get_homedirID();
82+
local_scirun_tempdir_ = tfm_->get_scirun_tmp_dir();
7883
return(true);
7984
}
8085
seterror("File transfer service returned an unknown packet");
@@ -85,8 +90,8 @@ bool FileTransferClient::open(IComAddress address, std::string servicename, int
8590

8691
bool FileTransferClient::create_remote_tempdir(std::string pattern,std::string &tempdir)
8792
{
88-
IComPacketHandle packet = new IComPacket;
89-
if (packet.get_rep() == 0)
93+
IComPacketHandle packet(new IComPacket);
94+
if (!packet)
9095
{
9196
seterror("Could not create IComPacket");
9297
tempdir = "";
@@ -124,7 +129,7 @@ bool FileTransferClient::create_remote_tempdir(std::string pattern,std::string &
124129

125130
bool FileTransferClient::create_local_tempdir(std::string pattern,std::string &tempdir)
126131
{
127-
return(tfm_.create_tempdir(pattern,tempdir));
132+
return(tfm_->create_tempdir(pattern,tempdir));
128133
}
129134

130135

@@ -133,7 +138,7 @@ bool FileTransferClient::get_local_homedirid(std::string& homeid)
133138
homeid = local_homedirid_;
134139
if (homeid == "")
135140
{
136-
local_homedirid_ = tfm_.get_homedirID();
141+
local_homedirid_ = tfm_->get_homedirID();
137142
homeid = local_homedirid_;
138143
if (homeid == "") return(false);
139144
}
@@ -152,7 +157,7 @@ bool FileTransferClient::get_local_scirun_tempdir(std::string& tempdir)
152157
tempdir = local_scirun_tempdir_;
153158
if (tempdir == "")
154159
{
155-
local_scirun_tempdir_ = tfm_.get_scirun_tmp_dir();
160+
local_scirun_tempdir_ = tfm_->get_scirun_tmp_dir();
156161
tempdir = local_scirun_tempdir_;
157162
if (tempdir == "") return(false);
158163
}
@@ -219,8 +224,8 @@ bool FileTransferClient::get_file(std::string remotefilename,std::string localfi
219224
return(false);
220225
}
221226

222-
IComPacketHandle packet = new IComPacket;
223-
if (packet.get_rep() == 0)
227+
IComPacketHandle packet(new IComPacket);
228+
if (!packet)
224229
{
225230
::fclose(localfile);
226231
seterror("Could not create IComPacket");
@@ -322,8 +327,8 @@ bool FileTransferClient::put_file(std::string localfilename,std::string remotefi
322327
return(false);
323328
}
324329

325-
IComPacketHandle packet = new IComPacket;
326-
if (packet.get_rep() == 0)
330+
IComPacketHandle packet(new IComPacket);
331+
if (!packet)
327332
{
328333
seterror("Could not create IComPacket");
329334
::fclose(localfile);
@@ -376,7 +381,7 @@ bool FileTransferClient::put_file(std::string localfilename,std::string remotefi
376381
}
377382

378383
int seekpos = packet->getparam1();
379-
int bytesread = 0;
384+
size_t bytesread = 0;
380385

381386
packet->clear();
382387
packet->newbuffer(buffersize_);
@@ -385,16 +390,6 @@ bool FileTransferClient::put_file(std::string localfilename,std::string remotefi
385390

386391
bytesread = ::fread(packet->getbuffer(),1,buffersize_,localfile);
387392

388-
if (bytesread < 0)
389-
{
390-
::fclose(localfile);
391-
packet->clear();
392-
packet->settag(TAG_FRESET);
393-
send(packet);
394-
seterror("Error reading local file");
395-
return(false);
396-
}
397-
398393
if (bytesread < buffersize_)
399394
{
400395
packet->setdatasize(bytesread);
@@ -423,6 +418,29 @@ bool FileTransferClient::put_file(std::string localfilename,std::string remotefi
423418

424419

425420

421+
bool FileTransferClient::set_local_dir(std::string dir)
422+
{
423+
if (dir[dir.size() - 1] != '/') dir += '/';
424+
local_dir_ = dir;
425+
return(true);
426+
}
427+
428+
bool FileTransferClient::set_remote_dir(std::string dir)
429+
{
430+
if (dir[dir.size() - 1] != '/') dir += '/';
431+
remote_dir_ = dir;
432+
return(true);
433+
}
434+
435+
std::string FileTransferClient::local_file(std::string filename)
436+
{
437+
return(local_dir_ + filename);
438+
}
439+
440+
std::string FileTransferClient::remote_file(std::string filename)
441+
{
442+
return(remote_dir_ + filename);
443+
}
426444

427445
} // end namespace
428446

src/Core/Services/FileTransferClient.h

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,7 @@
2929
#ifndef CORE_SERVICES_FILETRANSFERCLIENT_H
3030
#define CORE_SERVICES_FILETRANSFERCLIENT_H 1
3131

32-
#include <Core/Services/Service.h>
3332
#include <Core/Services/ServiceClient.h>
34-
#include <Core/Services/FileTransfer.h>
35-
#include <Core/SystemCall/TempFileManager.h>
36-
#include <stdio.h>
37-
3833
#include <Core/Services/share.h>
3934

4035
namespace SCIRun {
@@ -50,7 +45,7 @@ class SCISHARE FileTransferClient : public ServiceClient
5045
// open this service. This overloaded open function will deal as well with the first packet send
5146
// by the service, which is an information packet. Containing location and ID of the remote home
5247
// directory
53-
bool open(IComAddress address, std::string servicename, int session, std::string passwd);
48+
virtual bool open(IComAddressHandle address, std::string servicename, int session, std::string passwd) override;
5449

5550
// Create temp directories on the local and remote site. The pattern is a name ending with
5651
// XXXXXX which will be replace by an uniquely generated string of numbers and letters
@@ -103,39 +98,15 @@ class SCISHARE FileTransferClient : public ServiceClient
10398
std::string remote_dir_;
10499
std::string local_dir_;
105100

106-
TempFileManager tfm_;
101+
boost::shared_ptr<class TempFileManager> tfm_;
107102

108103
int fileidcnt_;
109104
int buffersize_;
110105
};
111106

112107

113-
typedef LockingHandle<FileTransferClient> FileTransferClientHandle;
114-
115-
inline bool FileTransferClient::set_local_dir(std::string dir)
116-
{
117-
if (dir[dir.size()-1] != '/') dir +='/';
118-
local_dir_ = dir;
119-
return(true);
120-
}
108+
typedef boost::shared_ptr<FileTransferClient> FileTransferClientHandle;
121109

122-
inline bool FileTransferClient::set_remote_dir(std::string dir)
123-
{
124-
if (dir[dir.size()-1] != '/') dir +='/';
125-
remote_dir_ = dir;
126-
return(true);
127-
}
128-
129-
inline std::string FileTransferClient::local_file(std::string filename)
130-
{
131-
return(local_dir_+filename);
132-
}
133-
134-
inline std::string FileTransferClient::remote_file(std::string filename)
135-
{
136-
return(remote_dir_+filename);
137-
}
138-
139110

140111

141112
} // end namespace

src/Core/Services/ServiceClient.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ class SCISHARE ServiceClient : public ServiceBase
4343
{
4444
public:
4545
ServiceClient();
46-
~ServiceClient();
46+
virtual ~ServiceClient();
4747

48-
bool open(IComAddressHandle address, std::string servicename,
48+
virtual bool open(IComAddressHandle address, std::string servicename,
4949
int session, std::string passwd);
5050

51-
bool open(IComAddressHandle address, std::string servicename,
51+
virtual bool open(IComAddressHandle address, std::string servicename,
5252
int session, std::string passwd,
5353
int timeout, std::string startcommand);
5454

0 commit comments

Comments
 (0)