CoreClient.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright 1999-2019 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. #ifndef CORE_INCLUDE_ALIBABACLOUD_CORE_CORECLIENT_H_
  17. #define CORE_INCLUDE_ALIBABACLOUD_CORE_CORECLIENT_H_
  18. #include "ClientConfiguration.h"
  19. #include "CoreExport.h"
  20. #include "HttpClient.h"
  21. #include "HttpRequest.h"
  22. #include "HttpResponse.h"
  23. #include "Outcome.h"
  24. #include "Runnable.h"
  25. #include "ServiceRequest.h"
  26. #include <functional>
  27. #include <memory>
  28. #include <string>
  29. namespace AlibabaCloud {
  30. class ALIBABACLOUD_CORE_EXPORT CoreClient {
  31. public:
  32. CoreClient(const std::string &servicename,
  33. const ClientConfiguration &configuration);
  34. virtual ~CoreClient();
  35. ClientConfiguration configuration() const;
  36. std::string serviceName() const;
  37. protected:
  38. virtual HttpClient::HttpResponseOutcome
  39. AttemptRequest(const std::string &endpoint, const ServiceRequest &request,
  40. HttpRequest::Method method) const;
  41. Error buildCoreError(const HttpResponse &response) const;
  42. bool hasResponseError(const HttpResponse &response) const;
  43. virtual HttpRequest buildHttpRequest(const std::string &endpoint,
  44. const ServiceRequest &msg,
  45. HttpRequest::Method method) const = 0;
  46. void asyncExecute(Runnable *r) const;
  47. private:
  48. std::string serviceName_;
  49. ClientConfiguration configuration_;
  50. std::shared_ptr<CredentialsProvider> credentialsProvider_;
  51. HttpClient *httpClient_;
  52. };
  53. } // namespace AlibabaCloud
  54. #endif // CORE_INCLUDE_ALIBABACLOUD_CORE_CORECLIENT_H_