llxfer_mem.cpp

Go to the documentation of this file.
00001 
00032 #include "linden_common.h"
00033 
00034 #include "llxfer_mem.h"
00035 #include "lluuid.h"
00036 #include "llerror.h"
00037 #include "llmath.h"
00038 
00040 
00041 LLXfer_Mem::LLXfer_Mem ()
00042 : LLXfer(-1)
00043 {
00044         init();
00045 }
00046 
00048 
00049 LLXfer_Mem::~LLXfer_Mem ()
00050 {
00051         free();
00052 }
00053 
00055 
00056 void LLXfer_Mem::init ()
00057 {
00058         mRemoteFilename[0] = '\0';
00059         mRemotePath = LL_PATH_NONE;
00060         mDeleteRemoteOnCompletion = FALSE;
00061 }
00062         
00064 
00065 void LLXfer_Mem::free ()
00066 {
00067         LLXfer::free();
00068 }
00069 
00071 
00072 void LLXfer_Mem::setXferSize (S32 xfer_size)
00073 {       
00074         mXferSize = xfer_size;
00075 
00076         delete[] mBuffer;
00077         mBuffer = new char[xfer_size];
00078         
00079         mBufferLength = 0;
00080         mBufferStartOffset = 0; 
00081         mBufferContainsEOF = TRUE;
00082 
00083 //      cout << "starting transfer of size: " << xfer_size << endl;
00084 }
00085 
00087 
00088 U64 LLXfer_Mem::registerXfer(U64 xfer_id, const void *datap, const S32 length)
00089 {
00090         mID = xfer_id;
00091 
00092         if (datap)
00093         {
00094                 setXferSize(length);
00095                 if (mBuffer)
00096                 {
00097                         memcpy(mBuffer,datap,length);           /* Flawfinder : ignore */
00098                         mBufferLength = length;
00099                 }
00100                 else
00101                 {
00102                         xfer_id = 0;
00103                 }
00104         }
00105         
00106         mStatus = e_LL_XFER_REGISTERED;
00107         return (xfer_id);
00108 }
00109 
00110 S32 LLXfer_Mem::startSend (U64 xfer_id, const LLHost &remote_host)
00111 {
00112         S32 retval = LL_ERR_NOERR;  // presume success
00113         
00114         if (mXferSize <= 0)
00115         {
00116                 return LL_ERR_FILE_EMPTY;
00117         }
00118 
00119     mRemoteHost = remote_host;
00120         mID = xfer_id;
00121         mPacketNum = -1;
00122 
00123 //      cout << "Sending file: " << getName() << endl;
00124 
00125         mStatus = e_LL_XFER_PENDING;
00126 
00127         return (retval);
00128 }
00129 
00131 
00132 S32 LLXfer_Mem::processEOF()
00133 {
00134         S32 retval = 0;
00135 
00136         mStatus = e_LL_XFER_COMPLETE;
00137 
00138         llinfos << "xfer complete: " << getName() << llendl;
00139 
00140         if (mCallback)
00141         {
00142                 mCallback((void *)mBuffer,mBufferLength,mCallbackDataHandle,mCallbackResult,LL_EXSTAT_NONE);
00143         }
00144 
00145         return(retval);
00146 }
00147 
00149 
00150 S32 LLXfer_Mem::initializeRequest(U64 xfer_id,
00151                                                                   const std::string& remote_filename,
00152                                                                   ELLPath remote_path,
00153                                                                   const LLHost& remote_host,
00154                                                                   BOOL delete_remote_on_completion,
00155                                                                   void (*callback)(void*,S32,void**,S32,LLExtStat),
00156                                                                   void** user_data)
00157 {
00158         S32 retval = 0;  // presume success
00159         
00160         mRemoteHost = remote_host;
00161 
00162         // create a temp filename string using a GUID
00163         mID = xfer_id;
00164         mCallback = callback;
00165         mCallbackDataHandle = user_data;
00166         mCallbackResult = LL_ERR_NOERR;
00167 
00168         strncpy(mRemoteFilename, remote_filename.c_str(), LL_MAX_PATH-1);
00169         mRemoteFilename[LL_MAX_PATH-1] = '\0'; // stupid strncpy.
00170         mRemotePath = remote_path;
00171         mDeleteRemoteOnCompletion = delete_remote_on_completion;
00172 
00173         llinfos << "Requesting file: " << remote_filename << llendl;
00174 
00175         delete [] mBuffer;
00176         mBuffer = NULL;
00177 
00178         mBufferLength = 0;
00179         mPacketNum = 0;
00180         mStatus = e_LL_XFER_PENDING;
00181         return retval;
00182 }
00183 
00185 
00186 S32 LLXfer_Mem::startDownload()
00187 {
00188         S32 retval = 0;  // presume success
00189         gMessageSystem->newMessageFast(_PREHASH_RequestXfer);
00190         gMessageSystem->nextBlockFast(_PREHASH_XferID);
00191         gMessageSystem->addU64Fast(_PREHASH_ID, mID);
00192         gMessageSystem->addStringFast(_PREHASH_Filename, mRemoteFilename);
00193         gMessageSystem->addU8("FilePath", (U8) mRemotePath);
00194         gMessageSystem->addBOOL("DeleteOnCompletion", mDeleteRemoteOnCompletion);
00195         gMessageSystem->addBOOL("UseBigPackets", BOOL(mChunkSize == LL_XFER_LARGE_PAYLOAD));
00196         gMessageSystem->addUUIDFast(_PREHASH_VFileID, LLUUID::null);
00197         gMessageSystem->addS16Fast(_PREHASH_VFileType, -1);
00198 
00199         gMessageSystem->sendReliable(mRemoteHost);              
00200         mStatus = e_LL_XFER_IN_PROGRESS;
00201 
00202         return (retval);
00203 }
00204 
00206 
00207 U32 LLXfer_Mem::getXferTypeTag()
00208 {
00209         return LLXfer::XFER_MEM;
00210 }
00211 
00212 
00213 
00214 
00215 
00216 
00217 
00218 
00219 
00220 
00221 
00222 
00223 
00224 

Generated on Thu Jul 1 06:09:47 2010 for Second Life Viewer by  doxygen 1.4.7