Add gitlab issue/merge request templates
[apps/homescreen.git] / homescreen / src / AglShellGrpcClient.cpp
index 6f4ff24..f3c72ca 100644 (file)
@@ -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,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<std::string>