feat(hos_client_create, hos_client_destory): 多次调用destory不会导致重复释放

This commit is contained in:
彭宣正
2020-12-14 17:24:58 +08:00
parent 505d529c32
commit 10b370e486
55976 changed files with 8544395 additions and 2 deletions

View File

@@ -0,0 +1,124 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/core/utils/Outcome.h>
#include <aws/core/auth/AWSAuthSigner.h>
#include <aws/core/client/CoreErrors.h>
#include <aws/core/client/RetryStrategy.h>
#include <aws/core/http/HttpClient.h>
#include <aws/core/http/HttpResponse.h>
#include <aws/core/http/HttpClientFactory.h>
#include <aws/core/auth/AWSCredentialsProviderChain.h>
#include <aws/core/utils/json/JsonSerializer.h>
#include <aws/core/utils/memory/stl/AWSStringStream.h>
#include <aws/core/utils/threading/Executor.h>
#include <aws/core/utils/DNS.h>
#include <aws/core/utils/logging/LogMacros.h>
#include <aws/kinesis-video-media/KinesisVideoMediaClient.h>
#include <aws/kinesis-video-media/KinesisVideoMediaEndpoint.h>
#include <aws/kinesis-video-media/KinesisVideoMediaErrorMarshaller.h>
#include <aws/kinesis-video-media/model/GetMediaRequest.h>
using namespace Aws;
using namespace Aws::Auth;
using namespace Aws::Client;
using namespace Aws::KinesisVideoMedia;
using namespace Aws::KinesisVideoMedia::Model;
using namespace Aws::Http;
using namespace Aws::Utils::Json;
static const char* SERVICE_NAME = "kinesisvideo";
static const char* ALLOCATION_TAG = "KinesisVideoMediaClient";
KinesisVideoMediaClient::KinesisVideoMediaClient(const Client::ClientConfiguration& clientConfiguration) :
BASECLASS(clientConfiguration,
Aws::MakeShared<AWSAuthV4Signer>(ALLOCATION_TAG, Aws::MakeShared<DefaultAWSCredentialsProviderChain>(ALLOCATION_TAG),
SERVICE_NAME, Aws::Region::ComputeSignerRegion(clientConfiguration.region)),
Aws::MakeShared<KinesisVideoMediaErrorMarshaller>(ALLOCATION_TAG)),
m_executor(clientConfiguration.executor)
{
init(clientConfiguration);
}
KinesisVideoMediaClient::KinesisVideoMediaClient(const AWSCredentials& credentials, const Client::ClientConfiguration& clientConfiguration) :
BASECLASS(clientConfiguration,
Aws::MakeShared<AWSAuthV4Signer>(ALLOCATION_TAG, Aws::MakeShared<SimpleAWSCredentialsProvider>(ALLOCATION_TAG, credentials),
SERVICE_NAME, Aws::Region::ComputeSignerRegion(clientConfiguration.region)),
Aws::MakeShared<KinesisVideoMediaErrorMarshaller>(ALLOCATION_TAG)),
m_executor(clientConfiguration.executor)
{
init(clientConfiguration);
}
KinesisVideoMediaClient::KinesisVideoMediaClient(const std::shared_ptr<AWSCredentialsProvider>& credentialsProvider,
const Client::ClientConfiguration& clientConfiguration) :
BASECLASS(clientConfiguration,
Aws::MakeShared<AWSAuthV4Signer>(ALLOCATION_TAG, credentialsProvider,
SERVICE_NAME, Aws::Region::ComputeSignerRegion(clientConfiguration.region)),
Aws::MakeShared<KinesisVideoMediaErrorMarshaller>(ALLOCATION_TAG)),
m_executor(clientConfiguration.executor)
{
init(clientConfiguration);
}
KinesisVideoMediaClient::~KinesisVideoMediaClient()
{
}
void KinesisVideoMediaClient::init(const ClientConfiguration& config)
{
SetServiceClientName("Kinesis Video Media");
m_configScheme = SchemeMapper::ToString(config.scheme);
if (config.endpointOverride.empty())
{
m_uri = m_configScheme + "://" + KinesisVideoMediaEndpoint::ForRegion(config.region, config.useDualStack);
}
else
{
OverrideEndpoint(config.endpointOverride);
}
}
void KinesisVideoMediaClient::OverrideEndpoint(const Aws::String& endpoint)
{
if (endpoint.compare(0, 7, "http://") == 0 || endpoint.compare(0, 8, "https://") == 0)
{
m_uri = endpoint;
}
else
{
m_uri = m_configScheme + "://" + endpoint;
}
}
GetMediaOutcome KinesisVideoMediaClient::GetMedia(const GetMediaRequest& request) const
{
Aws::Http::URI uri = m_uri;
Aws::StringStream ss;
ss << "/getMedia";
uri.SetPath(uri.GetPath() + ss.str());
return GetMediaOutcome(MakeRequestWithUnparsedResponse(uri, request, Aws::Http::HttpMethod::HTTP_POST));
}
GetMediaOutcomeCallable KinesisVideoMediaClient::GetMediaCallable(const GetMediaRequest& request) const
{
auto task = Aws::MakeShared< std::packaged_task< GetMediaOutcome() > >(ALLOCATION_TAG, [this, request](){ return this->GetMedia(request); } );
auto packagedFunction = [task]() { (*task)(); };
m_executor->Submit(packagedFunction);
return task->get_future();
}
void KinesisVideoMediaClient::GetMediaAsync(const GetMediaRequest& request, const GetMediaResponseReceivedHandler& handler, const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context) const
{
m_executor->Submit( [this, request, handler, context](){ this->GetMediaAsyncHelper( request, handler, context ); } );
}
void KinesisVideoMediaClient::GetMediaAsyncHelper(const GetMediaRequest& request, const GetMediaResponseReceivedHandler& handler, const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context) const
{
handler(this, request, GetMedia(request), context);
}

