6 #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 "agl_shell.grpc.pb.h"
18 typedef void (*Callback)(agl_shell_ipc::AppStateResponse app_response, void *data);
20 class Reader : public grpc::ClientReadReactor<::agl_shell_ipc::AppStateResponse> {
22 Reader(agl_shell_ipc::AglShellManagerService::Stub *stub)
27 void AppStatusState(Callback callback, void *_data)
29 ::agl_shell_ipc::AppStateRequest request;
31 // set up the callback
32 m_callback = callback;
34 m_stub->async()->AppStatusState(&m_context, &request, this);
36 StartRead(&m_app_state);
40 void OnReadDone(bool ok) override
43 m_callback(m_app_state, m_data);
45 // blocks in StartRead() if the server doesn't send
47 StartRead(&m_app_state);
53 fprintf(stderr, "%s()\n", __func__);
54 std::unique_lock<std::mutex> l(m_mutex);
58 void OnDone(const grpc::Status& s) override
60 fprintf(stderr, "%s()\n", __func__);
61 std::unique_lock<std::mutex> l(m_mutex);
65 fprintf(stderr, "%s() done\n", __func__);
71 std::unique_lock<std::mutex> l(m_mutex);
73 m_cv.wait(l, [this] { return m_done; });
75 return std::move(m_status);
78 grpc::ClientContext m_context;
79 ::agl_shell_ipc::AppStateResponse m_app_state;
81 agl_shell_ipc::AglShellManagerService::Stub *m_stub;
87 std::condition_variable m_cv;
88 grpc::Status m_status;
95 void WaitForConnected(int wait_time_ms, int tries_timeout);
96 bool ActivateApp(const std::string& app_id, const std::string& output_name);
97 bool DeactivateApp(const std::string& app_id);
98 bool SetAppFloat(const std::string& app_id, int32_t x_pos, int32_t y_pos);
99 bool SetAppFullscreen(const std::string& app_id);
100 bool SetAppOnOutput(const std::string& app_id, const std::string& output);
101 bool SetAppNormal(const std::string& app_id);
102 bool SetAppPosition(const std::string& app_id, int32_t x, int32_t y);
103 bool SetAppScale(const std::string& app_id, int32_t width, int32_t height);
104 std::vector<std::string> GetOutputs();
106 void AppStatusState(Callback callback, void *data);
111 std::unique_ptr<agl_shell_ipc::AglShellManagerService::Stub> m_stub;
112 std::shared_ptr<grpc::Channel> m_channel;