LocationClient.cc 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. #include <alibabacloud/core/location/LocationClient.h>
  17. #include <alibabacloud/core/SimpleCredentialsProvider.h>
  18. using namespace AlibabaCloud;
  19. using namespace AlibabaCloud::Location;
  20. namespace
  21. {
  22. const std::string SERVICE_NAME = "Location";
  23. const std::string ENDPOINT = "location.aliyuncs.com";
  24. }
  25. LocationClient::LocationClient(const Credentials &credentials, const ClientConfiguration &configuration) :
  26. RpcServiceClient(SERVICE_NAME, std::make_shared<SimpleCredentialsProvider>(credentials), configuration)
  27. {
  28. }
  29. LocationClient::LocationClient(const std::shared_ptr<CredentialsProvider>& credentialsProvider, const ClientConfiguration & configuration) :
  30. RpcServiceClient(SERVICE_NAME, credentialsProvider, configuration)
  31. {
  32. }
  33. LocationClient::LocationClient(const std::string & accessKeyId, const std::string & accessKeySecret, const ClientConfiguration & configuration) :
  34. RpcServiceClient(SERVICE_NAME, std::make_shared<SimpleCredentialsProvider>(accessKeyId, accessKeySecret), configuration)
  35. {
  36. }
  37. LocationClient::LocationClient(const std::shared_ptr<Location::LocationClient>& locationClient):
  38. RpcServiceClient(SERVICE_NAME, locationClient->credentialsProvider(), locationClient->configuration())
  39. {
  40. }
  41. LocationClient::~LocationClient()
  42. {}
  43. LocationClient::DescribeEndpointsOutcome LocationClient::describeEndpoints(const Model::DescribeEndpointsRequest &request) const
  44. {
  45. auto outcome = makeRequest(ENDPOINT, request);
  46. if (outcome.isSuccess())
  47. return DescribeEndpointsOutcome(Model::DescribeEndpointsResult(outcome.result()));
  48. else
  49. return DescribeEndpointsOutcome(outcome.error());
  50. }
  51. void LocationClient::describeEndpointsAsync(const Model::DescribeEndpointsRequest& request, const DescribeEndpointsAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
  52. {
  53. std::async(std::launch::async,
  54. [this, request, handler, context]()
  55. {
  56. handler(this, request, describeEndpoints(request), context);
  57. });
  58. }
  59. LocationClient::DescribeEndpointsOutcomeCallable LocationClient::describeEndpointsCallable(const Model::DescribeEndpointsRequest &request) const
  60. {
  61. auto task = std::make_shared<std::packaged_task<DescribeEndpointsOutcome()>>(
  62. [this, request]()
  63. {
  64. return this->describeEndpoints(request);
  65. });
  66. asyncExecute(new Runnable([task]() { (*task)(); }));
  67. return task->get_future();
  68. }