View File

@@ -0,0 +1,64 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/kinesis-video-media/KinesisVideoMediaEndpoint.h>
#include <aws/core/utils/memory/stl/AWSStringStream.h>
#include <aws/core/utils/HashingUtils.h>
using namespace Aws;
using namespace Aws::KinesisVideoMedia;
namespace Aws
{
namespace KinesisVideoMedia
{
namespace KinesisVideoMediaEndpoint
{
static const int CN_NORTH_1_HASH = Aws::Utils::HashingUtils::HashString("cn-north-1");
static const int CN_NORTHWEST_1_HASH = Aws::Utils::HashingUtils::HashString("cn-northwest-1");
static const int US_ISO_EAST_1_HASH = Aws::Utils::HashingUtils::HashString("us-iso-east-1");
static const int US_ISOB_EAST_1_HASH = Aws::Utils::HashingUtils::HashString("us-isob-east-1");
Aws::String ForRegion(const Aws::String& regionName, bool useDualStack)
{
// Fallback to us-east-1 if global endpoint does not exists.
Aws::String region = regionName == Aws::Region::AWS_GLOBAL ? Aws::Region::US_EAST_1 : regionName;
auto hash = Aws::Utils::HashingUtils::HashString(region.c_str());
Aws::StringStream ss;
ss << "kinesisvideo" << ".";
if(useDualStack)
{
ss << "dualstack.";
}
ss << region;
if (hash == CN_NORTH_1_HASH || hash == CN_NORTHWEST_1_HASH)
{
ss << ".amazonaws.com.cn";
}
else if (hash == US_ISO_EAST_1_HASH)
{
ss << ".c2s.ic.gov";
}
else if (hash == US_ISOB_EAST_1_HASH)
{
ss << ".sc2s.sgov.gov";
}
else
{
ss << ".amazonaws.com";
}
return ss.str();
}
} // namespace KinesisVideoMediaEndpoint
} // namespace KinesisVideoMedia
} // namespace Aws

