/* * 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 #include using namespace AlibabaCloud; using namespace AlibabaCloud::Location; using namespace AlibabaCloud::Cloudgame; using namespace AlibabaCloud::Cloudgame::Model; namespace { const std::string SERVICE_NAME = "cloudgame"; } CloudgameClient::CloudgameClient(const Credentials &credentials, const ClientConfiguration &configuration) : RpcServiceClient(SERVICE_NAME, std::make_shared(credentials), configuration) { auto locationClient = std::make_shared(credentials, configuration); endpointProvider_ = std::make_shared(locationClient, configuration.regionId(), SERVICE_NAME, ""); } CloudgameClient::CloudgameClient(const std::shared_ptr& credentialsProvider, const ClientConfiguration & configuration) : RpcServiceClient(SERVICE_NAME, credentialsProvider, configuration) { auto locationClient = std::make_shared(credentialsProvider, configuration); endpointProvider_ = std::make_shared(locationClient, configuration.regionId(), SERVICE_NAME, ""); } CloudgameClient::CloudgameClient(const std::string & accessKeyId, const std::string & accessKeySecret, const ClientConfiguration & configuration) : RpcServiceClient(SERVICE_NAME, std::make_shared(accessKeyId, accessKeySecret), configuration) { auto locationClient = std::make_shared(accessKeyId, accessKeySecret, configuration); endpointProvider_ = std::make_shared(locationClient, configuration.regionId(), SERVICE_NAME, ""); } CloudgameClient::~CloudgameClient() {} CloudgameClient::ListGamesOutcome CloudgameClient::listGames(const ListGamesRequest &request) const { auto endpointOutcome = endpointProvider_->getEndpoint(); if (!endpointOutcome.isSuccess()) return ListGamesOutcome(endpointOutcome.error()); auto outcome = makeRequest(endpointOutcome.result(), request); if (outcome.isSuccess()) return ListGamesOutcome(ListGamesResult(outcome.result())); else return ListGamesOutcome(outcome.error()); } void CloudgameClient::listGamesAsync(const ListGamesRequest& request, const ListGamesAsyncHandler& handler, const std::shared_ptr& context) const { auto fn = [this, request, handler, context]() { handler(this, request, listGames(request), context); }; asyncExecute(new Runnable(fn)); } CloudgameClient::ListGamesOutcomeCallable CloudgameClient::listGamesCallable(const ListGamesRequest &request) const { auto task = std::make_shared>( [this, request]() { return this->listGames(request); }); asyncExecute(new Runnable([task]() { (*task)(); })); return task->get_future(); } CloudgameClient::ListProjectsOutcome CloudgameClient::listProjects(const ListProjectsRequest &request) const { auto endpointOutcome = endpointProvider_->getEndpoint(); if (!endpointOutcome.isSuccess()) return ListProjectsOutcome(endpointOutcome.error()); auto outcome = makeRequest(endpointOutcome.result(), request); if (outcome.isSuccess()) return ListProjectsOutcome(ListProjectsResult(outcome.result())); else return ListProjectsOutcome(outcome.error()); } void CloudgameClient::listProjectsAsync(const ListProjectsRequest& request, const ListProjectsAsyncHandler& handler, const std::shared_ptr& context) const { auto fn = [this, request, handler, context]() { handler(this, request, listProjects(request), context); }; asyncExecute(new Runnable(fn)); } CloudgameClient::ListProjectsOutcomeCallable CloudgameClient::listProjectsCallable(const ListProjectsRequest &request) const { auto task = std::make_shared>( [this, request]() { return this->listProjects(request); }); asyncExecute(new Runnable([task]() { (*task)(); })); return task->get_future(); }