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 "lldir.h"
00049 #include "lllinkedqueue.h"
00050 #include "llthrottle.h"
00051 
00052 class LLHostStatus
00053 {
00054  public:
00055         LLHost mHost;
00056         S32    mNumActive;
00057         S32    mNumPending;
00058 
00059         LLHostStatus() {mNumActive = 0; mNumPending = 0;};
00060         virtual ~LLHostStatus(){};
00061 };
00062 
00063 // Class stores ack information, to be put on list so we can throttle xfer rate.
00064 class LLXferAckInfo
00065 {
00066 public:
00067         LLXferAckInfo(U32 dummy = 0)
00068         {
00069                 mID = 0;
00070                 mPacketNum = -1;
00071         }
00072 
00073         U64 mID;
00074         S32 mPacketNum;
00075         LLHost mRemoteHost;
00076 };
00077 
00078 class LLXferManager
00079 {
00080  private:
00081         LLVFS *mVFS;
00082 
00083  protected:
00084         S32    mMaxOutgoingXfersPerCircuit;
00085         S32    mMaxIncomingXfers;
00086 
00087         BOOL    mUseAckThrottling; // Use ack throttling to cap file xfer bandwidth
00088         LLLinkedQueue<LLXferAckInfo> mXferAckQueue;
00089         LLThrottle mAckThrottle;
00090  public:
00091 
00092         // This enumeration is useful in the requestFile() to specify if
00093         // an xfer must happen asap.
00094         enum
00095         {
00096                 LOW_PRIORITY = FALSE,
00097                 HIGH_PRIORITY = TRUE,
00098         };
00099 
00100         LLXfer *mSendList;
00101         LLXfer *mReceiveList;
00102 
00103         typedef std::list<LLHostStatus*> status_list_t;
00104         status_list_t 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 Fri May 16 08:32:32 2008 for SecondLife by  doxygen 1.5.5