5 #include <condition_variable>
8 #include <grpcpp/grpcpp.h>
9 #include <grpcpp/server.h>
10 #include <grpcpp/server_builder.h>
11 #include <grpcpp/server_context.h>
13 #include <grpcpp/ext/proto_server_reflection_plugin.h>
14 #include <grpcpp/health_check_service_interface.h>
16 #include "AglShellGrpcClient.h"
17 #include "agl_shell.grpc.pb.h"
19 using namespace std::chrono;
22 const char kDefaultGrpcServiceAddress[] = "127.0.0.1:14005";
25 GrpcClient::GrpcClient()
27 m_channel = grpc::CreateChannel(kDefaultGrpcServiceAddress,
28 grpc::InsecureChannelCredentials());
31 m_stub = agl_shell_ipc::AglShellManagerService::NewStub(m_channel);
32 reader = new Reader(m_stub.get());
36 GrpcClient::WaitForConnected(int wait_time_ms, int tries_timeout)
39 grpc_connectivity_state state;
42 clock_gettime(CLOCK_MONOTONIC, &ts);
44 ts.tv_nsec = 500 * 1000 * 1000; // 500ms
46 while (((state = m_channel->GetState(true)) != GRPC_CHANNEL_READY) &&
47 try_++ < tries_timeout) {
48 fprintf(stderr, "waiting for channel state to be ready, current state %d", state);
56 GrpcClient::ActivateApp(const std::string& app_id, const std::string& output_name)
58 agl_shell_ipc::ActivateRequest request;
60 request.set_app_id(app_id);
61 request.set_output_name(output_name);
63 grpc::ClientContext context;
64 ::agl_shell_ipc::ActivateResponse reply;
66 grpc::Status status = m_stub->ActivateApp(&context, request, &reply);
71 GrpcClient::DeactivateApp(const std::string& app_id)
73 agl_shell_ipc::DeactivateRequest request;
75 request.set_app_id(app_id);
77 grpc::ClientContext context;
78 ::agl_shell_ipc::DeactivateResponse reply;
80 grpc::Status status = m_stub->DeactivateApp(&context, request, &reply);
85 GrpcClient::SetAppFloat(const std::string& app_id, int32_t x_pos, int32_t y_pos)
87 agl_shell_ipc::FloatRequest request;
89 request.set_app_id(app_id);
91 request.set_x_pos(x_pos);
92 request.set_y_pos(y_pos);
94 grpc::ClientContext context;
95 ::agl_shell_ipc::FloatResponse reply;
97 grpc::Status status = m_stub->SetAppFloat(&context, request, &reply);
102 GrpcClient::SetAppNormal(const std::string& app_id)
104 agl_shell_ipc::NormalRequest request;
106 request.set_app_id(app_id);
108 grpc::ClientContext context;
109 ::agl_shell_ipc::NormalResponse reply;
111 grpc::Status status = m_stub->SetAppNormal(&context, request, &reply);
116 GrpcClient::SetAppFullscreen(const std::string& app_id)
118 agl_shell_ipc::FullscreenRequest request;
120 request.set_app_id(app_id);
122 grpc::ClientContext context;
123 ::agl_shell_ipc::FullscreenResponse reply;
125 grpc::Status status = m_stub->SetAppFullscreen(&context, request, &reply);
130 GrpcClient::SetAppOnOutput(const std::string& app_id, const std::string &output)
132 agl_shell_ipc::AppOnOutputRequest request;
134 request.set_app_id(app_id);
135 request.set_output(output);
137 grpc::ClientContext context;
138 ::agl_shell_ipc::AppOnOutputResponse reply;
140 grpc::Status status = m_stub->SetAppOnOutput(&context, request, &reply);
145 GrpcClient::SetAppPosition(const std::string& app_id, int32_t x, int32_t y)
147 agl_shell_ipc::AppPositionRequest request;
149 request.set_app_id(app_id);
153 grpc::ClientContext context;
154 ::agl_shell_ipc::AppPositionResponse reply;
156 grpc::Status status = m_stub->SetAppPosition(&context, request, &reply);
161 GrpcClient::SetAppScale(const std::string& app_id, int32_t width, int32_t height)
163 agl_shell_ipc::AppScaleRequest request;
165 request.set_app_id(app_id);
166 request.set_width(width);
167 request.set_height(height);
169 grpc::ClientContext context;
170 ::agl_shell_ipc::AppScaleResponse reply;
172 grpc::Status status = m_stub->SetAppScale(&context, request, &reply);
178 GrpcClient::Wait(void)
180 return reader->Await();
184 GrpcClient::AppStatusState(Callback callback, void *data)
186 reader->AppStatusState(callback, data);
189 std::vector<std::string>
190 GrpcClient::GetOutputs()
192 grpc::ClientContext context;
193 std::vector<std::string> v;
195 ::agl_shell_ipc::OutputRequest request;
196 ::agl_shell_ipc::ListOutputResponse response;
198 grpc::Status status = m_stub->GetOutputs(&context, request, &response);
200 return std::vector<std::string>();
202 for (int i = 0; i < response.outputs_size(); i++) {
203 ::agl_shell_ipc::OutputResponse rresponse = response.outputs(i);
204 v.push_back(rresponse.name());