OssRequest.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * Copyright 2009-2017 Alibaba Cloud All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #pragma once
  17. #include <string>
  18. #include <alibabacloud/oss/ServiceRequest.h>
  19. namespace AlibabaCloud
  20. {
  21. namespace OSS
  22. {
  23. class OssClientImpl;
  24. class ALIBABACLOUD_OSS_EXPORT OssRequest : public ServiceRequest
  25. {
  26. public:
  27. OssRequest();
  28. virtual ~ OssRequest() = default;
  29. virtual HeaderCollection Headers() const;
  30. virtual ParameterCollection Parameters() const;
  31. virtual std::shared_ptr<std::iostream> Body() const;
  32. protected:
  33. OssRequest(const std::string& bucket, const std::string& key);
  34. friend class OssClientImpl;
  35. virtual int validate() const;
  36. const char *validateMessage(int code) const;
  37. virtual std::string payload() const;
  38. virtual HeaderCollection specialHeaders() const;
  39. virtual ParameterCollection specialParameters() const;
  40. const std::string& bucket() const;
  41. const std::string& key() const;
  42. protected:
  43. std::string bucket_;
  44. std::string key_;
  45. };
  46. class ALIBABACLOUD_OSS_EXPORT OssBucketRequest : public OssRequest
  47. {
  48. public:
  49. OssBucketRequest(const std::string& bucket):
  50. OssRequest(bucket, "")
  51. {}
  52. void setBucket(const std::string& bucket);
  53. const std::string& Bucket() const;
  54. protected:
  55. virtual int validate() const;
  56. };
  57. class ALIBABACLOUD_OSS_EXPORT OssObjectRequest : public OssRequest
  58. {
  59. public:
  60. OssObjectRequest(const std::string& bucket, const std::string& key) :
  61. OssRequest(bucket, key),
  62. requestPayer_(RequestPayer::NotSet),
  63. versionId_()
  64. {}
  65. void setBucket(const std::string& bucket);
  66. const std::string& Bucket() const;
  67. void setKey(const std::string& key);
  68. const std::string& Key() const;
  69. void setRequestPayer(RequestPayer value);
  70. void setVersionId(const std::string& versionId);
  71. const std::string& VersionId() const;
  72. protected:
  73. virtual int validate() const;
  74. virtual HeaderCollection specialHeaders() const;
  75. virtual ParameterCollection specialParameters() const;
  76. RequestPayer requestPayer_;
  77. std::string versionId_;
  78. };
  79. class ALIBABACLOUD_OSS_EXPORT OssResumableBaseRequest : public OssRequest
  80. {
  81. public:
  82. OssResumableBaseRequest(const std::string& bucket, const std::string& key,
  83. const std::string& checkpointDir, const uint64_t partSize, const uint32_t threadNum) :
  84. OssRequest(bucket, key),
  85. partSize_(partSize),
  86. checkpointDir_(checkpointDir),
  87. requestPayer_(AlibabaCloud::OSS::RequestPayer::NotSet),
  88. trafficLimit_(0),
  89. versionId_()
  90. {
  91. threadNum_ = threadNum == 0 ? 1 : threadNum;
  92. }
  93. OssResumableBaseRequest(const std::string& bucket, const std::string& key,
  94. const std::wstring& checkpointDir, const uint64_t partSize, const uint32_t threadNum) :
  95. OssRequest(bucket, key),
  96. partSize_(partSize),
  97. checkpointDirW_(checkpointDir),
  98. requestPayer_(AlibabaCloud::OSS::RequestPayer::NotSet),
  99. trafficLimit_(0),
  100. versionId_()
  101. {
  102. threadNum_ = threadNum == 0 ? 1 : threadNum;
  103. }
  104. void setBucket(const std::string& bucket);
  105. const std::string& Bucket() const;
  106. void setKey(const std::string& key);
  107. const std::string& Key() const;
  108. void setPartSize(uint64_t partSize);
  109. uint64_t PartSize() const;
  110. void setObjectSize(uint64_t objectSize);
  111. uint64_t ObjectSize() const;
  112. void setThreadNum(uint32_t threadNum);
  113. uint32_t ThreadNum() const;
  114. void setCheckpointDir(const std::string& checkpointDir);
  115. const std::string& CheckpointDir() const;
  116. void setCheckpointDir(const std::wstring& checkpointDir);
  117. const std::wstring& CheckpointDirW() const;
  118. bool hasCheckpointDir() const;
  119. void setObjectMtime(const std::string& mtime);
  120. const std::string& ObjectMtime() const;
  121. void setRequestPayer(RequestPayer value);
  122. AlibabaCloud::OSS::RequestPayer RequestPayer() const;
  123. void setTrafficLimit(uint64_t value);
  124. uint64_t TrafficLimit() const;
  125. void setVersionId(const std::string& versionId);
  126. const std::string& VersionId() const;
  127. protected:
  128. friend class OssClientImpl;
  129. virtual int validate() const;
  130. const char *validateMessage(int code) const;
  131. protected:
  132. uint64_t partSize_;
  133. uint64_t objectSize_;
  134. uint32_t threadNum_;
  135. std::string checkpointDir_;
  136. std::wstring checkpointDirW_;
  137. std::string mtime_;
  138. AlibabaCloud::OSS::RequestPayer requestPayer_;
  139. uint64_t trafficLimit_;
  140. std::string versionId_;
  141. };
  142. class ALIBABACLOUD_OSS_EXPORT LiveChannelRequest : public OssRequest
  143. {
  144. public:
  145. LiveChannelRequest(const std::string &bucket, const std::string &channelName) :
  146. OssRequest(bucket, channelName),
  147. channelName_(channelName)
  148. {}
  149. void setBucket(const std::string &bucket);
  150. const std::string& Bucket() const;
  151. void setChannelName(const std::string &channelName);
  152. const std::string& ChannelName() const;
  153. protected:
  154. virtual int validate() const;
  155. protected:
  156. std::string channelName_;
  157. };
  158. }
  159. }