aboutsummaryrefslogtreecommitdiffstats
path: root/app/AglShellGrpcClient.cpp
diff options
context:
space:
mode:
authorMarius Vlad <marius.vlad@collabora.com>2024-12-11 13:30:56 +0200
committerMarius Vlad <marius.vlad@collabora.com>2024-12-12 14:22:17 +0200
commita3f206fcce874d4d98de9280c7f4ae67a57dc207 (patch)
tree794c2f588203566ef4e29c66780d818a76df8cc7 /app/AglShellGrpcClient.cpp
parentfd77d8d38d899ca40d090344582f3ec816fd0591 (diff)
AglShellGrpcClient: Add wait_for_ready + deadline for grpc::ContextHEADmaster
It seems that gRPC channel might not be ready when issueing floating request so add a wait_for_ready + deadline to make sure we don't send the request until the channel is available. Initial testing (though we might need more) shows that this fixes the issue. The way this works is that the client (if started with wait_for_ready set to true, passed in the AglShellGrpcClient constructor) will wait for the channel to be ready and then issue a floating request. There's a hidden deadline of 2 seconds in case that doesn't happen. Bug-AGL: SPEC-5235 Signed-off-by: Marius Vlad <marius.vlad@collabora.com> Change-Id: I40a5ad0dd760dc4559839ae7c302c1d6bc1ff973
Diffstat (limited to 'app/AglShellGrpcClient.cpp')
-rw-r--r--app/AglShellGrpcClient.cpp45
1 files changed, 44 insertions, 1 deletions
diff --git a/app/AglShellGrpcClient.cpp b/app/AglShellGrpcClient.cpp
index c7b76d5..126d84e 100644
--- a/app/AglShellGrpcClient.cpp
+++ b/app/AglShellGrpcClient.cpp
@@ -20,7 +20,7 @@ namespace {
const char kDefaultGrpcServiceAddress[] = "127.0.0.1:14005";
}
-GrpcClient::GrpcClient()
+GrpcClient::GrpcClient(bool wait_for_ready)
{
int retries = 10;
struct timespec ts;
@@ -33,6 +33,8 @@ GrpcClient::GrpcClient()
ts.tv_nsec = 500 * 1000 * 1000;
ts.tv_sec = 0;
+ wait_for_ready_ = wait_for_ready;
+ deadline_ = std::chrono::milliseconds(2000);
auto state = channel->GetState(true);
// artificial delay otherwise to be sure req calls succeed
@@ -61,6 +63,10 @@ GrpcClient::ActivateApp(const std::string& app_id, const std::string& output_nam
grpc::ClientContext context;
::agl_shell_ipc::ActivateResponse reply;
+ if (wait_for_ready_) {
+ context.set_wait_for_ready(true);
+ context.set_deadline(std::chrono::system_clock::now() + deadline_);
+ }
grpc::Status status = m_stub->ActivateApp(&context, request, &reply);
return status.ok();
@@ -75,6 +81,10 @@ GrpcClient::DeactivateApp(const std::string& app_id)
grpc::ClientContext context;
::agl_shell_ipc::DeactivateResponse reply;
+ if (wait_for_ready_) {
+ context.set_wait_for_ready(true);
+ context.set_deadline(std::chrono::system_clock::now() + deadline_);
+ }
grpc::Status status = m_stub->DeactivateApp(&context, request, &reply);
return status.ok();
@@ -92,6 +102,11 @@ GrpcClient::SetAppFloat(const std::string& app_id, int32_t x_pos, int32_t y_pos)
grpc::ClientContext context;
::agl_shell_ipc::FloatResponse reply;
+ if (wait_for_ready_) {
+ context.set_wait_for_ready(true);
+ context.set_deadline(std::chrono::system_clock::now() + deadline_);
+ }
+
grpc::Status status = m_stub->SetAppFloat(&context, request, &reply);
return status.ok();
}
@@ -105,6 +120,10 @@ GrpcClient::SetAppNormal(const std::string& app_id)
grpc::ClientContext context;
::agl_shell_ipc::NormalResponse reply;
+ if (wait_for_ready_) {
+ context.set_wait_for_ready(true);
+ context.set_deadline(std::chrono::system_clock::now() + deadline_);
+ }
grpc::Status status = m_stub->SetAppNormal(&context, request, &reply);
return status.ok();
@@ -119,6 +138,10 @@ GrpcClient::SetAppFullscreen(const std::string& app_id)
grpc::ClientContext context;
::agl_shell_ipc::FullscreenResponse reply;
+ if (wait_for_ready_) {
+ context.set_wait_for_ready(true);
+ context.set_deadline(std::chrono::system_clock::now() + deadline_);
+ }
grpc::Status status = m_stub->SetAppFullscreen(&context, request, &reply);
return status.ok();
@@ -134,6 +157,10 @@ GrpcClient::SetAppOnOutput(const std::string& app_id, const std::string &output)
grpc::ClientContext context;
::agl_shell_ipc::AppOnOutputResponse reply;
+ if (wait_for_ready_) {
+ context.set_wait_for_ready(true);
+ context.set_deadline(std::chrono::system_clock::now() + deadline_);
+ }
grpc::Status status = m_stub->SetAppOnOutput(&context, request, &reply);
return status.ok();
@@ -150,6 +177,10 @@ GrpcClient::SetAppPosition(const std::string& app_id, int32_t x, int32_t y)
grpc::ClientContext context;
::agl_shell_ipc::AppPositionResponse reply;
+ if (wait_for_ready_) {
+ context.set_wait_for_ready(true);
+ context.set_deadline(std::chrono::system_clock::now() + deadline_);
+ }
grpc::Status status = m_stub->SetAppPosition(&context, request, &reply);
return status.ok();
@@ -166,6 +197,10 @@ GrpcClient::SetAppScale(const std::string& app_id, int32_t width, int32_t height
grpc::ClientContext context;
::agl_shell_ipc::AppScaleResponse reply;
+ if (wait_for_ready_) {
+ context.set_wait_for_ready(true);
+ context.set_deadline(std::chrono::system_clock::now() + deadline_);
+ }
grpc::Status status = m_stub->SetAppScale(&context, request, &reply);
return status.ok();
@@ -186,6 +221,10 @@ GrpcClient::SetAppSplit(const std::string& app_id, uint32_t orientation,
grpc::ClientContext context;
::agl_shell_ipc::SplitResponse reply;
+ if (wait_for_ready_) {
+ context.set_wait_for_ready(true);
+ context.set_deadline(std::chrono::system_clock::now() + deadline_);
+ }
grpc::Status status = m_stub->SetAppSplit(&context, request, &reply);
return status.ok();
@@ -211,6 +250,10 @@ GrpcClient::GetOutputs()
::agl_shell_ipc::OutputRequest request;
::agl_shell_ipc::ListOutputResponse response;
+ if (wait_for_ready_) {
+ context.set_wait_for_ready(true);
+ context.set_deadline(std::chrono::system_clock::now() + deadline_);
+ }
grpc::Status status = m_stub->GetOutputs(&context, request, &response);
if (!status.ok())