Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef FILETRANSFERMGR_H
  7. #define FILETRANSFERMGR_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "inetchannel.h"
  12. typedef int FileTransferID_t;
  13. abstract_class CFileTransferMgr
  14. {
  15. public:
  16. CFileTransferMgr();
  17. virtual ~CFileTransferMgr();
  18. // Start transmitting a file.
  19. // The user data is sent in the header and can include the filename, its ID, or whatever.
  20. FileTransferID_t StartSending(
  21. INetChannel *pDest,
  22. const void *pUserData,
  23. int userDataLength,
  24. const char *pFileData,
  25. int fileLength,
  26. int bytesPerSecond );
  27. // Kill all file transfers on this channel.
  28. void HandleClientDisconnect( INetChannel *pChannel );
  29. // Call this when data comes in.
  30. void HandleReceivedData( INetChannel *pChannel, const void *pData, int len );
  31. // Iterate the list of files being downloaded.
  32. int FirstIncoming() const;
  33. int NextIncoming( int i ) const;
  34. int InvalidIncoming() const;
  35. void GetIncomingUserData( int i, const void* &pData, int &dataLen );
  36. // Overridables.
  37. public:
  38. // Send outgoing data for a file (reliably).
  39. // Returns false if it was unable to send the chunk. If this happens, the file transfer manager
  40. // will retry the chunk a few times, and eventually cancel the file transfer if the problem keeps happening.
  41. virtual bool SendChunk( INetChannel *pDest, const void *pData, int len ) = 0;
  42. // Had to stop sending because there was a problem sending a chunk, or
  43. // the net channel went away.
  44. virtual void OnSendCancelled( FileTransferID_t id ) = 0;
  45. // Called when it's done transmitting a file.
  46. virtual void OnFinishedSending(
  47. INetChannel *pDest,
  48. const void *pUserData,
  49. int userDataLen,
  50. FileTransferID_t id ) = 0;
  51. // Called when a file is received.
  52. virtual void OnFileReceived(
  53. INetChannel *pChan,
  54. const void *pUserData,
  55. int userDataLength,
  56. const char *pFileData,
  57. int fileLength ) = 0;
  58. };
  59. #endif // FILETRANSFERMGR_H