Skip to content

Commit

Permalink
Code generation example
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyRyabinin committed Feb 24, 2025
1 parent c3b28a2 commit cad86c2
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace Model
/**
* Underlying Event Stream Handler which is used to define callback functions.
*/
inline const SubscribeToShardHandler& GetEventStreamHandler() const { return m_handler; }
inline SubscribeToShardHandler& GetEventStreamHandler() { return m_handler; }

/**
* Underlying Event Stream Handler which is used to define callback functions.
Expand Down
11 changes: 11 additions & 0 deletions generated/src/aws-cpp-sdk-kinesis/source/KinesisClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,17 @@ SubscribeToShardOutcome KinesisClient::SubscribeToShard(SubscribeToShardRequest&
request.SetResponseStreamFactory(
[&] { request.GetEventStreamDecoder().Reset(); return Aws::New<Aws::Utils::Event::EventDecoderStream>(ALLOCATION_TAG, request.GetEventStreamDecoder()); }
);
if (!request.GetHeadersReceivedEventHandler()) {
request.SetHeadersReceivedEventHandler([&request](const Http::HttpRequest*, Http::HttpResponse* response) {
if (!response) {
AWS_LOGSTREAM_FATAL("SubscribeToShard", "Unexpected response nullptr!");
return;
}
if (const auto initialResponseHandler = request.GetEventStreamHandler().GetInitialResponseCallbackEx()) {
initialResponseHandler({response->GetHeaders()}, Utils::Event::InitialResponseType::ON_RESPONSE);
}
});
}
return SubscribeToShardOutcome(MakeRequestDeserialize(&request, request.GetServiceRequestName(), Aws::Http::HttpMethod::HTTP_POST, [&](Aws::Endpoint::AWSEndpoint& resolvedEndpoint) -> void {
AWS_UNREFERENCED_PARAM(resolvedEndpoint);
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace Model
/**
* Underlying Event Stream Handler which is used to define callback functions.
*/
inline const InvokeWithResponseStreamHandler& GetEventStreamHandler() const { return m_handler; }
inline InvokeWithResponseStreamHandler& GetEventStreamHandler() { return m_handler; }

/**
* Underlying Event Stream Handler which is used to define callback functions.
Expand Down
11 changes: 11 additions & 0 deletions generated/src/aws-cpp-sdk-lambda/source/LambdaClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,17 @@ InvokeWithResponseStreamOutcome LambdaClient::InvokeWithResponseStream(InvokeWit
request.SetResponseStreamFactory(
[&] { request.GetEventStreamDecoder().Reset(); return Aws::New<Aws::Utils::Event::EventDecoderStream>(ALLOCATION_TAG, request.GetEventStreamDecoder()); }
);
if (!request.GetHeadersReceivedEventHandler()) {
request.SetHeadersReceivedEventHandler([&request](const Http::HttpRequest*, Http::HttpResponse* response) {
if (!response) {
AWS_LOGSTREAM_FATAL("InvokeWithResponseStream", "Unexpected response nullptr!");
return;
}
if (const auto initialResponseHandler = request.GetEventStreamHandler().GetInitialResponseCallbackEx()) {
initialResponseHandler({response->GetHeaders()}, Utils::Event::InitialResponseType::ON_RESPONSE);
}
});
}
return InvokeWithResponseStreamOutcome(MakeRequest(request, endpointResolutionOutcome.GetResult(), Aws::Http::HttpMethod::HTTP_POST));
},
TracingUtils::SMITHY_CLIENT_DURATION_METRIC,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ InvokeWithResponseStreamRequest::InvokeWithResponseStreamRequest() :
m_qualifierHasBeenSet(false),
m_handler(), m_decoder(Aws::Utils::Event::EventStreamDecoder(&m_handler))
{
AmazonWebServiceRequest::SetHeadersReceivedEventHandler([this](const Http::HttpRequest*, Http::HttpResponse* response)
{
auto& initialResponseHandler = m_handler.GetInitialResponseCallbackEx();
if (initialResponseHandler) {
initialResponseHandler(InvokeWithResponseStreamInitialResponse(response->GetHeaders()), Utils::Event::InitialResponseType::ON_RESPONSE);
}
});
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace Model
/**
* Underlying Event Stream Handler which is used to define callback functions.
*/
inline const SelectObjectContentHandler& GetEventStreamHandler() const { return m_handler; }
inline SelectObjectContentHandler& GetEventStreamHandler() { return m_handler; }

