| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- /*
- * Copyright 2009-2017 Alibaba Cloud All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #include <alibabacloud/tesladam/TeslaDamClient.h>
- #include <alibabacloud/core/SimpleCredentialsProvider.h>
- using namespace AlibabaCloud;
- using namespace AlibabaCloud::Location;
- using namespace AlibabaCloud::TeslaDam;
- using namespace AlibabaCloud::TeslaDam::Model;
- TeslaDamClient::TeslaDamClient(const Credentials &credentials, const ClientConfiguration &configuration) :
- RpcServiceClient(std::make_shared<SimpleCredentialsProvider>(credentials), configuration)
- {
- auto locationClient = std::make_shared<LocationClient>(credentials, configuration);
- endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), "");
- }
- TeslaDamClient::TeslaDamClient(const std::shared_ptr<CredentialsProvider>& credentialsProvider, const ClientConfiguration & configuration) :
- RpcServiceClient(credentialsProvider, configuration)
- {
- auto locationClient = std::make_shared<LocationClient>(credentialsProvider, configuration);
- endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), "");
- }
- TeslaDamClient::TeslaDamClient(const std::string & accessKeyId, const std::string & accessKeySecret, const ClientConfiguration & configuration) :
- RpcServiceClient(std::make_shared<SimpleCredentialsProvider>(accessKeyId, accessKeySecret), configuration)
- {
- auto locationClient = std::make_shared<LocationClient>(accessKeyId, accessKeySecret, configuration);
- endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), "");
- }
- TeslaDamClient::~TeslaDamClient()
- {}
- CoreClient::EndpointOutcome TeslaDamClient::endpoint()const
- {
- if(!configuration().endpoint().empty())
- return CoreClient::EndpointOutcome(configuration().endpoint());
- auto endpoint = endpointProvider_->getEndpoint();
-
- if (endpoint.empty())
- return CoreClient::EndpointOutcome(Error("InvalidEndpoint",""));
- else
- return CoreClient::EndpointOutcome(endpoint);
- }
- TeslaDamClient::ActionOutcome TeslaDamClient::action(const ActionRequest &request) const
- {
- auto endpointOutcome = endpoint();
- if (!endpointOutcome.isSuccess())
- return ActionOutcome(endpointOutcome.error());
- auto outcome = makeRequest(endpointOutcome.result(), request);
- if (outcome.isSuccess())
- return ActionOutcome(ActionResult(outcome.result()));
- else
- return ActionOutcome(outcome.error());
- }
- void TeslaDamClient::actionAsync(const ActionRequest& request, const ActionAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
- {
- auto fn = [this, request, handler, context]()
- {
- handler(this, request, action(request), context);
- };
- asyncExecute(new Runnable(fn));
- }
- TeslaDamClient::ActionOutcomeCallable TeslaDamClient::actionCallable(const ActionRequest &request) const
- {
- auto task = std::make_shared<std::packaged_task<ActionOutcome()>>(
- [this, request]()
- {
- return this->action(request);
- });
- asyncExecute(new Runnable([task]() { (*task)(); }));
- return task->get_future();
- }
- TeslaDamClient::ActionDiskRmaOutcome TeslaDamClient::actionDiskRma(const ActionDiskRmaRequest &request) const
- {
- auto endpointOutcome = endpoint();
- if (!endpointOutcome.isSuccess())
- return ActionDiskRmaOutcome(endpointOutcome.error());
- auto outcome = makeRequest(endpointOutcome.result(), request);
- if (outcome.isSuccess())
- return ActionDiskRmaOutcome(ActionDiskRmaResult(outcome.result()));
- else
- return ActionDiskRmaOutcome(outcome.error());
- }
- void TeslaDamClient::actionDiskRmaAsync(const ActionDiskRmaRequest& request, const ActionDiskRmaAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
- {
- auto fn = [this, request, handler, context]()
- {
- handler(this, request, actionDiskRma(request), context);
- };
- asyncExecute(new Runnable(fn));
- }
- TeslaDamClient::ActionDiskRmaOutcomeCallable TeslaDamClient::actionDiskRmaCallable(const ActionDiskRmaRequest &request) const
- {
- auto task = std::make_shared<std::packaged_task<ActionDiskRmaOutcome()>>(
- [this, request]()
- {
- return this->actionDiskRma(request);
- });
- asyncExecute(new Runnable([task]() { (*task)(); }));
- return task->get_future();
- }
- TeslaDamClient::ActionDiskMaskOutcome TeslaDamClient::actionDiskMask(const ActionDiskMaskRequest &request) const
- {
- auto endpointOutcome = endpoint();
- if (!endpointOutcome.isSuccess())
- return ActionDiskMaskOutcome(endpointOutcome.error());
- auto outcome = makeRequest(endpointOutcome.result(), request);
- if (outcome.isSuccess())
- return ActionDiskMaskOutcome(ActionDiskMaskResult(outcome.result()));
- else
- return ActionDiskMaskOutcome(outcome.error());
- }
- void TeslaDamClient::actionDiskMaskAsync(const ActionDiskMaskRequest& request, const ActionDiskMaskAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
- {
- auto fn = [this, request, handler, context]()
- {
- handler(this, request, actionDiskMask(request), context);
- };
- asyncExecute(new Runnable(fn));
- }
- TeslaDamClient::ActionDiskMaskOutcomeCallable TeslaDamClient::actionDiskMaskCallable(const ActionDiskMaskRequest &request) const
- {
- auto task = std::make_shared<std::packaged_task<ActionDiskMaskOutcome()>>(
- [this, request]()
- {
- return this->actionDiskMask(request);
- });
- asyncExecute(new Runnable([task]() { (*task)(); }));
- return task->get_future();
- }
- TeslaDamClient::ActionDiskCheckOutcome TeslaDamClient::actionDiskCheck(const ActionDiskCheckRequest &request) const
- {
- auto endpointOutcome = endpoint();
- if (!endpointOutcome.isSuccess())
- return ActionDiskCheckOutcome(endpointOutcome.error());
- auto outcome = makeRequest(endpointOutcome.result(), request);
- if (outcome.isSuccess())
- return ActionDiskCheckOutcome(ActionDiskCheckResult(outcome.result()));
- else
- return ActionDiskCheckOutcome(outcome.error());
- }
- void TeslaDamClient::actionDiskCheckAsync(const ActionDiskCheckRequest& request, const ActionDiskCheckAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
- {
- auto fn = [this, request, handler, context]()
- {
- handler(this, request, actionDiskCheck(request), context);
- };
- asyncExecute(new Runnable(fn));
- }
- TeslaDamClient::ActionDiskCheckOutcomeCallable TeslaDamClient::actionDiskCheckCallable(const ActionDiskCheckRequest &request) const
- {
- auto task = std::make_shared<std::packaged_task<ActionDiskCheckOutcome()>>(
- [this, request]()
- {
- return this->actionDiskCheck(request);
- });
- asyncExecute(new Runnable([task]() { (*task)(); }));
- return task->get_future();
- }
- TeslaDamClient::HostGetsOutcome TeslaDamClient::hostGets(const HostGetsRequest &request) const
- {
- auto endpointOutcome = endpoint();
- if (!endpointOutcome.isSuccess())
- return HostGetsOutcome(endpointOutcome.error());
- auto outcome = makeRequest(endpointOutcome.result(), request);
- if (outcome.isSuccess())
- return HostGetsOutcome(HostGetsResult(outcome.result()));
- else
- return HostGetsOutcome(outcome.error());
- }
- void TeslaDamClient::hostGetsAsync(const HostGetsRequest& request, const HostGetsAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
- {
- auto fn = [this, request, handler, context]()
- {
- handler(this, request, hostGets(request), context);
- };
- asyncExecute(new Runnable(fn));
- }
- TeslaDamClient::HostGetsOutcomeCallable TeslaDamClient::hostGetsCallable(const HostGetsRequest &request) const
- {
- auto task = std::make_shared<std::packaged_task<HostGetsOutcome()>>(
- [this, request]()
- {
- return this->hostGets(request);
- });
- asyncExecute(new Runnable([task]() { (*task)(); }));
- return task->get_future();
- }
|