llxfermanager.h

Go to the documentation of this file.
00001 
00033 #ifndef LL_LLXFERMANAGER_H
00034 #define LL_LLXFERMANAGER_H
00035 
00041 //Forward declaration to avoid circular dependencies
00042 class LLXfer;
00043 class LLVFS;
00044 
00045 #include "llxfer.h"
00046 #include "message.h"
00047 #include "llassetstorage.h"
00048 #include "linked_lists.h"
00049 #include "lldir.h"
00050 #include "lllinkedqueue.h"
00051 #include "llthrottle.h"
00052 
00053 class LLHostStatus
00054 {
00055  public:
00056         LLHost mHost;
00057         S32    mNumActive;
00058         S32    mNumPending;
00059 
00060         LLHostStatus() {mNumActive = 0; mNumPending = 0;};
00061         virtual ~LLHostStatus(){};
00062 };
00063 
00064 // Class stores ack information, to be put on list so we can throttle xfer rate.
00065 class LLXferAckInfo
00066 {
00067 public:
00068         LLXferAckInfo(U32 dummy = 0)
00069         {
00070                 mID = 0;
00071                 mPacketNum = -1;
00072         }
00073 
00074         U64 mID;
00075         S32 mPacketNum;
00076         LLHost mRemoteHost;
00077 };
00078 
00079 class LLXferManager
00080 {
00081  private:
00082         LLVFS *mVFS;
00083 
00084  protected:
00085         S32    mMaxOutgoingXfersPerCircuit;
00086         S32    mMaxIncomingXfers;
00087 
00088         BOOL    mUseAckThrottling; // Use ack throttling to cap file xfer bandwidth
00089         LLLinkedQueue<LLXferAckInfo> mXferAckQueue;
00090         LLThrottle mAckThrottle;
00091  public:
00092 
00093         // This enumeration is useful in the requestFile() to specify if
00094         // an xfer must happen asap.
00095         enum
00096         {
00097                 LOW_PRIORITY = FALSE,
00098                 HIGH_PRIORITY = TRUE,
00099         };
00100 
00101         LLXfer *mSendList;
00102         LLXfer *mReceiveList;
00103 
00104         LLLinkedList <LLHostStatus> mOutgoingHosts;
00105 
00106  private:
00107  protected:
00108         // implementation methods
00109         virtual void startPendingDownloads();
00110         virtual void addToList(LLXfer* xferp, LLXfer*& head, BOOL is_priority);
00111 
00112  public:
00113         LLXferManager(LLVFS *vfs);
00114         virtual ~LLXferManager();
00115 
00116         virtual void init(LLVFS *vfs);
00117         virtual void free();
00118 
00119         void setUseAckThrottling(const BOOL use);
00120         void setAckThrottleBPS(const F32 bps);
00121 
00122 // list management routines
00123         virtual LLXfer *findXfer(U64 id, LLXfer *list_head);
00124         virtual void removeXfer (LLXfer *delp, LLXfer **list_head);
00125         virtual U32 numActiveListEntries(LLXfer *list_head);
00126         virtual S32 numActiveXfers(const LLHost &host);
00127         virtual S32 numPendingXfers(const LLHost &host);
00128         virtual void changeNumActiveXfers(const LLHost &host, S32 delta);
00129 
00130         virtual void setMaxOutgoingXfersPerCircuit (S32 max_num);
00131         virtual void setMaxIncomingXfers(S32 max_num);
00132         virtual void updateHostStatus();
00133         virtual void printHostStatus();
00134 
00135 // general utility routines
00136         virtual void registerCallbacks(LLMessageSystem *mesgsys);
00137         virtual U64 getNextID ();
00138         virtual S32 encodePacketNum(S32 packet_num, BOOL is_eof);       
00139         virtual S32 decodePacketNum(S32 packet_num);    
00140         virtual BOOL isLastPacket(S32 packet_num);
00141 
00142         virtual U64 registerXfer(const void *datap, const S32 length);
00143 
00144 // file requesting routines
00145 // .. to file
00146         virtual void requestFile(const char* local_filename,
00147                                                          const char* remote_filename,
00148                                                          ELLPath remote_path,
00149                                                          const LLHost& remote_host,
00150                                                          BOOL delete_remote_on_completion,
00151                                                          void (*callback)(void**,S32,LLExtStat), void** user_data,
00152                                                          BOOL is_priority = FALSE,
00153                                                          BOOL use_big_packets = FALSE);
00154 
00155 // .. to memory
00156         virtual void requestFile(const char* remote_filename, 
00157                                                          ELLPath remote_path,
00158                                                          const LLHost &remote_host,
00159                                                          BOOL delete_remote_on_completion,
00160                                                          void (*callback)(void*, S32, void**, S32, LLExtStat),
00161                                                          void** user_data,
00162                                                          BOOL is_priority = FALSE);
00163 
00164 // vfile requesting
00165 // .. to vfile
00166         virtual void requestVFile(const LLUUID &local_id, const LLUUID& remote_id,
00167                                                           LLAssetType::EType type, LLVFS* vfs,
00168                                                           const LLHost& remote_host,
00169                                                           void (*callback)(void**,S32,LLExtStat), void** user_data,
00170                                                           BOOL is_priority = FALSE);
00171 
00172 /*
00173 // xfer request (may be memory or file)
00174 // .. to file
00175         virtual void requestXfer(const char *local_filename, U64 xfer_id, 
00176                                                          BOOL delete_remote_on_completion,
00177                                                          const LLHost &remote_host, void (*callback)(void **,S32),void **user_data);
00178 // .. to memory
00179         virtual void requestXfer(U64 xfer_id, 
00180                                                          const LLHost &remote_host, 
00181                                                          BOOL delete_remote_on_completion,
00182                                                          void (*callback)(void *, S32, void **, S32),void **user_data);
00183 */
00184 
00185         virtual void processReceiveData (LLMessageSystem *mesgsys, void **user_data);
00186         virtual void sendConfirmPacket (LLMessageSystem *mesgsys, U64 id, S32 packetnum, const LLHost &remote_host);
00187 
00188 // file sending routines
00189         virtual void processFileRequest (LLMessageSystem *mesgsys, void **user_data);
00190         virtual void processConfirmation (LLMessageSystem *mesgsys, void **user_data);
00191         virtual void retransmitUnackedPackets ();
00192 
00193 // error handling
00194         virtual void processAbort (LLMessageSystem *mesgsys, void **user_data);
00195 };
00196 
00197 extern LLXferManager*   gXferManager;
00198 
00199 // initialization and garbage collection
00200 void start_xfer_manager(LLVFS *vfs);
00201 void cleanup_xfer_manager();
00202 
00203 // message system callbacks
00204 void process_confirm_packet (LLMessageSystem *mesgsys, void **user_data);
00205 void process_request_xfer (LLMessageSystem *mesgsys, void **user_data);
00206 void continue_file_receive(LLMessageSystem *mesgsys, void **user_data);
00207 void process_abort_xfer (LLMessageSystem *mesgsys, void **user_data);
00208 #endif
00209 
00210 
00211 

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