/**
* Underlying Event Stream Handler which is used to define callback functions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace Model
/**
* Underlying Event Stream Handler which is used to define callback functions.
*/
inline const StartCallAnalyticsStreamTranscriptionHandler& GetEventStreamHandler() const { return m_handler; }
inline StartCallAnalyticsStreamTranscriptionHandler& GetEventStreamHandler() { return m_handler; }

/**
* Underlying Event Stream Handler which is used to define callback functions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace Model
/**
* Underlying Event Stream Handler which is used to define callback functions.
*/
inline const StartMedicalScribeStreamHandler& GetEventStreamHandler() const { return m_handler; }
inline StartMedicalScribeStreamHandler& GetEventStreamHandler() { return m_handler; }

/**
* Underlying Event Stream Handler which is used to define callback functions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace Model
/**
* Underlying Event Stream Handler which is used to define callback functions.
*/
inline const StartMedicalStreamTranscriptionHandler& GetEventStreamHandler() const { return m_handler; }
inline StartMedicalStreamTranscriptionHandler& GetEventStreamHandler() { return m_handler; }

/**
* Underlying Event Stream Handler which is used to define callback functions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace Model
/**
* Underlying Event Stream Handler which is used to define callback functions.
*/
inline const StartStreamTranscriptionHandler& GetEventStreamHandler() const { return m_handler; }
inline StartStreamTranscriptionHandler& GetEventStreamHandler() { return m_handler; }

