00001
00033 #ifndef LL_LLTRANSFERMANAGER_H
00034 #define LL_LLTRANSFERMANAGER_H
00035
00036 #include <map>
00037 #include <list>
00038
00039 #include "llhost.h"
00040 #include "lluuid.h"
00041 #include "llthrottle.h"
00042 #include "llpriqueuemap.h"
00043 #include "llassettype.h"
00044
00045
00046
00047
00048
00049
00050
00051
00052 typedef enum e_transfer_channel_type
00053 {
00054 LLTCT_UNKNOWN = 0,
00055 LLTCT_MISC,
00056 LLTCT_ASSET,
00057 LLTCT_NUM_TYPES
00058 } LLTransferChannelType;
00059
00060
00061 typedef enum e_transfer_source_type
00062 {
00063 LLTST_UNKNOWN = 0,
00064 LLTST_FILE,
00065 LLTST_ASSET,
00066 LLTST_SIM_INV_ITEM,
00067 LLTST_SIM_ESTATE,
00068 LLTST_NUM_TYPES
00069 } LLTransferSourceType;
00070
00071
00072 typedef enum e_transfer_target_type
00073 {
00074 LLTTT_UNKNOWN = 0,
00075 LLTTT_FILE,
00076 LLTTT_VFILE,
00077 LLTTT_NUM_TYPES
00078 } LLTransferTargetType;
00079
00080
00081
00082 typedef enum e_status_codes
00083 {
00084 LLTS_OK = 0,
00085 LLTS_DONE = 1,
00086 LLTS_SKIP = 2,
00087 LLTS_ABORT = 3,
00088 LLTS_ERROR = -1,
00089 LLTS_UNKNOWN_SOURCE = -2,
00090 LLTS_INSUFFICIENT_PERMISSIONS = -3
00091 } LLTSCode;
00092
00093
00094 typedef enum e_estate_type
00095 {
00096 ET_Covenant = 0,
00097 ET_NONE = -1
00098 } EstateAssetType;
00099
00100 class LLMessageSystem;
00101 class LLDataPacker;
00102
00103 class LLTransferConnection;
00104 class LLTransferSourceChannel;
00105 class LLTransferTargetChannel;
00106 class LLTransferSourceParams;
00107 class LLTransferTargetParams;
00108 class LLTransferSource;
00109 class LLTransferTarget;
00110
00111 class LLTransferManager
00112 {
00113 public:
00114 LLTransferManager();
00115 virtual ~LLTransferManager();
00116
00117 void init();
00118 void cleanup();
00119
00120 void updateTransfers();
00121 void cleanupConnection(const LLHost &host);
00122
00123
00124 LLTransferSourceChannel *getSourceChannel(const LLHost &host, const LLTransferChannelType stype);
00125 LLTransferTargetChannel *getTargetChannel(const LLHost &host, const LLTransferChannelType stype);
00126
00127 LLTransferSource *findTransferSource(const LLUUID &transfer_id);
00128
00129 BOOL isValid() const { return mValid; }
00130
00131 static void processTransferRequest(LLMessageSystem *mesgsys, void **);
00132 static void processTransferInfo(LLMessageSystem *mesgsys, void **);
00133 static void processTransferPacket(LLMessageSystem *mesgsys, void **);
00134 static void processTransferAbort(LLMessageSystem *mesgsys, void **);
00135
00136 static void reliablePacketCallback(void **, S32 result);
00137
00138 S32 getTransferBitsIn(const LLTransferChannelType tctype) const { return mTransferBitsIn[tctype]; }
00139 S32 getTransferBitsOut(const LLTransferChannelType tctype) const { return mTransferBitsOut[tctype]; }
00140 void resetTransferBitsIn(const LLTransferChannelType tctype) { mTransferBitsIn[tctype] = 0; }
00141 void resetTransferBitsOut(const LLTransferChannelType tctype) { mTransferBitsOut[tctype] = 0; }
00142 void addTransferBitsIn(const LLTransferChannelType tctype, const S32 bits) { mTransferBitsIn[tctype] += bits; }
00143 void addTransferBitsOut(const LLTransferChannelType tctype, const S32 bits) { mTransferBitsOut[tctype] += bits; }
00144 protected:
00145 LLTransferConnection *getTransferConnection(const LLHost &host);
00146 BOOL removeTransferConnection(const LLHost &host);
00147
00148 protected:
00149
00150 typedef std::map<LLHost, LLTransferConnection *> host_tc_map;
00151
00152 BOOL mValid;
00153 LLHost mHost;
00154
00155 S32 mTransferBitsIn[LLTTT_NUM_TYPES];
00156 S32 mTransferBitsOut[LLTTT_NUM_TYPES];
00157
00158
00159 host_tc_map mTransferConnections;
00160 };
00161
00162
00163
00164
00165
00166 class LLTransferConnection
00167 {
00168 public:
00169 LLTransferConnection(const LLHost &host);
00170 virtual ~LLTransferConnection();
00171
00172 void updateTransfers();
00173
00174 LLTransferSourceChannel *getSourceChannel(const LLTransferChannelType type);
00175 LLTransferTargetChannel *getTargetChannel(const LLTransferChannelType type);
00176
00177
00178 typedef std::list<LLTransferSourceChannel *>::iterator tsc_iter;
00179 typedef std::list<LLTransferTargetChannel *>::iterator ttc_iter;
00180 friend class LLTransferManager;
00181 protected:
00182
00183 LLHost mHost;
00184 std::list<LLTransferSourceChannel *> mTransferSourceChannels;
00185 std::list<LLTransferTargetChannel *> mTransferTargetChannels;
00186
00187 };
00188
00189
00190
00191
00192
00193
00194 class LLTransferSourceChannel
00195 {
00196 public:
00197 LLTransferSourceChannel(const LLTransferChannelType channel_type,
00198 const LLHost &host);
00199 virtual ~LLTransferSourceChannel();
00200
00201 void updateTransfers();
00202
00203 void updatePriority(LLTransferSource *tsp, const F32 priority);
00204
00205 void addTransferSource(LLTransferSource *sourcep);
00206 LLTransferSource *findTransferSource(const LLUUID &transfer_id);
00207 BOOL deleteTransfer(LLTransferSource *tsp);
00208
00209 void setThrottleID(const S32 throttle_id) { mThrottleID = throttle_id; }
00210
00211 LLTransferChannelType getChannelType() const { return mChannelType; }
00212 LLHost getHost() const { return mHost; }
00213
00214 protected:
00215 typedef std::list<LLTransferSource *>::iterator ts_iter;
00216
00217 LLTransferChannelType mChannelType;
00218 LLHost mHost;
00219 LLPriQueueMap<LLTransferSource*> mTransferSources;
00220
00221
00222 S32 mThrottleID;
00223 };
00224
00225
00226
00227
00228
00229 class LLTransferTargetChannel
00230 {
00231 public:
00232 LLTransferTargetChannel(const LLTransferChannelType channel_type, const LLHost &host);
00233 virtual ~LLTransferTargetChannel();
00234
00235 void requestTransfer(const LLTransferSourceParams &source_params,
00236 const LLTransferTargetParams &target_params,
00237 const F32 priority);
00238
00239 LLTransferTarget *findTransferTarget(const LLUUID &transfer_id);
00240 BOOL deleteTransfer(LLTransferTarget *ttp);
00241
00242
00243 LLTransferChannelType getChannelType() const { return mChannelType; }
00244 LLHost getHost() const { return mHost; }
00245
00246 protected:
00247 void sendTransferRequest(LLTransferTarget *targetp,
00248 const LLTransferSourceParams ¶ms,
00249 const F32 priority);
00250
00251 void addTransferTarget(LLTransferTarget *targetp);
00252
00253 friend class LLTransferTarget;
00254 friend class LLTransferManager;
00255 protected:
00256 typedef std::list<LLTransferTarget *>::iterator tt_iter;
00257
00258 LLTransferChannelType mChannelType;
00259 LLHost mHost;
00260 std::list<LLTransferTarget *> mTransferTargets;
00261 };
00262
00263
00264 class LLTransferSourceParams
00265 {
00266 public:
00267 LLTransferSourceParams(const LLTransferSourceType type) : mType(type) { }
00268 virtual ~LLTransferSourceParams();
00269
00270 virtual void packParams(LLDataPacker &dp) const = 0;
00271 virtual BOOL unpackParams(LLDataPacker &dp) = 0;
00272
00273 LLTransferSourceType getType() const { return mType; }
00274
00275 protected:
00276 LLTransferSourceType mType;
00277 };
00278
00279
00280
00281
00282
00283 typedef LLTransferSource *(*LLTransferSourceCreateFunc)(const LLUUID &id, const F32 priority);
00284
00285 class LLTransferSource
00286 {
00287 public:
00288
00289 LLUUID getID() { return mID; }
00290
00291 friend class LLTransferManager;
00292 friend class LLTransferSourceChannel;
00293
00294 protected:
00295 LLTransferSource(const LLTransferSourceType source_type,
00296 const LLUUID &request_id,
00297 const F32 priority);
00298 virtual ~LLTransferSource();
00299
00300 void sendTransferStatus(LLTSCode status);
00301
00302 virtual void initTransfer() = 0;
00303 virtual F32 updatePriority() = 0;
00304 virtual LLTSCode dataCallback(const S32 packet_id,
00305 const S32 max_bytes,
00306 U8 **datap,
00307 S32 &returned_bytes,
00308 BOOL &delete_returned) = 0;
00309
00310
00311 virtual void completionCallback(const LLTSCode status) = 0;
00312
00313 virtual void packParams(LLDataPacker& dp) const = 0;
00314 virtual BOOL unpackParams(LLDataPacker& dp) = 0;
00315
00316 virtual S32 getNextPacketID() { return mLastPacketID + 1; }
00317 virtual void setLastPacketID(const S32 packet_id) { mLastPacketID = packet_id; }
00318
00319
00320
00321 F32 getPriority() { return mPriority; }
00322 void setPriority(const F32 pri) { mPriority = pri; }
00323
00324 virtual void abortTransfer();
00325
00326 static LLTransferSource *createSource(const LLTransferSourceType stype,
00327 const LLUUID &request_id,
00328 const F32 priority);
00329 static void registerSourceType(const LLTransferSourceType stype, LLTransferSourceCreateFunc);
00330
00331 static void sSetPriority(LLTransferSource *&tsp, const F32 priority);
00332 static F32 sGetPriority(LLTransferSource *&tsp);
00333 protected:
00334 typedef std::map<LLTransferSourceType, LLTransferSourceCreateFunc> stype_scfunc_map;
00335 static stype_scfunc_map sSourceCreateMap;
00336
00337 LLTransferSourceType mType;
00338 LLUUID mID;
00339 LLTransferSourceChannel *mChannelp;
00340 F32 mPriority;
00341 S32 mSize;
00342 S32 mLastPacketID;
00343 };
00344
00345
00346 class LLTransferTargetParams
00347 {
00348 public:
00349 LLTransferTargetParams(const LLTransferTargetType type) : mType(type) {}
00350 LLTransferTargetType getType() const { return mType; }
00351 protected:
00352 LLTransferTargetType mType;
00353 };
00354
00355
00356 class LLTransferPacket
00357 {
00358
00359
00360 friend class LLTransferTarget;
00361 friend class LLTransferManager;
00362
00363 protected:
00364
00365 LLTransferPacket(const S32 packet_id, const LLTSCode status, const U8 *datap, const S32 size);
00366 virtual ~LLTransferPacket();
00367
00368 protected:
00369 S32 mPacketID;
00370 LLTSCode mStatus;
00371 U8 *mDatap;
00372 S32 mSize;
00373 };
00374
00375
00376 class LLTransferTarget
00377 {
00378 public:
00379 LLTransferTarget(
00380 LLTransferTargetType target_type,
00381 const LLUUID& transfer_id,
00382 LLTransferSourceType source_type);
00383 virtual ~LLTransferTarget();
00384
00385
00386 LLUUID getID() const { return mID; }
00387 LLTransferTargetType getType() const { return mType; }
00388 LLTransferTargetChannel *getChannel() const { return mChannelp; }
00389 LLTransferSourceType getSourceType() const { return mSourceType; }
00390
00391
00392 static LLTransferTarget* createTarget(
00393 LLTransferTargetType target_type,
00394 const LLUUID& request_id,
00395 LLTransferSourceType source_type);
00396
00397
00398 friend class LLTransferManager;
00399 friend class LLTransferTargetChannel;
00400
00401 protected:
00402
00403 virtual bool unpackParams(LLDataPacker& dp) = 0;
00404 virtual void applyParams(const LLTransferTargetParams ¶ms) = 0;
00405 virtual LLTSCode dataCallback(const S32 packet_id, U8 *in_datap, const S32 in_size) = 0;
00406
00407
00408
00409 virtual void completionCallback(const LLTSCode status) = 0;
00410
00411 void abortTransfer();
00412
00413 virtual S32 getNextPacketID() { return mLastPacketID + 1; }
00414 virtual void setLastPacketID(const S32 packet_id) { mLastPacketID = packet_id; }
00415 void setSize(const S32 size) { mSize = size; }
00416 void setGotInfo(const BOOL got_info) { mGotInfo = got_info; }
00417 BOOL gotInfo() const { return mGotInfo; }
00418
00419 bool addDelayedPacket(
00420 const S32 packet_id,
00421 const LLTSCode status,
00422 U8* datap,
00423 const S32 size);
00424
00425 protected:
00426 typedef std::map<S32, LLTransferPacket *> transfer_packet_map;
00427 typedef std::map<S32, LLTransferPacket *>::iterator tpm_iter;
00428
00429 LLTransferTargetType mType;
00430 LLTransferSourceType mSourceType;
00431 LLUUID mID;
00432 LLTransferTargetChannel *mChannelp;
00433 BOOL mGotInfo;
00434 S32 mSize;
00435 S32 mLastPacketID;
00436
00437 transfer_packet_map mDelayedPacketMap;
00438 };
00439
00440
00441
00442 class LLTransferSourceParamsInvItem: public LLTransferSourceParams
00443 {
00444 public:
00445 LLTransferSourceParamsInvItem();
00446 virtual ~LLTransferSourceParamsInvItem() {}
00447 void packParams(LLDataPacker &dp) const;
00448 BOOL unpackParams(LLDataPacker &dp);
00449
00450 void setAgentSession(const LLUUID &agent_id, const LLUUID &session_id);
00451 void setInvItem(const LLUUID &owner_id, const LLUUID &task_id, const LLUUID &item_id);
00452 void setAsset(const LLUUID &asset_id, const LLAssetType::EType at);
00453
00454 LLUUID getAgentID() const { return mAgentID; }
00455 LLUUID getSessionID() const { return mSessionID; }
00456 LLUUID getOwnerID() const { return mOwnerID; }
00457 LLUUID getTaskID() const { return mTaskID; }
00458 LLUUID getItemID() const { return mItemID; }
00459 LLUUID getAssetID() const { return mAssetID; }
00460 LLAssetType::EType getAssetType() const { return mAssetType; }
00461
00462 protected:
00463 LLUUID mAgentID;
00464 LLUUID mSessionID;
00465 LLUUID mOwnerID;
00466 LLUUID mTaskID;
00467 LLUUID mItemID;
00468 LLUUID mAssetID;
00469 LLAssetType::EType mAssetType;
00470 };
00471
00472
00473
00474 class LLTransferSourceParamsEstate: public LLTransferSourceParams
00475 {
00476 public:
00477 LLTransferSourceParamsEstate();
00478 virtual ~LLTransferSourceParamsEstate() {}
00479 void packParams(LLDataPacker &dp) const;
00480 BOOL unpackParams(LLDataPacker &dp);
00481
00482 void setAgentSession(const LLUUID &agent_id, const LLUUID &session_id);
00483 void setEstateAssetType(const EstateAssetType etype);
00484 void setAsset(const LLUUID &asset_id, const LLAssetType::EType at);
00485
00486 LLUUID getAgentID() const { return mAgentID; }
00487 LLUUID getSessionID() const { return mSessionID; }
00488 EstateAssetType getEstateAssetType() const { return mEstateAssetType; }
00489 LLUUID getAssetID() const { return mAssetID; }
00490 LLAssetType::EType getAssetType() const { return mAssetType; }
00491
00492 protected:
00493 LLUUID mAgentID;
00494 LLUUID mSessionID;
00495 EstateAssetType mEstateAssetType;
00496
00497 LLUUID mAssetID;
00498 LLAssetType::EType mAssetType;
00499 };
00500
00501
00502 extern LLTransferManager gTransferManager;
00503
00504 #endif//LL_LLTRANSFERMANAGER_H