View File

@@ -0,0 +1,22 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/core/client/AWSError.h>
#include <aws/kinesis-video-media/KinesisVideoMediaErrorMarshaller.h>
#include <aws/kinesis-video-media/KinesisVideoMediaErrors.h>
using namespace Aws::Client;
using namespace Aws::KinesisVideoMedia;
AWSError<CoreErrors> KinesisVideoMediaErrorMarshaller::FindErrorByName(const char* errorName) const
{
AWSError<CoreErrors> error = KinesisVideoMediaErrorMapper::GetErrorForName(errorName);
if(error.GetErrorType() != CoreErrors::UNKNOWN)
{
return error;
}
return AWSErrorMarshaller::FindErrorByName(errorName);
}

View File

@@ -0,0 +1,57 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/core/client/AWSError.h>
#include <aws/core/utils/HashingUtils.h>
#include <aws/kinesis-video-media/KinesisVideoMediaErrors.h>
using namespace Aws::Client;
using namespace Aws::Utils;
using namespace Aws::KinesisVideoMedia;
namespace Aws
{
namespace KinesisVideoMedia
{
namespace KinesisVideoMediaErrorMapper
{
static const int INVALID_ENDPOINT_HASH = HashingUtils::HashString("InvalidEndpointException");
static const int CONNECTION_LIMIT_EXCEEDED_HASH = HashingUtils::HashString("ConnectionLimitExceededException");
static const int NOT_AUTHORIZED_HASH = HashingUtils::HashString("NotAuthorizedException");
static const int CLIENT_LIMIT_EXCEEDED_HASH = HashingUtils::HashString("ClientLimitExceededException");
static const int INVALID_ARGUMENT_HASH = HashingUtils::HashString("InvalidArgumentException");
AWSError<CoreErrors> GetErrorForName(const char* errorName)
{
int hashCode = HashingUtils::HashString(errorName);
if (hashCode == INVALID_ENDPOINT_HASH)
{
return AWSError<CoreErrors>(static_cast<CoreErrors>(KinesisVideoMediaErrors::INVALID_ENDPOINT), false);
}
else if (hashCode == CONNECTION_LIMIT_EXCEEDED_HASH)
{
return AWSError<CoreErrors>(static_cast<CoreErrors>(KinesisVideoMediaErrors::CONNECTION_LIMIT_EXCEEDED), false);
}
else if (hashCode == NOT_AUTHORIZED_HASH)
{
return AWSError<CoreErrors>(static_cast<CoreErrors>(KinesisVideoMediaErrors::NOT_AUTHORIZED), false);
}
else if (hashCode == CLIENT_LIMIT_EXCEEDED_HASH)
{
return AWSError<CoreErrors>(static_cast<CoreErrors>(KinesisVideoMediaErrors::CLIENT_LIMIT_EXCEEDED), false);
}
else if (hashCode == INVALID_ARGUMENT_HASH)
{
return AWSError<CoreErrors>(static_cast<CoreErrors>(KinesisVideoMediaErrors::INVALID_ARGUMENT), false);
}
return AWSError<CoreErrors>(CoreErrors::UNKNOWN, false);
}
} // namespace KinesisVideoMediaErrorMapper
} // namespace KinesisVideoMedia
} // namespace Aws

View File

@@ -0,0 +1,49 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/kinesis-video-media/model/GetMediaRequest.h>
#include <aws/core/utils/json/JsonSerializer.h>
#include <utility>
using namespace Aws::KinesisVideoMedia::Model;
using namespace Aws::Utils::Json;
using namespace Aws::Utils;
GetMediaRequest::GetMediaRequest() :
m_streamNameHasBeenSet(false),
m_streamARNHasBeenSet(false),
m_startSelectorHasBeenSet(false)
{
}
Aws::String GetMediaRequest::SerializePayload() const
{
JsonValue payload;
if(m_streamNameHasBeenSet)
{
payload.WithString("StreamName", m_streamName);
}
if(m_streamARNHasBeenSet)
{
payload.WithString("StreamARN", m_streamARN);
}
if(m_startSelectorHasBeenSet)
{
payload.WithObject("StartSelector", m_startSelector.Jsonize());
}
return payload.View().WriteReadable();
}

