aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/AglShellGrpcClient.cpp45
-rw-r--r--app/AglShellGrpcClient.h5
-rw-r--r--app/main.cpp2
3 files changed, 49 insertions, 3 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())
diff --git a/app/AglShellGrpcClient.h b/app/AglShellGrpcClient.h
index f66b44c..5030359 100644
--- a/app/AglShellGrpcClient.h
+++ b/app/AglShellGrpcClient.h
@@ -13,6 +13,7 @@
#include <grpcpp/health_check_service_interface.h>
#include "agl_shell.grpc.pb.h"
+#include <chrono>
typedef void (*Callback)(agl_shell_ipc::AppStateResponse app_response);
@@ -88,7 +89,7 @@ private:
class GrpcClient {
public:
- GrpcClient();
+ GrpcClient(bool wait_for_ready);
bool ActivateApp(const std::string& app_id, const std::string& output_name);
bool DeactivateApp(const std::string& app_id);
bool SetAppFloat(const std::string& app_id, int32_t x_pos, int32_t y_pos);
@@ -106,6 +107,8 @@ public:
private:
Reader *reader;
+ bool wait_for_ready_{false};
+ std::chrono::milliseconds deadline_;
std::unique_ptr<agl_shell_ipc::AglShellManagerService::Stub> m_stub;
};
diff --git a/app/main.cpp b/app/main.cpp
index 3953646..cb6218b 100644
--- a/app/main.cpp
+++ b/app/main.cpp
@@ -868,7 +868,7 @@ int main(int argc, char *argv[])
struct window *window;
std::string role = "cluster-receiver";
- GrpcClient *client = new GrpcClient();
+ GrpcClient *client = new GrpcClient(true);
sa.sa_sigaction = signal_int;
sigemptyset(&sa.sa_mask);