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,129 @@
/**
* 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/mobileanalytics/MobileAnalyticsClient.h>
#include <aws/mobileanalytics/MobileAnalyticsEndpoint.h>
#include <aws/mobileanalytics/MobileAnalyticsErrorMarshaller.h>
#include <aws/mobileanalytics/model/PutEventsRequest.h>
using namespace Aws;
using namespace Aws::Auth;
using namespace Aws::Client;
using namespace Aws::MobileAnalytics;
using namespace Aws::MobileAnalytics::Model;
using namespace Aws::Http;
using namespace Aws::Utils::Json;
static const char* SERVICE_NAME = "mobileanalytics";
static const char* ALLOCATION_TAG = "MobileAnalyticsClient";
MobileAnalyticsClient::MobileAnalyticsClient(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<MobileAnalyticsErrorMarshaller>(ALLOCATION_TAG)),
m_executor(clientConfiguration.executor)
{
init(clientConfiguration);
}
MobileAnalyticsClient::MobileAnalyticsClient(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<MobileAnalyticsErrorMarshaller>(ALLOCATION_TAG)),
m_executor(clientConfiguration.executor)
{
init(clientConfiguration);
}
MobileAnalyticsClient::MobileAnalyticsClient(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<MobileAnalyticsErrorMarshaller>(ALLOCATION_TAG)),
m_executor(clientConfiguration.executor)
{
init(clientConfiguration);
}
MobileAnalyticsClient::~MobileAnalyticsClient()
{
}
void MobileAnalyticsClient::init(const ClientConfiguration& config)
{
SetServiceClientName("mobileanalytics");
m_configScheme = SchemeMapper::ToString(config.scheme);
if (config.endpointOverride.empty())
{
m_uri = m_configScheme + "://" + MobileAnalyticsEndpoint::ForRegion(config.region, config.useDualStack);
}
else
{
OverrideEndpoint(config.endpointOverride);
}
}
void MobileAnalyticsClient::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;
}
}
PutEventsOutcome MobileAnalyticsClient::PutEvents(const PutEventsRequest& request) const
{
if (!request.ClientContextHasBeenSet())
{
AWS_LOGSTREAM_ERROR("PutEvents", "Required field: ClientContext, is not set");
return PutEventsOutcome(Aws::Client::AWSError<MobileAnalyticsErrors>(MobileAnalyticsErrors::MISSING_PARAMETER, "MISSING_PARAMETER", "Missing required field [ClientContext]", false));
}
Aws::Http::URI uri = m_uri;
Aws::StringStream ss;
ss << "/2014-06-05/events";
uri.SetPath(uri.GetPath() + ss.str());
return PutEventsOutcome(MakeRequest(uri, request, Aws::Http::HttpMethod::HTTP_POST, Aws::Auth::SIGV4_SIGNER));
}
PutEventsOutcomeCallable MobileAnalyticsClient::PutEventsCallable(const PutEventsRequest& request) const
{
auto task = Aws::MakeShared< std::packaged_task< PutEventsOutcome() > >(ALLOCATION_TAG, [this, request](){ return this->PutEvents(request); } );
auto packagedFunction = [task]() { (*task)(); };
m_executor->Submit(packagedFunction);
return task->get_future();
}
void MobileAnalyticsClient::PutEventsAsync(const PutEventsRequest& request, const PutEventsResponseReceivedHandler& handler, const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context) const
{
m_executor->Submit( [this, request, handler, context](){ this->PutEventsAsyncHelper( request, handler, context ); } );
}
void MobileAnalyticsClient::PutEventsAsyncHelper(const PutEventsRequest& request, const PutEventsResponseReceivedHandler& handler, const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context) const
{
handler(this, request, PutEvents(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/mobileanalytics/MobileAnalyticsEndpoint.h>
#include <aws/core/utils/memory/stl/AWSStringStream.h>
#include <aws/core/utils/HashingUtils.h>
using namespace Aws;
using namespace Aws::MobileAnalytics;
namespace Aws
{
namespace MobileAnalytics
{
namespace MobileAnalyticsEndpoint
{
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 << "mobileanalytics" << ".";
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 MobileAnalyticsEndpoint
} // namespace MobileAnalytics
} // 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/mobileanalytics/MobileAnalyticsErrorMarshaller.h>
#include <aws/mobileanalytics/MobileAnalyticsErrors.h>
using namespace Aws::Client;
using namespace Aws::MobileAnalytics;
AWSError<CoreErrors> MobileAnalyticsErrorMarshaller::FindErrorByName(const char* errorName) const
{
AWSError<CoreErrors> error = MobileAnalyticsErrorMapper::GetErrorForName(errorName);
if(error.GetErrorType() != CoreErrors::UNKNOWN)
{
return error;
}
return AWSErrorMarshaller::FindErrorByName(errorName);
}

View File

@@ -0,0 +1,37 @@
/**
* 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/mobileanalytics/MobileAnalyticsErrors.h>
using namespace Aws::Client;
using namespace Aws::Utils;
using namespace Aws::MobileAnalytics;
namespace Aws
{
namespace MobileAnalytics
{
namespace MobileAnalyticsErrorMapper
{
static const int BAD_REQUEST_HASH = HashingUtils::HashString("BadRequestException");
AWSError<CoreErrors> GetErrorForName(const char* errorName)
{
int hashCode = HashingUtils::HashString(errorName);
if (hashCode == BAD_REQUEST_HASH)
{
return AWSError<CoreErrors>(static_cast<CoreErrors>(MobileAnalyticsErrors::BAD_REQUEST), false);
}
return AWSError<CoreErrors>(CoreErrors::UNKNOWN, false);
}
} // namespace MobileAnalyticsErrorMapper
} // namespace MobileAnalytics
} // namespace Aws

View File

@@ -0,0 +1,150 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/mobileanalytics/model/Event.h>
#include <aws/core/utils/json/JsonSerializer.h>
#include <utility>
using namespace Aws::Utils::Json;
using namespace Aws::Utils;
namespace Aws
{
namespace MobileAnalytics
{
namespace Model
{
Event::Event() :
m_eventTypeHasBeenSet(false),
m_timestampHasBeenSet(false),
m_sessionHasBeenSet(false),
m_versionHasBeenSet(false),
m_attributesHasBeenSet(false),
m_metricsHasBeenSet(false)
{
}
Event::Event(JsonView jsonValue) :
m_eventTypeHasBeenSet(false),
m_timestampHasBeenSet(false),
m_sessionHasBeenSet(false),
m_versionHasBeenSet(false),
m_attributesHasBeenSet(false),
m_metricsHasBeenSet(false)
{
*this = jsonValue;
}
Event& Event::operator =(JsonView jsonValue)
{
if(jsonValue.ValueExists("eventType"))
{
m_eventType = jsonValue.GetString("eventType");
m_eventTypeHasBeenSet = true;
}
if(jsonValue.ValueExists("timestamp"))
{
m_timestamp = jsonValue.GetString("timestamp");
m_timestampHasBeenSet = true;
}
if(jsonValue.ValueExists("session"))
{
m_session = jsonValue.GetObject("session");
m_sessionHasBeenSet = true;
}
if(jsonValue.ValueExists("version"))
{
m_version = jsonValue.GetString("version");
m_versionHasBeenSet = true;
}
if(jsonValue.ValueExists("attributes"))
{
Aws::Map<Aws::String, JsonView> attributesJsonMap = jsonValue.GetObject("attributes").GetAllObjects();
for(auto& attributesItem : attributesJsonMap)
{
m_attributes[attributesItem.first] = attributesItem.second.AsString();
}
m_attributesHasBeenSet = true;
}
if(jsonValue.ValueExists("metrics"))
{
Aws::Map<Aws::String, JsonView> metricsJsonMap = jsonValue.GetObject("metrics").GetAllObjects();
for(auto& metricsItem : metricsJsonMap)
{
m_metrics[metricsItem.first] = metricsItem.second.AsDouble();
}
m_metricsHasBeenSet = true;
}
return *this;
}
JsonValue Event::Jsonize() const
{
JsonValue payload;
if(m_eventTypeHasBeenSet)
{
payload.WithString("eventType", m_eventType);
}
if(m_timestampHasBeenSet)
{
payload.WithString("timestamp", m_timestamp);
}
if(m_sessionHasBeenSet)
{
payload.WithObject("session", m_session.Jsonize());
}
if(m_versionHasBeenSet)
{
payload.WithString("version", m_version);
}
if(m_attributesHasBeenSet)
{
JsonValue attributesJsonMap;
for(auto& attributesItem : m_attributes)
{
attributesJsonMap.WithString(attributesItem.first, attributesItem.second);
}
payload.WithObject("attributes", std::move(attributesJsonMap));
}
if(m_metricsHasBeenSet)
{
JsonValue metricsJsonMap;
for(auto& metricsItem : m_metrics)
{
metricsJsonMap.WithDouble(metricsItem.first, metricsItem.second);
}
payload.WithObject("metrics", std::move(metricsJsonMap));
}
return payload;
}
} // namespace Model
} // namespace MobileAnalytics
} // namespace Aws

View File

@@ -0,0 +1,65 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/mobileanalytics/model/PutEventsRequest.h>
#include <aws/core/utils/json/JsonSerializer.h>
#include <aws/core/utils/memory/stl/AWSStringStream.h>
#include <utility>
using namespace Aws::MobileAnalytics::Model;
using namespace Aws::Utils::Json;
using namespace Aws::Utils;
PutEventsRequest::PutEventsRequest() :
m_eventsHasBeenSet(false),
m_clientContextHasBeenSet(false),
m_clientContextEncodingHasBeenSet(false)
{
}
Aws::String PutEventsRequest::SerializePayload() const
{
JsonValue payload;
if(m_eventsHasBeenSet)
{
Array<JsonValue> eventsJsonList(m_events.size());
for(unsigned eventsIndex = 0; eventsIndex < eventsJsonList.GetLength(); ++eventsIndex)
{
eventsJsonList[eventsIndex].AsObject(m_events[eventsIndex].Jsonize());
}
payload.WithArray("events", std::move(eventsJsonList));
}
return payload.View().WriteReadable();
}
Aws::Http::HeaderValueCollection PutEventsRequest::GetRequestSpecificHeaders() const
{
Aws::Http::HeaderValueCollection headers;
Aws::StringStream ss;
if(m_clientContextHasBeenSet)
{
ss << m_clientContext;
headers.emplace("x-amz-client-context", ss.str());
ss.str("");
}
if(m_clientContextEncodingHasBeenSet)
{
ss << m_clientContextEncoding;
headers.emplace("x-amz-client-context-encoding", ss.str());
ss.str("");
}
return headers;
}

View File

@@ -0,0 +1,106 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/mobileanalytics/model/Session.h>
#include <aws/core/utils/json/JsonSerializer.h>
#include <utility>
using namespace Aws::Utils::Json;
using namespace Aws::Utils;
namespace Aws
{
namespace MobileAnalytics
{
namespace Model
{
Session::Session() :
m_idHasBeenSet(false),
m_duration(0),
m_durationHasBeenSet(false),
m_startTimestampHasBeenSet(false),
m_stopTimestampHasBeenSet(false)
{
}
Session::Session(JsonView jsonValue) :
m_idHasBeenSet(false),
m_duration(0),
m_durationHasBeenSet(false),
m_startTimestampHasBeenSet(false),
m_stopTimestampHasBeenSet(false)
{
*this = jsonValue;
}
Session& Session::operator =(JsonView jsonValue)
{
if(jsonValue.ValueExists("id"))
{
m_id = jsonValue.GetString("id");
m_idHasBeenSet = true;
}
if(jsonValue.ValueExists("duration"))
{
m_duration = jsonValue.GetInt64("duration");
m_durationHasBeenSet = true;
}
if(jsonValue.ValueExists("startTimestamp"))
{
m_startTimestamp = jsonValue.GetString("startTimestamp");
m_startTimestampHasBeenSet = true;
}
if(jsonValue.ValueExists("stopTimestamp"))
{
m_stopTimestamp = jsonValue.GetString("stopTimestamp");
m_stopTimestampHasBeenSet = true;
}
return *this;
}
JsonValue Session::Jsonize() const
{
JsonValue payload;
if(m_idHasBeenSet)
{
payload.WithString("id", m_id);
}
if(m_durationHasBeenSet)
{
payload.WithInt64("duration", m_duration);
}
if(m_startTimestampHasBeenSet)
{
payload.WithString("startTimestamp", m_startTimestamp);
}
if(m_stopTimestampHasBeenSet)
{
payload.WithString("stopTimestamp", m_stopTimestamp);
}
return payload;
}
} // namespace Model
} // namespace MobileAnalytics
} // namespace Aws