PageRenderTime 37ms CodeModel.GetById 19ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmessage/llxfermanager.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 222 lines | 119 code | 35 blank | 68 comment | 0 complexity | 39abd0a82f1a70ae0b7a436955d1d2ac MD5 | raw file
  1/** 
  2 * @file llxfermanager.h
  3 * @brief definition of LLXferManager class for a keeping track of
  4 * multiple xfers
  5 *
  6 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  7 * Second Life Viewer Source Code
  8 * Copyright (C) 2010, Linden Research, Inc.
  9 * 
 10 * This library is free software; you can redistribute it and/or
 11 * modify it under the terms of the GNU Lesser General Public
 12 * License as published by the Free Software Foundation;
 13 * version 2.1 of the License only.
 14 * 
 15 * This library is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 18 * Lesser General Public License for more details.
 19 * 
 20 * You should have received a copy of the GNU Lesser General Public
 21 * License along with this library; if not, write to the Free Software
 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 23 * 
 24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 25 * $/LicenseInfo$
 26 */
 27
 28#ifndef LL_LLXFERMANAGER_H
 29#define LL_LLXFERMANAGER_H
 30
 31/**
 32 * this manager keeps both a send list and a receive list; anything with a 
 33 * LLXferManager can send and receive files via messages
 34 */
 35
 36//Forward declaration to avoid circular dependencies
 37class LLXfer;
 38class LLVFS;
 39
 40#include "llxfer.h"
 41#include "message.h"
 42#include "llassetstorage.h"
 43#include "lldir.h"
 44#include "lllinkedqueue.h"
 45#include "llthrottle.h"
 46
 47class LLHostStatus
 48{
 49 public:
 50	LLHost mHost;
 51	S32    mNumActive;
 52	S32    mNumPending;
 53
 54	LLHostStatus() {mNumActive = 0; mNumPending = 0;};
 55	virtual ~LLHostStatus(){};
 56};
 57
 58// Class stores ack information, to be put on list so we can throttle xfer rate.
 59class LLXferAckInfo
 60{
 61public:
 62	LLXferAckInfo(U32 dummy = 0)
 63	{
 64		mID = 0;
 65		mPacketNum = -1;
 66	}
 67
 68	U64 mID;
 69	S32 mPacketNum;
 70	LLHost mRemoteHost;
 71};
 72
 73class LLXferManager
 74{
 75 private:
 76	LLVFS *mVFS;
 77
 78 protected:
 79	S32    mMaxOutgoingXfersPerCircuit;
 80	S32    mMaxIncomingXfers;
 81
 82	BOOL	mUseAckThrottling; // Use ack throttling to cap file xfer bandwidth
 83	LLLinkedQueue<LLXferAckInfo> mXferAckQueue;
 84	LLThrottle mAckThrottle;
 85 public:
 86
 87	// This enumeration is useful in the requestFile() to specify if
 88	// an xfer must happen asap.
 89	enum
 90	{
 91		LOW_PRIORITY = FALSE,
 92		HIGH_PRIORITY = TRUE,
 93	};
 94
 95	LLXfer *mSendList;
 96	LLXfer *mReceiveList;
 97
 98	typedef std::list<LLHostStatus*> status_list_t;
 99	status_list_t mOutgoingHosts;
100
101 private:
102 protected:
103	// implementation methods
104	virtual void startPendingDownloads();
105	virtual void addToList(LLXfer* xferp, LLXfer*& head, BOOL is_priority);
106	std::multiset<std::string> mExpectedTransfers; // files that are authorized to transfer out
107	std::multiset<std::string> mExpectedRequests;  // files that are authorized to be downloaded on top of
108
109 public:
110	LLXferManager(LLVFS *vfs);
111	virtual ~LLXferManager();
112
113	virtual void init(LLVFS *vfs);
114	virtual void cleanup();
115
116	void setUseAckThrottling(const BOOL use);
117	void setAckThrottleBPS(const F32 bps);
118
119// list management routines
120	virtual LLXfer *findXfer(U64 id, LLXfer *list_head);
121	virtual void removeXfer (LLXfer *delp, LLXfer **list_head);
122	virtual U32 numActiveListEntries(LLXfer *list_head);
123	virtual S32 numActiveXfers(const LLHost &host);
124	virtual S32 numPendingXfers(const LLHost &host);
125	virtual void changeNumActiveXfers(const LLHost &host, S32 delta);
126
127	virtual void setMaxOutgoingXfersPerCircuit (S32 max_num);
128	virtual void setMaxIncomingXfers(S32 max_num);
129	virtual void updateHostStatus();
130	virtual void printHostStatus();
131
132// general utility routines
133	virtual void registerCallbacks(LLMessageSystem *mesgsys);
134	virtual U64 getNextID ();
135	virtual S32 encodePacketNum(S32 packet_num, BOOL is_eof);	
136	virtual S32 decodePacketNum(S32 packet_num);	
137	virtual BOOL isLastPacket(S32 packet_num);
138
139	virtual U64 registerXfer(const void *datap, const S32 length);
140
141// file requesting routines
142// .. to file
143	virtual void requestFile(const std::string& local_filename,
144							 const std::string& remote_filename,
145							 ELLPath remote_path,
146							 const LLHost& remote_host,
147 							 BOOL delete_remote_on_completion,
148							 void (*callback)(void**,S32,LLExtStat), void** user_data,
149							 BOOL is_priority = FALSE,
150							 BOOL use_big_packets = FALSE);
151
152// .. to memory
153	virtual void requestFile(const std::string& remote_filename, 
154							 ELLPath remote_path,
155							 const LLHost &remote_host,
156 							 BOOL delete_remote_on_completion,
157							 void (*callback)(void*, S32, void**, S32, LLExtStat),
158							 void** user_data,
159							 BOOL is_priority = FALSE);
160
161// vfile requesting
162// .. to vfile
163	virtual void requestVFile(const LLUUID &local_id, const LLUUID& remote_id,
164							  LLAssetType::EType type, LLVFS* vfs,
165							  const LLHost& remote_host,
166							  void (*callback)(void**,S32,LLExtStat), void** user_data,
167							  BOOL is_priority = FALSE);
168	/**
169		When arbitrary files are requested to be transfered (by giving a dir of LL_PATH_NONE)
170	   they must be "expected", but having something pre-authorize them. This pair of functions
171	   maintains a pre-authorized list. The first function adds something to the list, the second
172	   checks if is authorized, removing it if so.  In this way, a file is only authorized for
173	   a single use.
174	*/
175	virtual void expectFileForTransfer(const std::string& filename);
176	virtual bool validateFileForTransfer(const std::string& filename);
177	/**
178		Same idea, but for the viewer about to call InitiateDownload to track what it requested.
179	*/
180	virtual void expectFileForRequest(const std::string& filename);
181	virtual bool validateFileForRequest(const std::string& filename);
182
183/*
184// xfer request (may be memory or file)
185// .. to file
186	virtual void requestXfer(const char *local_filename, U64 xfer_id, 
187							 BOOL delete_remote_on_completion,
188							 const LLHost &remote_host, void (*callback)(void **,S32),void **user_data);
189// .. to memory
190	virtual void requestXfer(U64 xfer_id, 
191							 const LLHost &remote_host, 
192							 BOOL delete_remote_on_completion,
193							 void (*callback)(void *, S32, void **, S32),void **user_data);
194*/
195
196	virtual void processReceiveData (LLMessageSystem *mesgsys, void **user_data);
197	virtual void sendConfirmPacket (LLMessageSystem *mesgsys, U64 id, S32 packetnum, const LLHost &remote_host);
198
199// file sending routines
200	virtual void processFileRequest (LLMessageSystem *mesgsys, void **user_data);
201	virtual void processConfirmation (LLMessageSystem *mesgsys, void **user_data);
202	virtual void retransmitUnackedPackets ();
203
204// error handling
205	virtual void processAbort (LLMessageSystem *mesgsys, void **user_data);
206};
207
208extern LLXferManager*	gXferManager;
209
210// initialization and garbage collection
211void start_xfer_manager(LLVFS *vfs);
212void cleanup_xfer_manager();
213
214// message system callbacks
215void process_confirm_packet (LLMessageSystem *mesgsys, void **user_data);
216void process_request_xfer (LLMessageSystem *mesgsys, void **user_data);
217void continue_file_receive(LLMessageSystem *mesgsys, void **user_data);
218void process_abort_xfer (LLMessageSystem *mesgsys, void **user_data);
219#endif
220
221
222