/**
* Underlying Event Stream Handler which is used to define callback functions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <aws/core/utils/DNS.h>
#include <aws/core/utils/logging/LogMacros.h>
#include <aws/core/utils/logging/ErrorMacros.h>
#include <aws/core/client/AWSClientEventStreamingAsyncTask.h>
#include <aws/core/utils/event/EventStream.h>

#include <aws/transcribestreaming/TranscribeStreamingServiceClient.h>
Expand Down Expand Up @@ -243,31 +244,23 @@ void TranscribeStreamingServiceClient::StartCallAnalyticsStreamTranscriptionAsyn
return;
}
endpointResolutionOutcome.GetResult().AddPathSegments("/call-analytics-stream-transcription");
request.SetResponseStreamFactory(
[&] { request.GetEventStreamDecoder().Reset(); return Aws::New<Aws::Utils::Event::EventDecoderStream>(ALLOCATION_TAG, request.GetEventStreamDecoder()); }
);

auto eventEncoderStream = Aws::MakeShared<Model::AudioStream>(ALLOCATION_TAG);
eventEncoderStream->SetSigner(GetSignerByName(Aws::Auth::EVENTSTREAM_SIGV4_SIGNER));
request.SetAudioStream(eventEncoderStream); // this becomes the body of the request
auto sem = Aws::MakeShared<Aws::Utils::Threading::Semaphore>(ALLOCATION_TAG, 0, 1);
request.SetRequestSignedHandler([eventEncoderStream, sem](const Aws::Http::HttpRequest& httpRequest) { eventEncoderStream->SetSignatureSeed(Aws::Client::GetAuthorizationHeader(httpRequest)); sem->ReleaseAll(); });
auto requestCopy = Aws::MakeShared<StartCallAnalyticsStreamTranscriptionRequest>("StartCallAnalyticsStreamTranscription", request);
requestCopy->SetAudioStream(eventEncoderStream); // this becomes the body of the request
request.SetAudioStream(eventEncoderStream);

m_clientConfiguration.executor->Submit([this, endpointResolutionOutcome, &request, handler, handlerContext] () mutable {
JsonOutcome outcome = MakeRequest(request, endpointResolutionOutcome.GetResult(), Aws::Http::HttpMethod::HTTP_POST, Aws::Auth::EVENTSTREAM_SIGV4_SIGNER);
if(outcome.IsSuccess())
{
handler(this, request, StartCallAnalyticsStreamTranscriptionOutcome(NoResult()), handlerContext);
}
else
{
request.GetAudioStream()->Close();
handler(this, request, StartCallAnalyticsStreamTranscriptionOutcome(outcome.GetError()), handlerContext);
}
return StartCallAnalyticsStreamTranscriptionOutcome(NoResult());
});
auto asyncTask = CreateBidirectionalEventStreamTask<StartCallAnalyticsStreamTranscriptionOutcome>(this,
endpointResolutionOutcome.GetResultWithOwnership(),
requestCopy,
handler,
handlerContext,
eventEncoderStream);
auto sem = asyncTask.GetSemaphore();
m_clientConfiguration.executor->Submit(std::move(asyncTask));
sem->WaitOne();
streamReadyHandler(*request.GetAudioStream());
streamReadyHandler(*eventEncoderStream);
}
void TranscribeStreamingServiceClient::StartMedicalScribeStreamAsync(Model::StartMedicalScribeStreamRequest& request,
const StartMedicalScribeStreamStreamReadyHandler& streamReadyHandler,
Expand Down Expand Up @@ -309,31 +302,23 @@ void TranscribeStreamingServiceClient::StartMedicalScribeStreamAsync(Model::Star
return;
}
endpointResolutionOutcome.GetResult().AddPathSegments("/medical-scribe-stream");
request.SetResponseStreamFactory(
[&] { request.GetEventStreamDecoder().Reset(); return Aws::New<Aws::Utils::Event::EventDecoderStream>(ALLOCATION_TAG, request.GetEventStreamDecoder()); }
);

auto eventEncoderStream = Aws::MakeShared<Model::MedicalScribeInputStream>(ALLOCATION_TAG);
eventEncoderStream->SetSigner(GetSignerByName(Aws::Auth::EVENTSTREAM_SIGV4_SIGNER));
request.SetInputStream(eventEncoderStream); // this becomes the body of the request
auto sem = Aws::MakeShared<Aws::Utils::Threading::Semaphore>(ALLOCATION_TAG, 0, 1);
request.SetRequestSignedHandler([eventEncoderStream, sem](const Aws::Http::HttpRequest& httpRequest) { eventEncoderStream->SetSignatureSeed(Aws::Client::GetAuthorizationHeader(httpRequest)); sem->ReleaseAll(); });
auto requestCopy = Aws::MakeShared<StartMedicalScribeStreamRequest>("StartMedicalScribeStream", request);
requestCopy->SetInputStream(eventEncoderStream); // this becomes the body of the request
request.SetInputStream(eventEncoderStream);

m_clientConfiguration.executor->Submit([this, endpointResolutionOutcome, &request, handler, handlerContext] () mutable {
JsonOutcome outcome = MakeRequest(request, endpointResolutionOutcome.GetResult(), Aws::Http::HttpMethod::HTTP_POST, Aws::Auth::EVENTSTREAM_SIGV4_SIGNER);
if(outcome.IsSuccess())
{
handler(this, request, StartMedicalScribeStreamOutcome(NoResult()), handlerContext);
}
else
{
request.GetInputStream()->Close();
handler(this, request, StartMedicalScribeStreamOutcome(outcome.GetError()), handlerContext);
}
return StartMedicalScribeStreamOutcome(NoResult());
});
auto asyncTask = CreateBidirectionalEventStreamTask<StartMedicalScribeStreamOutcome>(this,
endpointResolutionOutcome.GetResultWithOwnership(),
requestCopy,
handler,
handlerContext,
eventEncoderStream);
auto sem = asyncTask.GetSemaphore();
m_clientConfiguration.executor->Submit(std::move(asyncTask));
sem->WaitOne();
streamReadyHandler(*request.GetInputStream());
streamReadyHandler(*eventEncoderStream);
}
void TranscribeStreamingServiceClient::StartMedicalStreamTranscriptionAsync(Model::StartMedicalStreamTranscriptionRequest& request,
const StartMedicalStreamTranscriptionStreamReadyHandler& streamReadyHandler,
Expand Down Expand Up @@ -387,31 +372,23 @@ void TranscribeStreamingServiceClient::StartMedicalStreamTranscriptionAsync(Mode
return;
}
endpointResolutionOutcome.GetResult().AddPathSegments("/medical-stream-transcription");
request.SetResponseStreamFactory(
[&] { request.GetEventStreamDecoder().Reset(); return Aws::New<Aws::Utils::Event::EventDecoderStream>(ALLOCATION_TAG, request.GetEventStreamDecoder()); }
);

auto eventEncoderStream = Aws::MakeShared<Model::AudioStream>(ALLOCATION_TAG);
eventEncoderStream->SetSigner(GetSignerByName(Aws::Auth::EVENTSTREAM_SIGV4_SIGNER));
request.SetAudioStream(eventEncoderStream); // this becomes the body of the request
auto sem = Aws::MakeShared<Aws::Utils::Threading::Semaphore>(ALLOCATION_TAG, 0, 1);
request.SetRequestSignedHandler([eventEncoderStream, sem](const Aws::Http::HttpRequest& httpRequest) { eventEncoderStream->SetSignatureSeed(Aws::Client::GetAuthorizationHeader(httpRequest)); sem->ReleaseAll(); });
auto requestCopy = Aws::MakeShared<StartMedicalStreamTranscriptionRequest>("StartMedicalStreamTranscription", request);
requestCopy->SetAudioStream(eventEncoderStream); // this becomes the body of the request
request.SetAudioStream(eventEncoderStream);

m_clientConfiguration.executor->Submit([this, endpointResolutionOutcome, &request, handler, handlerContext] () mutable {
JsonOutcome outcome = MakeRequest(request, endpointResolutionOutcome.GetResult(), Aws::Http::HttpMethod::HTTP_POST, Aws::Auth::EVENTSTREAM_SIGV4_SIGNER);
if(outcome.IsSuccess())
{
handler(this, request, StartMedicalStreamTranscriptionOutcome(NoResult()), handlerContext);
}
else
{
request.GetAudioStream()->Close();
handler(this, request, StartMedicalStreamTranscriptionOutcome(outcome.GetError()), handlerContext);
}
return StartMedicalStreamTranscriptionOutcome(NoResult());
});
auto asyncTask = CreateBidirectionalEventStreamTask<StartMedicalStreamTranscriptionOutcome>(this,
endpointResolutionOutcome.GetResultWithOwnership(),
requestCopy,
handler,
handlerContext,
eventEncoderStream);
auto sem = asyncTask.GetSemaphore();
m_clientConfiguration.executor->Submit(std::move(asyncTask));
sem->WaitOne();
streamReadyHandler(*request.GetAudioStream());
streamReadyHandler(*eventEncoderStream);
}
void TranscribeStreamingServiceClient::StartStreamTranscriptionAsync(Model::StartStreamTranscriptionRequest& request,
const StartStreamTranscriptionStreamReadyHandler& streamReadyHandler,
Expand Down Expand Up @@ -447,29 +424,21 @@ void TranscribeStreamingServiceClient::StartStreamTranscriptionAsync(Model::Star
return;
}
endpointResolutionOutcome.GetResult().AddPathSegments("/stream-transcription");
request.SetResponseStreamFactory(
[&] { request.GetEventStreamDecoder().Reset(); return Aws::New<Aws::Utils::Event::EventDecoderStream>(ALLOCATION_TAG, request.GetEventStreamDecoder()); }
);

auto eventEncoderStream = Aws::MakeShared<Model::AudioStream>(ALLOCATION_TAG);
eventEncoderStream->SetSigner(GetSignerByName(Aws::Auth::EVENTSTREAM_SIGV4_SIGNER));
request.SetAudioStream(eventEncoderStream); // this becomes the body of the request
auto sem = Aws::MakeShared<Aws::Utils::Threading::Semaphore>(ALLOCATION_TAG, 0, 1);
request.SetRequestSignedHandler([eventEncoderStream, sem](const Aws::Http::HttpRequest& httpRequest) { eventEncoderStream->SetSignatureSeed(Aws::Client::GetAuthorizationHeader(httpRequest)); sem->ReleaseAll(); });
auto requestCopy = Aws::MakeShared<StartStreamTranscriptionRequest>("StartStreamTranscription", request);
requestCopy->SetAudioStream(eventEncoderStream); // this becomes the body of the request
request.SetAudioStream(eventEncoderStream);

m_clientConfiguration.executor->Submit([this, endpointResolutionOutcome, &request, handler, handlerContext] () mutable {
JsonOutcome outcome = MakeRequest(request, endpointResolutionOutcome.GetResult(), Aws::Http::HttpMethod::HTTP_POST, Aws::Auth::EVENTSTREAM_SIGV4_SIGNER);
if(outcome.IsSuccess())
{
handler(this, request, StartStreamTranscriptionOutcome(NoResult()), handlerContext);
}
else
{
request.GetAudioStream()->Close();
handler(this, request, StartStreamTranscriptionOutcome(outcome.GetError()), handlerContext);
}
return StartStreamTranscriptionOutcome(NoResult());
});
auto asyncTask = CreateBidirectionalEventStreamTask<StartStreamTranscriptionOutcome>(this,
endpointResolutionOutcome.GetResultWithOwnership(),
requestCopy,
handler,
handlerContext,
eventEncoderStream);
auto sem = asyncTask.GetSemaphore();
m_clientConfiguration.executor->Submit(std::move(asyncTask));
sem->WaitOne();
streamReadyHandler(*request.GetAudioStream());
streamReadyHandler(*eventEncoderStream);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ StartCallAnalyticsStreamTranscriptionRequest::StartCallAnalyticsStreamTranscript
m_piiEntityTypesHasBeenSet(false),
m_handler(), m_decoder(Aws::Utils::Event::EventStreamDecoder(&m_handler))
{
AmazonWebServiceRequest::SetHeadersReceivedEventHandler([this](const Http::HttpRequest*, Http::HttpResponse* response)
{
auto& initialResponseHandler = m_handler.GetInitialResponseCallbackEx();
if (initialResponseHandler) {
initialResponseHandler(StartCallAnalyticsStreamTranscriptionInitialResponse(response->GetHeaders()), Utils::Event::InitialResponseType::ON_RESPONSE);
}
});
}

std::shared_ptr<Aws::IOStream> StartCallAnalyticsStreamTranscriptionRequest::GetBody() const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ StartMedicalScribeStreamRequest::StartMedicalScribeStreamRequest() :
m_mediaEncodingHasBeenSet(false),
m_handler(), m_decoder(Aws::Utils::Event::EventStreamDecoder(&m_handler))
{
AmazonWebServiceRequest::SetHeadersReceivedEventHandler([this](const Http::HttpRequest*, Http::HttpResponse* response)
{
auto& initialResponseHandler = m_handler.GetInitialResponseCallbackEx();
if (initialResponseHandler) {
initialResponseHandler(StartMedicalScribeStreamInitialResponse(response->GetHeaders()), Utils::Event::InitialResponseType::ON_RESPONSE);
}
});
}

std::shared_ptr<Aws::IOStream> StartMedicalScribeStreamRequest::GetBody() const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ StartMedicalStreamTranscriptionRequest::StartMedicalStreamTranscriptionRequest()
m_contentIdentificationTypeHasBeenSet(false),
m_handler(), m_decoder(Aws::Utils::Event::EventStreamDecoder(&m_handler))
{
AmazonWebServiceRequest::SetHeadersReceivedEventHandler([this](const Http::HttpRequest*, Http::HttpResponse* response)
{
auto& initialResponseHandler = m_handler.GetInitialResponseCallbackEx();
if (initialResponseHandler) {
initialResponseHandler(StartMedicalStreamTranscriptionInitialResponse(response->GetHeaders()), Utils::Event::InitialResponseType::ON_RESPONSE);
}
});
}

std::shared_ptr<Aws::IOStream> StartMedicalStreamTranscriptionRequest::GetBody() const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,6 @@ StartStreamTranscriptionRequest::StartStreamTranscriptionRequest() :
m_vocabularyFilterNamesHasBeenSet(false),
m_handler(), m_decoder(Aws::Utils::Event::EventStreamDecoder(&m_handler))
{
AmazonWebServiceRequest::SetHeadersReceivedEventHandler([this](const Http::HttpRequest*, Http::HttpResponse* response)
{
auto& initialResponseHandler = m_handler.GetInitialResponseCallbackEx();
if (initialResponseHandler) {
initialResponseHandler(StartStreamTranscriptionInitialResponse(response->GetHeaders()), Utils::Event::InitialResponseType::ON_RESPONSE);
}
});
}

std::shared_ptr<Aws::IOStream> StartStreamTranscriptionRequest::GetBody() const
Expand Down

0 comments on commit cad86c2

Please sign in to comment.