PageRenderTime 15ms CodeModel.GetById 1ms app.highlight 11ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/llmessage/llxfer_mem.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 218 lines | 121 code | 59 blank | 38 comment | 5 complexity | 1115708c88c47ae5192d3dda28834d6a MD5 | raw file
  1/** 
  2 * @file llxfer_mem.cpp
  3 * @brief implementation of LLXfer_Mem class for a single xfer
  4 *
  5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "linden_common.h"
 28
 29#include "llxfer_mem.h"
 30#include "lluuid.h"
 31#include "llerror.h"
 32#include "llmath.h"
 33
 34///////////////////////////////////////////////////////////
 35
 36LLXfer_Mem::LLXfer_Mem ()
 37: LLXfer(-1)
 38{
 39	init();
 40}
 41
 42///////////////////////////////////////////////////////////
 43
 44LLXfer_Mem::~LLXfer_Mem ()
 45{
 46	cleanup();
 47}
 48
 49///////////////////////////////////////////////////////////
 50
 51void LLXfer_Mem::init ()
 52{
 53	mRemoteFilename.clear();
 54	mRemotePath = LL_PATH_NONE;
 55	mDeleteRemoteOnCompletion = FALSE;
 56}
 57	
 58///////////////////////////////////////////////////////////
 59
 60void LLXfer_Mem::cleanup ()
 61{
 62	LLXfer::cleanup();
 63}
 64
 65///////////////////////////////////////////////////////////
 66
 67void LLXfer_Mem::setXferSize (S32 xfer_size)
 68{	
 69	mXferSize = xfer_size;
 70
 71	delete[] mBuffer;
 72	mBuffer = new char[xfer_size];
 73	
 74	mBufferLength = 0;
 75	mBufferStartOffset = 0;	
 76	mBufferContainsEOF = TRUE;
 77
 78//	cout << "starting transfer of size: " << xfer_size << endl;
 79}
 80
 81///////////////////////////////////////////////////////////
 82
 83U64 LLXfer_Mem::registerXfer(U64 xfer_id, const void *datap, const S32 length)
 84{
 85	mID = xfer_id;
 86
 87	if (datap)
 88	{
 89		setXferSize(length);
 90		if (mBuffer)
 91		{
 92			memcpy(mBuffer,datap,length);		/* Flawfinder : ignore */
 93			mBufferLength = length;
 94		}
 95		else
 96		{
 97			xfer_id = 0;
 98		}
 99	}
100	
101	mStatus = e_LL_XFER_REGISTERED;
102	return (xfer_id);
103}
104
105S32 LLXfer_Mem::startSend (U64 xfer_id, const LLHost &remote_host)
106{
107	S32 retval = LL_ERR_NOERR;  // presume success
108	
109	if (mXferSize <= 0)
110	{
111		return LL_ERR_FILE_EMPTY;
112	}
113
114    mRemoteHost = remote_host;
115	mID = xfer_id;
116   	mPacketNum = -1;
117
118//	cout << "Sending file: " << getFileName() << endl;
119
120	mStatus = e_LL_XFER_PENDING;
121
122	return (retval);
123}
124
125///////////////////////////////////////////////////////////
126
127S32 LLXfer_Mem::processEOF()
128{
129	S32 retval = 0;
130
131	mStatus = e_LL_XFER_COMPLETE;
132
133	llinfos << "xfer complete: " << getFileName() << llendl;
134
135	if (mCallback)
136	{
137		mCallback((void *)mBuffer,mBufferLength,mCallbackDataHandle,mCallbackResult,LL_EXSTAT_NONE);
138	}
139
140	return(retval);
141}
142
143///////////////////////////////////////////////////////////
144
145S32 LLXfer_Mem::initializeRequest(U64 xfer_id,
146								  const std::string& remote_filename,
147								  ELLPath remote_path,
148								  const LLHost& remote_host,
149								  BOOL delete_remote_on_completion,
150								  void (*callback)(void*,S32,void**,S32,LLExtStat),
151								  void** user_data)
152{
153 	S32 retval = 0;  // presume success
154	
155	mRemoteHost = remote_host;
156
157	// create a temp filename string using a GUID
158	mID = xfer_id;
159	mCallback = callback;
160	mCallbackDataHandle = user_data;
161	mCallbackResult = LL_ERR_NOERR;
162
163	mRemoteFilename = remote_filename;
164	mRemotePath = remote_path;
165	mDeleteRemoteOnCompletion = delete_remote_on_completion;
166
167	llinfos << "Requesting file: " << remote_filename << llendl;
168
169	delete [] mBuffer;
170	mBuffer = NULL;
171
172	mBufferLength = 0;
173	mPacketNum = 0;
174 	mStatus = e_LL_XFER_PENDING;
175	return retval;
176}
177
178//////////////////////////////////////////////////////////
179
180S32 LLXfer_Mem::startDownload()
181{
182 	S32 retval = 0;  // presume success
183	gMessageSystem->newMessageFast(_PREHASH_RequestXfer);
184	gMessageSystem->nextBlockFast(_PREHASH_XferID);
185	gMessageSystem->addU64Fast(_PREHASH_ID, mID);
186	gMessageSystem->addStringFast(_PREHASH_Filename, mRemoteFilename);
187	gMessageSystem->addU8("FilePath", (U8) mRemotePath);
188	gMessageSystem->addBOOL("DeleteOnCompletion", mDeleteRemoteOnCompletion);
189	gMessageSystem->addBOOL("UseBigPackets", BOOL(mChunkSize == LL_XFER_LARGE_PAYLOAD));
190	gMessageSystem->addUUIDFast(_PREHASH_VFileID, LLUUID::null);
191	gMessageSystem->addS16Fast(_PREHASH_VFileType, -1);
192
193	gMessageSystem->sendReliable(mRemoteHost);		
194	mStatus = e_LL_XFER_IN_PROGRESS;
195
196	return (retval);
197}
198
199//////////////////////////////////////////////////////////
200
201U32 LLXfer_Mem::getXferTypeTag()
202{
203	return LLXfer::XFER_MEM;
204}
205
206
207
208
209
210
211
212
213
214
215
216
217
218