View File

@@ -0,0 +1,59 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/kinesis-video-media/model/GetMediaResult.h>
#include <aws/core/AmazonWebServiceResult.h>
#include <aws/core/utils/StringUtils.h>
#include <aws/core/utils/memory/stl/AWSStringStream.h>
#include <aws/core/utils/HashingUtils.h>
#include <utility>
using namespace Aws::KinesisVideoMedia::Model;
using namespace Aws::Utils::Stream;
using namespace Aws::Utils;
using namespace Aws;
GetMediaResult::GetMediaResult()
{
}
GetMediaResult::GetMediaResult(GetMediaResult&& toMove) :
m_contentType(std::move(toMove.m_contentType)),
m_payload(std::move(toMove.m_payload))
{
}
GetMediaResult& GetMediaResult::operator=(GetMediaResult&& toMove)
{
if(this == &toMove)
{
return *this;
}
m_contentType = std::move(toMove.m_contentType);
m_payload = std::move(toMove.m_payload);
return *this;
}
GetMediaResult::GetMediaResult(Aws::AmazonWebServiceResult<ResponseStream>&& result)
{
*this = std::move(result);
}
GetMediaResult& GetMediaResult::operator =(Aws::AmazonWebServiceResult<ResponseStream>&& result)
{
m_payload = result.TakeOwnershipOfPayload();
const auto& headers = result.GetHeaderValueCollection();
const auto& contentTypeIter = headers.find("content-type");
if(contentTypeIter != headers.end())
{
m_contentType = contentTypeIter->second;
}
return *this;
}

View File

@@ -0,0 +1,104 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/kinesis-video-media/model/StartSelector.h>
#include <aws/core/utils/json/JsonSerializer.h>
#include <utility>
using namespace Aws::Utils::Json;
using namespace Aws::Utils;
namespace Aws
{
namespace KinesisVideoMedia
{
namespace Model
{
StartSelector::StartSelector() :
m_startSelectorType(StartSelectorType::NOT_SET),
m_startSelectorTypeHasBeenSet(false),
m_afterFragmentNumberHasBeenSet(false),
m_startTimestampHasBeenSet(false),
m_continuationTokenHasBeenSet(false)
{
}
StartSelector::StartSelector(JsonView jsonValue) :
m_startSelectorType(StartSelectorType::NOT_SET),
m_startSelectorTypeHasBeenSet(false),
m_afterFragmentNumberHasBeenSet(false),
m_startTimestampHasBeenSet(false),
m_continuationTokenHasBeenSet(false)
{
*this = jsonValue;
}
StartSelector& StartSelector::operator =(JsonView jsonValue)
{
if(jsonValue.ValueExists("StartSelectorType"))
{
m_startSelectorType = StartSelectorTypeMapper::GetStartSelectorTypeForName(jsonValue.GetString("StartSelectorType"));
m_startSelectorTypeHasBeenSet = true;
}
if(jsonValue.ValueExists("AfterFragmentNumber"))
{
m_afterFragmentNumber = jsonValue.GetString("AfterFragmentNumber");
m_afterFragmentNumberHasBeenSet = true;
}
if(jsonValue.ValueExists("StartTimestamp"))
{
m_startTimestamp = jsonValue.GetDouble("StartTimestamp");
m_startTimestampHasBeenSet = true;
}
if(jsonValue.ValueExists("ContinuationToken"))
{
m_continuationToken = jsonValue.GetString("ContinuationToken");
m_continuationTokenHasBeenSet = true;
}
return *this;
}
JsonValue StartSelector::Jsonize() const
{
JsonValue payload;
if(m_startSelectorTypeHasBeenSet)
{
payload.WithString("StartSelectorType", StartSelectorTypeMapper::GetNameForStartSelectorType(m_startSelectorType));
}
if(m_afterFragmentNumberHasBeenSet)
{
payload.WithString("AfterFragmentNumber", m_afterFragmentNumber);
}
if(m_startTimestampHasBeenSet)
{
payload.WithDouble("StartTimestamp", m_startTimestamp.SecondsWithMSPrecision());
}
if(m_continuationTokenHasBeenSet)
{
payload.WithString("ContinuationToken", m_continuationToken);
}
return payload;
}
} // namespace Model
} // namespace KinesisVideoMedia
} // namespace Aws

