FileListTransferCBInterface.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. /// \file FileListTransferCBInterface.h
  11. ///
  12. #ifndef __FILE_LIST_TRANSFER_CALLBACK_INTERFACE_H
  13. #define __FILE_LIST_TRANSFER_CALLBACK_INTERFACE_H
  14. #include "RakMemoryOverride.h"
  15. #include "FileListNodeContext.h"
  16. #ifdef _MSC_VER
  17. #pragma warning( push )
  18. #endif
  19. namespace RakNet
  20. {
  21. /// \brief Used by FileListTransfer plugin as a callback for when we get a file.
  22. /// \details You get the last file when fileIndex==numberOfFilesInThisSet
  23. /// \sa FileListTransfer
  24. class FileListTransferCBInterface
  25. {
  26. public:
  27. // Note: If this structure is changed the struct in the swig files need to be changed as well
  28. struct OnFileStruct
  29. {
  30. /// \brief The index into the set of files, from 0 to numberOfFilesInThisSet
  31. unsigned fileIndex;
  32. /// \brief The name of the file
  33. char fileName[512];
  34. /// \brief The data pointed to by the file
  35. char *fileData;
  36. /// \brief The amount of data to be downloaded for this file
  37. BitSize_t byteLengthOfThisFile;
  38. /// \brief How many bytes of this file has been downloaded
  39. BitSize_t bytesDownloadedForThisFile;
  40. /// \brief Files are transmitted in sets, where more than one set of files can be transmitted at the same time.
  41. /// \details This is the identifier for the set, which is returned by FileListTransfer::SetupReceive
  42. unsigned short setID;
  43. /// \brief The number of files that are in this set.
  44. unsigned numberOfFilesInThisSet;
  45. /// \brief The total length of the transmitted files for this set, after being uncompressed
  46. unsigned byteLengthOfThisSet;
  47. /// \brief The total length, in bytes, downloaded for this set.
  48. unsigned bytesDownloadedForThisSet;
  49. /// \brief User data passed to one of the functions in the FileList class.
  50. /// \details However, on error, this is instead changed to one of the enumerations in the PatchContext structure.
  51. FileListNodeContext context;
  52. /// \brief Who sent this file
  53. SystemAddress senderSystemAddress;
  54. /// \brief Who sent this file. Not valid when using TCP, only RakPeer (UDP)
  55. RakNetGUID senderGuid;
  56. };
  57. // Note: If this structure is changed the struct in the swig files need to be changed as well
  58. struct FileProgressStruct
  59. {
  60. /// \param[out] onFileStruct General information about this file, such as the filename and the first \a partLength bytes. You do NOT need to save this data yourself. The complete file will arrive normally.
  61. OnFileStruct *onFileStruct;
  62. /// \param[out] partCount The zero based index into partTotal. The percentage complete done of this file is 100 * (partCount+1)/partTotal
  63. unsigned int partCount;
  64. /// \param[out] partTotal The total number of parts this file was split into. Each part will be roughly the MTU size, minus the UDP header and RakNet headers
  65. unsigned int partTotal;
  66. /// \param[out] dataChunkLength How many bytes long firstDataChunk and iriDataChunk are
  67. unsigned int dataChunkLength;
  68. /// \param[out] firstDataChunk The first \a partLength of the final file. If you store identifying information about the file in the first \a partLength bytes, you can read them while the download is taking place. If this hasn't arrived yet, firstDataChunk will be 0
  69. char *firstDataChunk;
  70. /// \param[out] iriDataChunk If the remote system is sending this file using IncrementalReadInterface, then this is the chunk we just downloaded. It will not exist in memory after this callback. You should either store this to disk, or in memory. If it is 0, then the file is smaller than one chunk, and will be held in memory automatically
  71. char *iriDataChunk;
  72. /// \param[out] iriWriteOffset Offset in bytes from the start of the file for the data pointed to by iriDataChunk
  73. unsigned int iriWriteOffset;
  74. /// \param[out] Who sent this file
  75. SystemAddress senderSystemAddress;
  76. /// \param[out] Who sent this file. Not valid when using TCP, only RakPeer (UDP)
  77. RakNetGUID senderGuid;
  78. /// \param[in] allocateIrIDataChunkAutomatically If true, then RakNet will hold iriDataChunk for you and return it in OnFile. Defaults to true
  79. bool allocateIrIDataChunkAutomatically;
  80. };
  81. struct DownloadCompleteStruct
  82. {
  83. /// \brief Files are transmitted in sets, where more than one set of files can be transmitted at the same time.
  84. /// \details This is the identifier for the set, which is returned by FileListTransfer::SetupReceive
  85. unsigned short setID;
  86. /// \brief The number of files that are in this set.
  87. unsigned numberOfFilesInThisSet;
  88. /// \brief The total length of the transmitted files for this set, after being uncompressed
  89. unsigned byteLengthOfThisSet;
  90. /// \brief Who sent this file
  91. SystemAddress senderSystemAddress;
  92. /// \brief Who sent this file. Not valid when using TCP, only RakPeer (UDP)
  93. RakNetGUID senderGuid;
  94. };
  95. FileListTransferCBInterface() {}
  96. virtual ~FileListTransferCBInterface() {}
  97. /// \brief Got a file.
  98. /// \details This structure is only valid for the duration of this function call.
  99. /// \return Return true to have RakNet delete the memory allocated to hold this file for this function call.
  100. virtual bool OnFile(OnFileStruct *onFileStruct)=0;
  101. /// \brief Got part of a big file internally in RakNet
  102. /// \details This is called in one of two circumstances: Either the transport layer is returning ID_PROGRESS_NOTIFICATION, or you got a block via IncrementalReadInterface
  103. /// If the transport layer is returning ID_PROGRESS_NOTIFICATION (see RakPeer::SetSplitMessageProgressInterval()) then FileProgressStruct::iriDataChunk will be 0.
  104. /// If this is a block via IncrementalReadInterface, then iriDataChunk will point to the block just downloaded.
  105. /// If not using IncrementalReadInterface, then you only care about partCount and partTotal to tell how far the download has progressed. YOu can use firstDataChunk to read the first part of the file if desired. The file is usable when you get the OnFile callback.
  106. /// If using IncrementalReadInterface and you let RakNet buffer the files in memory (default), then it is the same as above. The file is usable when you get the OnFile callback.
  107. /// If using IncrementalReadInterface and you do not let RakNet buffer the files in memory, then set allocateIrIDataChunkAutomatically to false. Write the file to disk whenever you get OnFileProgress and iriDataChunk is not 0, and ignore OnFile.
  108. virtual void OnFileProgress(FileProgressStruct *fps)=0;
  109. /// \brief Called while the handler is active by FileListTransfer
  110. /// \details Return false when you are done with the class.
  111. /// At that point OnDereference will be called and the class will no longer be maintained by the FileListTransfer plugin.
  112. virtual bool Update(void) {return true;}
  113. /// \brief Called when the download is completed.
  114. /// \details If you are finished with this class, return false.
  115. /// At that point OnDereference will be called and the class will no longer be maintained by the FileListTransfer plugin.
  116. /// Otherwise return true, and Update will continue to be called.
  117. virtual bool OnDownloadComplete(DownloadCompleteStruct *dcs) {(void) dcs; return false;}
  118. /// \brief This function is called when this instance is about to be dereferenced by the FileListTransfer plugin.
  119. /// \details Update will no longer be called.
  120. /// It will will be deleted automatically if true was passed to FileListTransfer::SetupReceive::deleteHandler
  121. /// Otherwise it is up to you to delete it yourself.
  122. virtual void OnDereference(void) {}
  123. };
  124. } // namespace RakNet
  125. #ifdef _MSC_VER
  126. #pragma warning( pop )
  127. #endif
  128. #endif
粤ICP备19079148号