|
| 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 | + |
| 17 | +#include <alibabacloud/aipodcast/AIPodcastClient.h> |
| 18 | +#include <alibabacloud/core/SimpleCredentialsProvider.h> |
| 19 | + |
| 20 | +using namespace AlibabaCloud; |
| 21 | +using namespace AlibabaCloud::Location; |
| 22 | +using namespace AlibabaCloud::AIPodcast; |
| 23 | +using namespace AlibabaCloud::AIPodcast::Model; |
| 24 | + |
| 25 | +namespace |
| 26 | +{ |
| 27 | + const std::string SERVICE_NAME = "AIPodcast"; |
| 28 | +} |
| 29 | + |
| 30 | +AIPodcastClient::AIPodcastClient(const Credentials &credentials, const ClientConfiguration &configuration) : |
| 31 | + RoaServiceClient(SERVICE_NAME, std::make_shared<SimpleCredentialsProvider>(credentials), configuration) |
| 32 | +{ |
| 33 | + auto locationClient = std::make_shared<LocationClient>(credentials, configuration); |
| 34 | + endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, ""); |
| 35 | +} |
| 36 | + |
| 37 | +AIPodcastClient::AIPodcastClient(const std::shared_ptr<CredentialsProvider>& credentialsProvider, const ClientConfiguration & configuration) : |
| 38 | + RoaServiceClient(SERVICE_NAME, credentialsProvider, configuration) |
| 39 | +{ |
| 40 | + auto locationClient = std::make_shared<LocationClient>(credentialsProvider, configuration); |
| 41 | + endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, ""); |
| 42 | +} |
| 43 | + |
| 44 | +AIPodcastClient::AIPodcastClient(const std::string & accessKeyId, const std::string & accessKeySecret, const ClientConfiguration & configuration) : |
| 45 | + RoaServiceClient(SERVICE_NAME, std::make_shared<SimpleCredentialsProvider>(accessKeyId, accessKeySecret), configuration) |
| 46 | +{ |
| 47 | + auto locationClient = std::make_shared<LocationClient>(accessKeyId, accessKeySecret, configuration); |
| 48 | + endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, ""); |
| 49 | +} |
| 50 | + |
| 51 | +AIPodcastClient::~AIPodcastClient() |
| 52 | +{} |
| 53 | + |
| 54 | +AIPodcastClient::PodcastTaskResultQueryOutcome AIPodcastClient::podcastTaskResultQuery(const PodcastTaskResultQueryRequest &request) const |
| 55 | +{ |
| 56 | + auto endpointOutcome = endpointProvider_->getEndpoint(); |
| 57 | + if (!endpointOutcome.isSuccess()) |
| 58 | + return PodcastTaskResultQueryOutcome(endpointOutcome.error()); |
| 59 | + |
| 60 | + auto outcome = makeRequest(endpointOutcome.result(), request); |
| 61 | + |
| 62 | + if (outcome.isSuccess()) |
| 63 | + return PodcastTaskResultQueryOutcome(PodcastTaskResultQueryResult(outcome.result())); |
| 64 | + else |
| 65 | + return PodcastTaskResultQueryOutcome(outcome.error()); |
| 66 | +} |
| 67 | + |
| 68 | +void AIPodcastClient::podcastTaskResultQueryAsync(const PodcastTaskResultQueryRequest& request, const PodcastTaskResultQueryAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const |
| 69 | +{ |
| 70 | + auto fn = [this, request, handler, context]() |
| 71 | + { |
| 72 | + handler(this, request, podcastTaskResultQuery(request), context); |
| 73 | + }; |
| 74 | + |
| 75 | + asyncExecute(new Runnable(fn)); |
| 76 | +} |
| 77 | + |
| 78 | +AIPodcastClient::PodcastTaskResultQueryOutcomeCallable AIPodcastClient::podcastTaskResultQueryCallable(const PodcastTaskResultQueryRequest &request) const |
| 79 | +{ |
| 80 | + auto task = std::make_shared<std::packaged_task<PodcastTaskResultQueryOutcome()>>( |
| 81 | + [this, request]() |
| 82 | + { |
| 83 | + return this->podcastTaskResultQuery(request); |
| 84 | + }); |
| 85 | + |
| 86 | + asyncExecute(new Runnable([task]() { (*task)(); })); |
| 87 | + return task->get_future(); |
| 88 | +} |
| 89 | + |
| 90 | +AIPodcastClient::PodcastTaskSubmitOutcome AIPodcastClient::podcastTaskSubmit(const PodcastTaskSubmitRequest &request) const |
| 91 | +{ |
| 92 | + auto endpointOutcome = endpointProvider_->getEndpoint(); |
| 93 | + if (!endpointOutcome.isSuccess()) |
| 94 | + return PodcastTaskSubmitOutcome(endpointOutcome.error()); |
| 95 | + |
| 96 | + auto outcome = makeRequest(endpointOutcome.result(), request); |
| 97 | + |
| 98 | + if (outcome.isSuccess()) |
| 99 | + return PodcastTaskSubmitOutcome(PodcastTaskSubmitResult(outcome.result())); |
| 100 | + else |
| 101 | + return PodcastTaskSubmitOutcome(outcome.error()); |
| 102 | +} |
| 103 | + |
| 104 | +void AIPodcastClient::podcastTaskSubmitAsync(const PodcastTaskSubmitRequest& request, const PodcastTaskSubmitAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const |
| 105 | +{ |
| 106 | + auto fn = [this, request, handler, context]() |
| 107 | + { |
| 108 | + handler(this, request, podcastTaskSubmit(request), context); |
| 109 | + }; |
| 110 | + |
| 111 | + asyncExecute(new Runnable(fn)); |
| 112 | +} |
| 113 | + |
| 114 | +AIPodcastClient::PodcastTaskSubmitOutcomeCallable AIPodcastClient::podcastTaskSubmitCallable(const PodcastTaskSubmitRequest &request) const |
| 115 | +{ |
| 116 | + auto task = std::make_shared<std::packaged_task<PodcastTaskSubmitOutcome()>>( |
| 117 | + [this, request]() |
| 118 | + { |
| 119 | + return this->podcastTaskSubmit(request); |
| 120 | + }); |
| 121 | + |
| 122 | + asyncExecute(new Runnable([task]() { (*task)(); })); |
| 123 | + return task->get_future(); |
| 124 | +} |
| 125 | + |
0 commit comments