00001 
00033 #ifndef LL_LLXFERMANAGER_H
00034 #define LL_LLXFERMANAGER_H
00035 
00041 
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 
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; 
00089         LLLinkedQueue<LLXferAckInfo> mXferAckQueue;
00090         LLThrottle mAckThrottle;
00091  public:
00092 
00093         
00094         
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         
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 
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 
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 
00145 
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 
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 
00165 
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 
00174 
00175 
00176 
00177 
00178 
00179 
00180 
00181 
00182 
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 
00189         virtual void processFileRequest (LLMessageSystem *mesgsys, void **user_data);
00190         virtual void processConfirmation (LLMessageSystem *mesgsys, void **user_data);
00191         virtual void retransmitUnackedPackets ();
00192 
00193 
00194         virtual void processAbort (LLMessageSystem *mesgsys, void **user_data);
00195 };
00196 
00197 extern LLXferManager*   gXferManager;
00198 
00199 
00200 void start_xfer_manager(LLVFS *vfs);
00201 void cleanup_xfer_manager();
00202 
00203 
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