View File

@@ -0,0 +1,98 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/kinesis-video-media/model/StartSelectorType.h>
#include <aws/core/utils/HashingUtils.h>
#include <aws/core/Globals.h>
#include <aws/core/utils/EnumParseOverflowContainer.h>
using namespace Aws::Utils;
namespace Aws
{
namespace KinesisVideoMedia
{
namespace Model
{
namespace StartSelectorTypeMapper
{
static const int FRAGMENT_NUMBER_HASH = HashingUtils::HashString("FRAGMENT_NUMBER");
static const int SERVER_TIMESTAMP_HASH = HashingUtils::HashString("SERVER_TIMESTAMP");
static const int PRODUCER_TIMESTAMP_HASH = HashingUtils::HashString("PRODUCER_TIMESTAMP");
static const int NOW_HASH = HashingUtils::HashString("NOW");
static const int EARLIEST_HASH = HashingUtils::HashString("EARLIEST");
static const int CONTINUATION_TOKEN_HASH = HashingUtils::HashString("CONTINUATION_TOKEN");
StartSelectorType GetStartSelectorTypeForName(const Aws::String& name)
{
int hashCode = HashingUtils::HashString(name.c_str());
if (hashCode == FRAGMENT_NUMBER_HASH)
{
return StartSelectorType::FRAGMENT_NUMBER;
}
else if (hashCode == SERVER_TIMESTAMP_HASH)
{
return StartSelectorType::SERVER_TIMESTAMP;
}
else if (hashCode == PRODUCER_TIMESTAMP_HASH)
{
return StartSelectorType::PRODUCER_TIMESTAMP;
}
else if (hashCode == NOW_HASH)
{
return StartSelectorType::NOW;
}
else if (hashCode == EARLIEST_HASH)
{
return StartSelectorType::EARLIEST;
}
else if (hashCode == CONTINUATION_TOKEN_HASH)
{
return StartSelectorType::CONTINUATION_TOKEN;
}
EnumParseOverflowContainer* overflowContainer = Aws::GetEnumOverflowContainer();
if(overflowContainer)
{
overflowContainer->StoreOverflow(hashCode, name);
return static_cast<StartSelectorType>(hashCode);
}
return StartSelectorType::NOT_SET;
}
Aws::String GetNameForStartSelectorType(StartSelectorType enumValue)
{
switch(enumValue)
{
case StartSelectorType::FRAGMENT_NUMBER:
return "FRAGMENT_NUMBER";
case StartSelectorType::SERVER_TIMESTAMP:
return "SERVER_TIMESTAMP";
case StartSelectorType::PRODUCER_TIMESTAMP:
return "PRODUCER_TIMESTAMP";
case StartSelectorType::NOW:
return "NOW";
case StartSelectorType::EARLIEST:
return "EARLIEST";
case StartSelectorType::CONTINUATION_TOKEN:
return "CONTINUATION_TOKEN";
default:
EnumParseOverflowContainer* overflowContainer = Aws::GetEnumOverflowContainer();
if(overflowContainer)
{
return overflowContainer->RetrieveOverflow(static_cast<int>(enumValue));
}
return {};
}
}
} // namespace StartSelectorTypeMapper
} // namespace Model
} // namespace KinesisVideoMedia
} // namespace Aws