X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=homescreen%2Fsrc%2FAglShellGrpcClient.cpp;h=f3c72ca923a0a9db72e74683565a9c99619e2264;hb=b2c08ec4a30e5acf3cb1851f71bda88bc542f7d1;hp=6f4ff24ae5cb32d6d735af76b3d3c613fa553a38;hpb=36e2c9697e431414ae0263635f3ebf1f3c200723;p=apps%2Fhomescreen.git diff --git a/homescreen/src/AglShellGrpcClient.cpp b/homescreen/src/AglShellGrpcClient.cpp index 6f4ff24..f3c72ca 100644 --- a/homescreen/src/AglShellGrpcClient.cpp +++ b/homescreen/src/AglShellGrpcClient.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -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,14 +25,33 @@ namespace { GrpcClient::GrpcClient() { - auto channel = grpc::CreateChannel(kDefaultGrpcServiceAddress, + m_channel = grpc::CreateChannel(kDefaultGrpcServiceAddress, grpc::InsecureChannelCredentials()); // init the stub here - m_stub = agl_shell_ipc::AglShellManagerService::NewStub(channel); + 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 + + 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); + } + +} + bool GrpcClient::ActivateApp(const std::string& app_id, const std::string& output_name) @@ -159,9 +182,9 @@ GrpcClient::Wait(void) } void -GrpcClient::AppStatusState(Callback callback) +GrpcClient::AppStatusState(Callback callback, void *data) { - reader->AppStatusState(callback); + reader->AppStatusState(callback, data); } std::vector