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.

129 lines
4.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef VMPI_FILESYSTEM_INTERNAL_H
  7. #define VMPI_FILESYSTEM_INTERNAL_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "vmpi_filesystem.h"
  12. #include "filesystem.h"
  13. #include "messbuf.h"
  14. #include "iphelpers.h"
  15. #include "vmpi.h"
  16. #include "utlvector.h"
  17. #include "utllinkedlist.h"
  18. #include "filesystem_passthru.h"
  19. // Sub packet IDs specific to the VMPI file system.
  20. #define VMPI_FSPACKETID_FILE_REQUEST 1 // Sent by the worker to request a file.
  21. #define VMPI_FSPACKETID_FILE_RESPONSE 2 // Master's response to a file request.
  22. #define VMPI_FSPACKETID_CHUNK_RECEIVED 3 // Sent by workers to tell the master they received a chunk.
  23. #define VMPI_FSPACKETID_FILE_RECEIVED 4 // Sent by workers to tell the master they received the whole file.
  24. #define VMPI_FSPACKETID_MULTICAST_ADDR 5
  25. #define VMPI_FSPACKETID_FILE_CHUNK 6 // Used to send file data when using TCP.
  26. // In TCP mode, we send larger chunks in a sliding window.
  27. #define TCP_CHUNK_QUEUE_LEN 16
  28. #define TCP_CHUNK_PAYLOAD_SIZE (16*1024)
  29. #define MULTICAST_CHUNK_PAYLOAD_SIZE (1024*1)
  30. #define MAX_CHUNK_PAYLOAD_SIZE MAX( TCP_CHUNK_PAYLOAD_SIZE, MULTICAST_CHUNK_PAYLOAD_SIZE )
  31. class CMulticastFileInfo
  32. {
  33. public:
  34. unsigned long m_CompressedSize;
  35. unsigned long m_UncompressedSize;
  36. unsigned short m_FileID;
  37. unsigned short m_nChunks;
  38. };
  39. class CBaseVMPIFileSystem : public CFileSystemPassThru
  40. {
  41. public:
  42. virtual ~CBaseVMPIFileSystem();
  43. virtual void Release();
  44. virtual void CreateVirtualFile( const char *pFilename, const void *pData, int fileLength ) = 0;
  45. virtual bool HandleFileSystemPacket( MessageBuffer *pBuf, int iSource, int iPacketID ) = 0;
  46. virtual void Close( FileHandle_t file );
  47. virtual int Read( void* pOutput, int size, FileHandle_t file );
  48. virtual int Write( void const* pInput, int size, FileHandle_t file );
  49. virtual void Seek( FileHandle_t file, int pos, FileSystemSeek_t seekType );
  50. virtual unsigned int Tell( FileHandle_t file );
  51. virtual unsigned int Size( FileHandle_t file );
  52. virtual unsigned int Size( const char *pFilename, const char *pathID );
  53. virtual bool FileExists( const char *pFileName, const char *pPathID );
  54. virtual void Flush( FileHandle_t file );
  55. virtual bool Precache( const char* pFileName, const char *pPathID );
  56. virtual bool ReadFile( const char *pFileName, const char *pPath, CUtlBuffer &buf, int nMaxBytes = 0, int nStartingByte = 0, FSAllocFunc_t pfnAlloc = 0 );
  57. virtual bool WriteFile( const char *pFileName, const char *pPath, CUtlBuffer &buf );
  58. // All the IFileSystem-specific ones pass the calls through.
  59. // The worker opens its own filesystem_stdio fthrough.
  60. protected:
  61. CIPAddr m_MulticastIP;
  62. };
  63. class IVMPIFile
  64. {
  65. public:
  66. virtual void Close() = 0;
  67. virtual void Seek( int pos, FileSystemSeek_t seekType ) = 0;
  68. virtual unsigned int Tell() = 0;
  69. virtual unsigned int Size() = 0;
  70. virtual void Flush() = 0;
  71. virtual int Read( void* pOutput, int size ) = 0;
  72. virtual int Write( void const* pInput, int size ) = 0;
  73. };
  74. // Both the workers and masters use this to hand out the file data.
  75. class CVMPIFile_Memory : public IVMPIFile
  76. {
  77. public:
  78. void Init( const char *pData, long len, char chMode = 'b' );
  79. virtual void Close();
  80. virtual void Seek( int pos, FileSystemSeek_t seekType );
  81. virtual unsigned int Tell();
  82. virtual unsigned int Size();
  83. virtual void Flush();
  84. virtual int Read( void* pOutput, int size ) ;
  85. virtual int Write( void const* pInput, int size );
  86. private:
  87. const char *m_pData;
  88. long m_DataLen;
  89. int m_iCurPos;
  90. char m_chMode; // 'b' or 't'
  91. };
  92. // We use different payload sizes if we're using TCP mode vs. multicast/broadcast mode.
  93. inline int VMPI_GetChunkPayloadSize()
  94. {
  95. if ( VMPI_GetFileSystemMode() == VMPI_FILESYSTEM_TCP )
  96. return TCP_CHUNK_PAYLOAD_SIZE;
  97. else
  98. return MULTICAST_CHUNK_PAYLOAD_SIZE;
  99. }
  100. extern bool g_bDisableFileAccess;
  101. extern CBaseVMPIFileSystem *g_pBaseVMPIFileSystem;
  102. #endif // VMPI_FILESYSTEM_INTERNAL_H