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 00078f3 commit 602782b
Show file tree
Hide file tree
Showing 26 changed files with 100 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace Model
public:
AWS_KINESIS_API SubscribeToShardHandler();
AWS_KINESIS_API SubscribeToShardHandler& operator=(const SubscribeToShardHandler&) = default;
AWS_KINESIS_API SubscribeToShardHandler(const SubscribeToShardHandler&) = default;

AWS_KINESIS_API virtual void OnEvent() override;

Expand Down
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 @@ -39,6 +39,7 @@ namespace Model
public:
AWS_LAMBDA_API InvokeWithResponseStreamHandler();
AWS_LAMBDA_API InvokeWithResponseStreamHandler& operator=(const InvokeWithResponseStreamHandler&) = default;
AWS_LAMBDA_API InvokeWithResponseStreamHandler(const InvokeWithResponseStreamHandler&) = default;

AWS_LAMBDA_API virtual void OnEvent() override;

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 @@ -51,6 +51,7 @@ namespace Model
public:
AWS_LEXRUNTIMEV2_API StartConversationHandler();
AWS_LEXRUNTIMEV2_API StartConversationHandler& operator=(const StartConversationHandler&) = default;
AWS_LEXRUNTIMEV2_API StartConversationHandler(const StartConversationHandler&) = default;

AWS_LEXRUNTIMEV2_API virtual void OnEvent() override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace Model
/**
* Underlying Event Stream Handler which is used to define callback functions.
*/
inline const StartConversationHandler& GetEventStreamHandler() const { return m_handler; }
inline StartConversationHandler& 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/lexv2-runtime/LexRuntimeV2Client.h>
Expand Down Expand Up @@ -502,29 +503,21 @@ void LexRuntimeV2Client::StartConversationAsync(Model::StartConversationRequest&
endpointResolutionOutcome.GetResult().AddPathSegments("/sessions/");
endpointResolutionOutcome.GetResult().AddPathSegment(request.GetSessionId());
endpointResolutionOutcome.GetResult().AddPathSegments("/conversation");
request.SetResponseStreamFactory(
[&] { request.GetEventStreamDecoder().Reset(); return Aws::New<Aws::Utils::Event::EventDecoderStream>(ALLOCATION_TAG, request.GetEventStreamDecoder()); }
);

auto eventEncoderStream = Aws::MakeShared<Model::StartConversationRequestEventStream>(ALLOCATION_TAG);
eventEncoderStream->SetSigner(GetSignerByName(Aws::Auth::EVENTSTREAM_SIGV4_SIGNER));
request.SetRequestEventStream(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<StartConversationRequest>("StartConversation", request);
requestCopy->SetRequestEventStream(eventEncoderStream); // this becomes the body of the request
request.SetRequestEventStream(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, StartConversationOutcome(NoResult()), handlerContext);
}
else
{
request.GetRequestEventStream()->Close();
handler(this, request, StartConversationOutcome(outcome.GetError()), handlerContext);
}
return StartConversationOutcome(NoResult());
});
auto asyncTask = CreateBidirectionalEventStreamTask<StartConversationOutcome>(this,
endpointResolutionOutcome.GetResultWithOwnership(),
requestCopy,
handler,
handlerContext,
eventEncoderStream);
auto sem = asyncTask.GetSemaphore();
m_clientConfiguration.executor->Submit(std::move(asyncTask));
sem->WaitOne();
streamReadyHandler(*request.GetRequestEventStream());
streamReadyHandler(*eventEncoderStream);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ StartConversationRequest::StartConversationRequest() :
m_conversationModeHasBeenSet(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(StartConversationInitialResponse(response->GetHeaders()), Utils::Event::InitialResponseType::ON_RESPONSE);
}
});
}

std::shared_ptr<Aws::IOStream> StartConversationRequest::GetBody() const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace Model
public:
AWS_S3_API SelectObjectContentHandler();
AWS_S3_API SelectObjectContentHandler& operator=(const SelectObjectContentHandler&) = default;
AWS_S3_API SelectObjectContentHandler(const SelectObjectContentHandler&) = default;

AWS_S3_API virtual void OnEvent() override;

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 @@ -39,6 +39,7 @@ namespace Model
public:
AWS_TRANSCRIBESTREAMINGSERVICE_API StartCallAnalyticsStreamTranscriptionHandler();
AWS_TRANSCRIBESTREAMINGSERVICE_API StartCallAnalyticsStreamTranscriptionHandler& operator=(const StartCallAnalyticsStreamTranscriptionHandler&) = default;
AWS_TRANSCRIBESTREAMINGSERVICE_API StartCallAnalyticsStreamTranscriptionHandler(const StartCallAnalyticsStreamTranscriptionHandler&) = default;

AWS_TRANSCRIBESTREAMINGSERVICE_API virtual void OnEvent() override;

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 @@ -36,6 +36,7 @@ namespace Model
public:
AWS_TRANSCRIBESTREAMINGSERVICE_API StartMedicalScribeStreamHandler();
AWS_TRANSCRIBESTREAMINGSERVICE_API StartMedicalScribeStreamHandler& operator=(const StartMedicalScribeStreamHandler&) = default;
AWS_TRANSCRIBESTREAMINGSERVICE_API StartMedicalScribeStreamHandler(const StartMedicalScribeStreamHandler&) = default;

AWS_TRANSCRIBESTREAMINGSERVICE_API virtual void OnEvent() override;

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 @@ -36,6 +36,7 @@ namespace Model
public:
AWS_TRANSCRIBESTREAMINGSERVICE_API StartMedicalStreamTranscriptionHandler();
AWS_TRANSCRIBESTREAMINGSERVICE_API StartMedicalStreamTranscriptionHandler& operator=(const StartMedicalStreamTranscriptionHandler&) = default;
AWS_TRANSCRIBESTREAMINGSERVICE_API StartMedicalStreamTranscriptionHandler(const StartMedicalStreamTranscriptionHandler&) = default;

AWS_TRANSCRIBESTREAMINGSERVICE_API virtual void OnEvent() override;

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 @@ -36,6 +36,7 @@ namespace Model
public:
AWS_TRANSCRIBESTREAMINGSERVICE_API StartStreamTranscriptionHandler();
AWS_TRANSCRIBESTREAMINGSERVICE_API StartStreamTranscriptionHandler& operator=(const StartStreamTranscriptionHandler&) = default;
AWS_TRANSCRIBESTREAMINGSERVICE_API StartStreamTranscriptionHandler(const StartStreamTranscriptionHandler&) = default;

AWS_TRANSCRIBESTREAMINGSERVICE_API virtual void OnEvent() override;

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
Loading

0 comments on commit 602782b

Please sign in to comment.