diff options
Diffstat (limited to 'homescreen/src/AglShellGrpcClient.cpp')
-rw-r--r-- | homescreen/src/AglShellGrpcClient.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/homescreen/src/AglShellGrpcClient.cpp b/homescreen/src/AglShellGrpcClient.cpp index 6f4ff24..ee7510f 100644 --- a/homescreen/src/AglShellGrpcClient.cpp +++ b/homescreen/src/AglShellGrpcClient.cpp @@ -3,6 +3,7 @@ #include <mutex> #include <condition_variable> +#include <chrono> #include <grpc/grpc.h> #include <grpcpp/grpcpp.h> #include <grpcpp/server.h> @@ -14,6 +15,9 @@ #include "AglShellGrpcClient.h" #include "agl_shell.grpc.pb.h" +#include "hmi-debug.h" + +using namespace std::chrono; namespace { const char kDefaultGrpcServiceAddress[] = "127.0.0.1:14005"; @@ -21,9 +25,25 @@ namespace { GrpcClient::GrpcClient() { + struct timespec ts; auto channel = grpc::CreateChannel(kDefaultGrpcServiceAddress, grpc::InsecureChannelCredentials()); + clock_gettime(CLOCK_MONOTONIC, &ts); + ts.tv_sec = 0; + ts.tv_nsec = 500 * 1000 * 1000; // 500ms + + bool try_to_connect = true; + grpc_connectivity_state state = channel->GetState(try_to_connect); + + while (state != GRPC_CHANNEL_READY) { + state = channel->GetState(try_to_connect); + + HMI_DEBUG("HomesScreen", "waiting for channel state to be ready, current state %d", state); + nanosleep(&ts, NULL); + } + + // init the stub here m_stub = agl_shell_ipc::AglShellManagerService::NewStub(channel); reader = new Reader(m_stub.get()); @@ -159,9 +179,9 @@ GrpcClient::Wait(void) } void -GrpcClient::AppStatusState(Callback callback) +GrpcClient::AppStatusState(Callback callback, void *data) { - reader->AppStatusState(callback); + reader->AppStatusState(callback, data); } std::vector<std::string> |