Et-industry-openapiClient.cc 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #include <alibabacloud/et-industry-openapi/Et_industry_openapiClient.h>
  17. #include <alibabacloud/core/SimpleCredentialsProvider.h>
  18. using namespace AlibabaCloud;
  19. using namespace AlibabaCloud::Location;
  20. using namespace AlibabaCloud::Et_industry_openapi;
  21. using namespace AlibabaCloud::Et_industry_openapi::Model;
  22. namespace
  23. {
  24. const std::string SERVICE_NAME = "et-industry-openapi";
  25. }
  26. Et_industry_openapiClient::Et_industry_openapiClient(const Credentials &credentials, const ClientConfiguration &configuration) :
  27. RoaServiceClient(SERVICE_NAME, std::make_shared<SimpleCredentialsProvider>(credentials), configuration)
  28. {
  29. auto locationClient = std::make_shared<LocationClient>(credentials, configuration);
  30. endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "");
  31. }
  32. Et_industry_openapiClient::Et_industry_openapiClient(const std::shared_ptr<CredentialsProvider>& credentialsProvider, const ClientConfiguration & configuration) :
  33. RoaServiceClient(SERVICE_NAME, credentialsProvider, configuration)
  34. {
  35. auto locationClient = std::make_shared<LocationClient>(credentialsProvider, configuration);
  36. endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "");
  37. }
  38. Et_industry_openapiClient::Et_industry_openapiClient(const std::string & accessKeyId, const std::string & accessKeySecret, const ClientConfiguration & configuration) :
  39. RoaServiceClient(SERVICE_NAME, std::make_shared<SimpleCredentialsProvider>(accessKeyId, accessKeySecret), configuration)
  40. {
  41. auto locationClient = std::make_shared<LocationClient>(accessKeyId, accessKeySecret, configuration);
  42. endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "");
  43. }
  44. Et_industry_openapiClient::~Et_industry_openapiClient()
  45. {}
  46. Et_industry_openapiClient::UploadDeviceDataOutcome Et_industry_openapiClient::uploadDeviceData(const UploadDeviceDataRequest &request) const
  47. {
  48. auto endpointOutcome = endpointProvider_->getEndpoint();
  49. if (!endpointOutcome.isSuccess())
  50. return UploadDeviceDataOutcome(endpointOutcome.error());
  51. auto outcome = makeRequest(endpointOutcome.result(), request);
  52. if (outcome.isSuccess())
  53. return UploadDeviceDataOutcome(UploadDeviceDataResult(outcome.result()));
  54. else
  55. return UploadDeviceDataOutcome(outcome.error());
  56. }
  57. void Et_industry_openapiClient::uploadDeviceDataAsync(const UploadDeviceDataRequest& request, const UploadDeviceDataAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
  58. {
  59. auto fn = [this, request, handler, context]()
  60. {
  61. handler(this, request, uploadDeviceData(request), context);
  62. };
  63. asyncExecute(new Runnable(fn));
  64. }
  65. Et_industry_openapiClient::UploadDeviceDataOutcomeCallable Et_industry_openapiClient::uploadDeviceDataCallable(const UploadDeviceDataRequest &request) const
  66. {
  67. auto task = std::make_shared<std::packaged_task<UploadDeviceDataOutcome()>>(
  68. [this, request]()
  69. {
  70. return this->uploadDeviceData(request);
  71. });
  72. asyncExecute(new Runnable([task]() { (*task)(); }));
  73. return task->get_future();
  74. }