diff options
author | Marius Vlad <marius.vlad@collabora.com> | 2023-10-25 23:41:46 +0300 |
---|---|---|
committer | Marius Vlad <marius.vlad@collabora.com> | 2023-10-26 00:41:59 +0300 |
commit | 537937138e9855408c6b8af4331725c8a1d52705 (patch) | |
tree | 40b43c4b1e043ac153e3fc458d4463fbc228af76 /homescreen/src/AglShellGrpcClient.cpp | |
parent | c13f6c196066bccb33c3a1f524a108b52c356bfd (diff) |
homescreen: Re-work gRPC client start-up
And start the gRPC client as soon as possible and just wait for
a connected status after we bounded to the agl-shell
extension/interface.
Bug-AGL: SPEC-4912
Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Change-Id: I26da89dd6aaf1b5c2357d70dcaed7622c1892c31
Diffstat (limited to 'homescreen/src/AglShellGrpcClient.cpp')
-rw-r--r-- | homescreen/src/AglShellGrpcClient.cpp | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/homescreen/src/AglShellGrpcClient.cpp b/homescreen/src/AglShellGrpcClient.cpp index ee7510f..f3c72ca 100644 --- a/homescreen/src/AglShellGrpcClient.cpp +++ b/homescreen/src/AglShellGrpcClient.cpp @@ -25,28 +25,31 @@ namespace { GrpcClient::GrpcClient() { - struct timespec ts; - auto channel = grpc::CreateChannel(kDefaultGrpcServiceAddress, + m_channel = grpc::CreateChannel(kDefaultGrpcServiceAddress, grpc::InsecureChannelCredentials()); + // init the stub here + m_stub = agl_shell_ipc::AglShellManagerService::NewStub(m_channel); + reader = new Reader(m_stub.get()); +} + +void +GrpcClient::WaitForConnected(int wait_time_ms, int tries_timeout) +{ + struct timespec ts; + grpc_connectivity_state state; + int try_ = 0; + 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); - + while (((state = m_channel->GetState(true)) != GRPC_CHANNEL_READY) && + try_++ < tries_timeout) { 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()); } |