CloudCommon.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. #include "NativeFeatureIncludes.h"
  11. #if _RAKNET_SUPPORT_CloudClient==1 || _RAKNET_SUPPORT_CloudServer==1
  12. #ifndef __CLOUD_COMMON_H
  13. #define __CLOUD_COMMON_H
  14. #include "RakNetTypes.h"
  15. #include "RakString.h"
  16. namespace RakNet
  17. {
  18. class BitStream;
  19. struct CloudQueryRow;
  20. /// Allocates CloudQueryRow and the row data. Override to use derived classes or different allocators
  21. /// \ingroup CLOUD_GROUP
  22. class RAK_DLL_EXPORT CloudAllocator
  23. {
  24. public:
  25. CloudAllocator() {}
  26. virtual ~CloudAllocator() {}
  27. /// \brief Allocate a row
  28. virtual CloudQueryRow* AllocateCloudQueryRow(void);
  29. /// \brief Free a row
  30. virtual void DeallocateCloudQueryRow(CloudQueryRow *row);
  31. /// \brief Allocate CloudQueryRow::data
  32. virtual unsigned char *AllocateRowData(uint32_t bytesNeededForData);
  33. /// \brief Free CloudQueryRow::data
  34. virtual void DeallocateRowData(void *data);
  35. };
  36. /// Serves as a key to identify data uploaded to or queried from the server.
  37. /// \ingroup CLOUD_GROUP
  38. struct RAK_DLL_EXPORT CloudKey
  39. {
  40. CloudKey() {}
  41. CloudKey(RakNet::RakString _primaryKey, uint32_t _secondaryKey) : primaryKey(_primaryKey), secondaryKey(_secondaryKey) {}
  42. ~CloudKey() {}
  43. /// Identifies the primary key. This is intended to be a major category, such as the name of the application
  44. /// Must be non-empty
  45. RakNet::RakString primaryKey;
  46. /// Identifies the secondary key. This is intended to be a subcategory enumeration, such as PLAYER_LIST or RUNNING_SCORES
  47. uint32_t secondaryKey;
  48. /// \internal
  49. void Serialize(bool writeToBitstream, BitStream *bitStream);
  50. };
  51. /// \internal
  52. int CloudKeyComp(const CloudKey &key, const CloudKey &data);
  53. /// Data members used to query the cloud
  54. /// \ingroup CLOUD_GROUP
  55. struct RAK_DLL_EXPORT CloudQuery
  56. {
  57. CloudQuery() {startingRowIndex=0; maxRowsToReturn=0; subscribeToResults=false;}
  58. /// List of keys to query. Must be at least of length 1.
  59. /// This query is run on uploads from all clients, and those that match the combination of primaryKey and secondaryKey are potentially returned
  60. /// If you pass more than one key at a time, the results are concatenated so if you need to differentiate between queries then send two different queries
  61. DataStructures::List<CloudKey> keys;
  62. /// If limiting the number of rows to return, this is the starting offset into the list. Has no effect unless maxRowsToReturn is > 0
  63. uint32_t startingRowIndex;
  64. /// Maximum number of rows to return. Actual number may still be less than this. Pass 0 to mean no-limit.
  65. uint32_t maxRowsToReturn;
  66. /// If true, automatically get updates as the results returned to you change. Unsubscribe with CloudMemoryClient::Unsubscribe()
  67. bool subscribeToResults;
  68. /// \internal
  69. void Serialize(bool writeToBitstream, BitStream *bitStream);
  70. };
  71. /// \ingroup CLOUD_GROUP
  72. struct RAK_DLL_EXPORT CloudQueryRow
  73. {
  74. /// Key used to identify this data
  75. CloudKey key;
  76. /// Data uploaded
  77. unsigned char *data;
  78. /// Length of data uploaded
  79. uint32_t length;
  80. /// System address of server that is holding this data, and the client is connected to
  81. SystemAddress serverSystemAddress;
  82. /// System address of client that uploaded this data
  83. SystemAddress clientSystemAddress;
  84. /// RakNetGUID of server that is holding this data, and the client is connected to
  85. RakNetGUID serverGUID;
  86. /// RakNetGUID of client that uploaded this data
  87. RakNetGUID clientGUID;
  88. /// \internal
  89. void Serialize(bool writeToBitstream, BitStream *bitStream, CloudAllocator *allocator);
  90. };
  91. /// \ingroup CLOUD_GROUP
  92. struct RAK_DLL_EXPORT CloudQueryResult
  93. {
  94. /// Query originally passed to Download()
  95. CloudQuery cloudQuery;
  96. /// Results returned from query. If there were multiple keys in CloudQuery::keys then see resultKeyIndices
  97. DataStructures::List<CloudQueryRow*> rowsReturned;
  98. /// If there were multiple keys in CloudQuery::keys, then each key is processed in order and the result concatenated to rowsReturned
  99. /// The starting index of each query is written to resultKeyIndices
  100. /// For example, if CloudQuery::keys had 4 keys, returning 3 rows, 0, rows, 5 rows, and 12 rows then
  101. /// resultKeyIndices would be 0, 3, 3, 8
  102. DataStructures::List<uint32_t> resultKeyIndices;
  103. /// Whatever was passed to CloudClient::Get() as CloudQuery::subscribeToResults
  104. bool subscribeToResults;
  105. /// \internal
  106. void Serialize(bool writeToBitstream, BitStream *bitStream, CloudAllocator *allocator);
  107. /// \internal
  108. void SerializeHeader(bool writeToBitstream, BitStream *bitStream);
  109. /// \internal
  110. void SerializeNumRows(bool writeToBitstream, uint32_t &numRows, BitStream *bitStream);
  111. /// \internal
  112. void SerializeCloudQueryRows(bool writeToBitstream, uint32_t &numRows, BitStream *bitStream, CloudAllocator *allocator);
  113. };
  114. } // Namespace RakNet
  115. #endif // __CLOUD_COMMON_H
  116. #endif // #if _RAKNET_SUPPORT_CloudClient==1 || _RAKNET_SUPPORT_CloudServer==1
粤ICP备19079148号