8#include <aws/core/client/AWSAsyncOperationTemplate.h>
9#include <aws/core/utils/logging/ErrorMacros.h>
10#include <aws/core/utils/component-registry/ComponentRegistry.h>
14namespace Http {
class HttpRequest; }
21 class AsyncCallerContext;
22 template <
typename OutcomeT,
typename ClientT,
typename AWSEndpo
intT,
typename RequestT,
typename HandlerT>
23 class BidirectionalEventStreamingTask;
31 template<
typename ReturnT,
typename ClassT,
typename RequestT>
34 static const bool value = !std::is_const<typename std::remove_reference<RequestT>::type>::value;
37 template<
typename ReturnT,
typename ClassT>
40 static const bool value =
false;
48 template <
typename AwsServiceClientT>
56 AwsServiceClientT* pThis =
static_cast<AwsServiceClientT*
>(
this);
59 &AwsServiceClientT::ShutdownSdkClient);
67 AwsServiceClientT* pThis =
static_cast<AwsServiceClientT*
>(
this);
70 &AwsServiceClientT::ShutdownSdkClient);
87 AwsServiceClientT* pClient =
static_cast<AwsServiceClientT*
>(
this);
99 AwsServiceClientT* pClient =
reinterpret_cast<AwsServiceClientT*
>(pThis);
100 AWS_CHECK_PTR(AwsServiceClientT::GetServiceName(), pClient);
101 if(!pClient->m_isInitialized)
106 std::unique_lock<std::mutex> lock(pClient->m_shutdownMutex);
108 pClient->m_isInitialized =
false;
109 if (pClient->GetHttpClient().use_count() == 1)
111 pClient->DisableRequestProcessing();
116 timeoutMs = pClient->m_clientConfiguration.requestTimeoutMs;
118 pClient->m_shutdownSignal.wait_for(lock,
119 std::chrono::milliseconds(timeoutMs),
120 [&](){
return pClient->m_operationsProcessed.load() == 0; });
122 if (pClient->m_operationsProcessed.load())
124 AWS_LOGSTREAM_FATAL(AwsServiceClientT::GetAllocationTag(),
"Service client "
125 << AwsServiceClientT::GetServiceName() <<
" is shutting down while async tasks are present.");
128 pClient->m_clientConfiguration.executor.reset();
129 pClient->m_clientConfiguration.retryStrategy.reset();
130 pClient->m_endpointProvider.reset();
137 template<typename RequestT, typename HandlerT, typename OperationFuncT, typename std::enable_if<!IsEventStreamOperation<OperationFuncT>::value,
int>::type = 0>
139 const RequestT& request,
140 const HandlerT& handler,
141 const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context =
nullptr)
const
143 const AwsServiceClientT* clientThis =
static_cast<const AwsServiceClientT*
>(
this);
152 template<typename RequestT, typename HandlerT, typename OperationFuncT, typename std::enable_if<IsEventStreamOperation<OperationFuncT>::value,
int>::type = 0>
155 const HandlerT& handler,
156 const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context =
nullptr)
const
158 const AwsServiceClientT* clientThis =
static_cast<const AwsServiceClientT*
>(
this);
166 template<
typename HandlerT,
typename OperationFuncT>
168 const HandlerT& handler,
169 const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context =
nullptr)
const
171 const AwsServiceClientT* clientThis =
static_cast<const AwsServiceClientT*
>(
this);
179 template<typename RequestT, typename OperationFuncT, typename std::enable_if<!IsEventStreamOperation<OperationFuncT>::value,
int>::type = 0>
181 const RequestT& request)
const
182 -> std::future<decltype((static_cast<const AwsServiceClientT*>(
nullptr)->*operationFunc)(request))>
184 const AwsServiceClientT* clientThis =
static_cast<const AwsServiceClientT*
>(
this);
185 return Aws::Client::MakeCallableOperation(AwsServiceClientT::GetAllocationTag(), operationFunc, clientThis, request, clientThis->m_clientConfiguration.executor.get());
193 template<typename RequestT, typename OperationFuncT, typename std::enable_if<IsEventStreamOperation<OperationFuncT>::value,
int>::type = 0>
195 -> std::future<decltype((static_cast<const AwsServiceClientT*>(
nullptr)->*operationFunc)(request))>
197 const AwsServiceClientT* clientThis =
static_cast<const AwsServiceClientT*
>(
this);
206 template<
typename OperationFuncT>
208 -> std::future<decltype((static_cast<const AwsServiceClientT*>(
nullptr)->*operationFunc)())>
210 const AwsServiceClientT* clientThis =
static_cast<const AwsServiceClientT*
>(
this);
214 template <
typename OutcomeT,
typename ClientT,
typename AWSEndpo
intT,
typename RequestT,
typename HandlerT>
217 template <
typename ClientT,
typename OutcomeT,
typename RequestT,
typename EncoderStreamT,
218 typename HandlerT,
typename StreamReadyHandlerT>
220 const ClientT*, RequestT&, std::shared_ptr<RequestT>, std::shared_ptr<EncoderStreamT>,
221 std::shared_ptr<Aws::Utils::Stream::HttpWriteDataStreamBuf>,
const std::shared_ptr<Aws::Http::HttpRequest>&,
223 const StreamReadyHandlerT&,
const HandlerT&,
const std::shared_ptr<const Aws::Client::AsyncCallerContext>&);
ClientWithAsyncTemplateMethods & operator=(const ClientWithAsyncTemplateMethods &other)
std::condition_variable m_shutdownSignal
std::atomic< bool > m_isInitialized
auto SubmitCallable(OperationFuncT operationFunc, const RequestT &request) const -> std::future< decltype((static_cast< const AwsServiceClientT * >(nullptr) -> *operationFunc)(request))>
auto SubmitCallable(OperationFuncT operationFunc, RequestT &request) const -> std::future< decltype((static_cast< const AwsServiceClientT * >(nullptr) -> *operationFunc)(request))>
void SubmitAsync(OperationFuncT operationFunc, RequestT &request, const HandlerT &handler, const std::shared_ptr< const Aws::Client::AsyncCallerContext > &context=nullptr) const
ClientWithAsyncTemplateMethods()
void SubmitAsync(OperationFuncT operationFunc, const RequestT &request, const HandlerT &handler, const std::shared_ptr< const Aws::Client::AsyncCallerContext > &context=nullptr) const
void SubmitAsync(OperationFuncT operationFunc, const HandlerT &handler, const std::shared_ptr< const Aws::Client::AsyncCallerContext > &context=nullptr) const
std::atomic< size_t > m_operationsProcessed
ClientWithAsyncTemplateMethods(const ClientWithAsyncTemplateMethods &other)
std::mutex m_shutdownMutex
static void ShutdownSdkClient(void *pThis, int64_t timeoutMs=-1)
friend void SubmitBidirectionalStreamingRequest(const ClientT *, RequestT &, std::shared_ptr< RequestT >, std::shared_ptr< EncoderStreamT >, std::shared_ptr< Aws::Utils::Stream::HttpWriteDataStreamBuf >, const std::shared_ptr< Aws::Http::HttpRequest > &, Aws::Utils::Threading::Executor *, const StreamReadyHandlerT &, const HandlerT &, const std::shared_ptr< const Aws::Client::AsyncCallerContext > &)
auto SubmitCallable(OperationFuncT operationFunc) const -> std::future< decltype((static_cast< const AwsServiceClientT * >(nullptr) -> *operationFunc)())>
virtual ~ClientWithAsyncTemplateMethods()
auto AWS_CORE_LOCAL MakeCallableOperation(const char *ALLOCATION_TAG, OperationFuncT &&operationFunc, const ClientT *clientThis, const RequestT &request, ExecutorT *pExecutor) -> std::future< decltype((clientThis-> *operationFunc)(request))>
void AWS_CORE_LOCAL MakeAsyncOperation(OperationFuncT &&operationFunc, const ClientT *clientThis, const RequestT &request, const HandlerT &handler, const HandlerContextT &context, ExecutorT *pExecutor)
void AWS_CORE_LOCAL MakeAsyncStreamingOperation(OperationFuncT &&operationFunc, const ClientT *clientThis, RequestT &request, const HandlerT &handler, const HandlerContextT &context, ExecutorT *pExecutor)
auto AWS_CORE_LOCAL MakeCallableStreamingOperation(const char *ALLOCATION_TAG, OperationFuncT &&operationFunc, const ClientT *clientThis, RequestT &request, ExecutorT *pExecutor) -> std::future< decltype((clientThis-> *operationFunc)(request))>
AWS_CORE_API void DeRegisterComponent(void *pClient)
AWS_CORE_API void RegisterComponent(const char *clientName, void *pClient, ComponentTerminateFn terminateMethod)