2 * Copyright © 2022, 2023 Collabora, Ltd.
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 #define GRPC_CALLBACK_API_NONEXPERIMENTAL
33 #include <grpc/grpc.h>
34 #include <grpcpp/grpcpp.h>
35 #include <grpcpp/server.h>
36 #include <grpcpp/server_builder.h>
37 #include <grpcpp/server_context.h>
39 #include <grpcpp/ext/proto_server_reflection_plugin.h>
40 #include <grpcpp/health_check_service_interface.h>
43 #include "agl_shell.grpc.pb.h"
44 #include "grpc-async-cb.h"
46 Lister::Lister(Shell *shell) : m_shell(shell)
48 // don't call NextWrite() just yet we do it explicitly when getting
49 // the events from the compositor
59 void Lister::OnWriteDone(bool ok)
61 LOG("got ok %d\n", ok);
63 LOG("done writting %d\n", m_writting);
69 Lister::NextWrite(void)
72 LOG(">>>>> still in writting\n");
76 StartWrite(&m_shell->m_shell_data->current_app_state);
80 Lister::Writting(void)
85 grpc::ServerUnaryReactor *
86 GrpcServiceImpl::ActivateApp(grpc::CallbackServerContext *context,
87 const ::agl_shell_ipc::ActivateRequest* request,
88 ::agl_shell_ipc::ActivateResponse* /*response*/)
90 LOG("activating app %s on output %s\n", request->app_id().c_str(),
91 request->output_name().c_str());
93 m_aglShell->ActivateApp(request->app_id(), request->output_name());
95 grpc::ServerUnaryReactor* reactor = context->DefaultReactor();
96 reactor->Finish(grpc::Status::OK);
100 grpc::ServerUnaryReactor *
101 GrpcServiceImpl::DeactivateApp(grpc::CallbackServerContext *context,
102 const ::agl_shell_ipc::DeactivateRequest* request,
103 ::agl_shell_ipc::DeactivateResponse* /*response*/)
105 m_aglShell->DeactivateApp(request->app_id());
107 grpc::ServerUnaryReactor* reactor = context->DefaultReactor();
108 reactor->Finish(grpc::Status::OK);
112 grpc::ServerUnaryReactor *
113 GrpcServiceImpl::SetAppFloat(grpc::CallbackServerContext *context,
114 const ::agl_shell_ipc::FloatRequest* request,
115 ::agl_shell_ipc::FloatResponse* /* response */)
117 m_aglShell->SetAppFloat(request->app_id(),
118 request->x_pos(), request->y_pos());
120 grpc::ServerUnaryReactor* reactor = context->DefaultReactor();
121 reactor->Finish(grpc::Status::OK);
125 grpc::ServerUnaryReactor *
126 GrpcServiceImpl::SetAppNormal(grpc::CallbackServerContext *context,
127 const ::agl_shell_ipc::NormalRequest* request,
128 ::agl_shell_ipc::NormalResponse* /* response */)
130 m_aglShell->SetAppNormal(request->app_id());
132 grpc::ServerUnaryReactor* reactor = context->DefaultReactor();
133 reactor->Finish(grpc::Status::OK);
137 grpc::ServerUnaryReactor *
138 GrpcServiceImpl::SetAppFullscreen(grpc::CallbackServerContext *context,
139 const ::agl_shell_ipc::FullscreenRequest* request,
140 ::agl_shell_ipc::FullscreenResponse* /* response */)
142 m_aglShell->SetAppFullscreen(request->app_id());
144 grpc::ServerUnaryReactor* reactor = context->DefaultReactor();
145 reactor->Finish(grpc::Status::OK);
149 grpc::ServerUnaryReactor *
150 GrpcServiceImpl::SetAppOnOutput(grpc::CallbackServerContext *context,
151 const ::agl_shell_ipc::AppOnOutputRequest* request,
152 ::agl_shell_ipc::AppOnOutputResponse* /* response */)
154 m_aglShell->SetAppOnOutput(request->app_id(), request->output());
156 grpc::ServerUnaryReactor* reactor = context->DefaultReactor();
157 reactor->Finish(grpc::Status::OK);
161 grpc::ServerUnaryReactor *
162 GrpcServiceImpl::SetAppPosition(grpc::CallbackServerContext *context,
163 const ::agl_shell_ipc::AppPositionRequest* request,
164 ::agl_shell_ipc::AppPositionResponse* /* response */)
166 m_aglShell->SetAppPosition(request->app_id(), request->x(), request->y());
168 grpc::ServerUnaryReactor* reactor = context->DefaultReactor();
169 reactor->Finish(grpc::Status::OK);
173 grpc::ServerUnaryReactor *
174 GrpcServiceImpl::SetAppScale(grpc::CallbackServerContext *context,
175 const ::agl_shell_ipc::AppScaleRequest* request,
176 ::agl_shell_ipc::AppScaleResponse* /* response */)
178 m_aglShell->SetAppScale(request->app_id(),
179 request->width(), request->height());
181 grpc::ServerUnaryReactor* reactor = context->DefaultReactor();
182 reactor->Finish(grpc::Status::OK);
186 grpc::ServerUnaryReactor *
187 GrpcServiceImpl::SetAppSplit(grpc::CallbackServerContext *context,
188 const ::agl_shell_ipc::SplitRequest* request,
189 ::agl_shell_ipc::SplitResponse* /*response*/)
191 m_aglShell->SetAppSplit(request->app_id(), request->tile_orientation());
193 grpc::ServerUnaryReactor* reactor = context->DefaultReactor();
194 reactor->Finish(grpc::Status::OK);
198 grpc::ServerUnaryReactor *
199 GrpcServiceImpl::GetOutputs(grpc::CallbackServerContext *context,
200 const ::agl_shell_ipc::OutputRequest* /* request */,
201 ::agl_shell_ipc::ListOutputResponse* response)
203 struct window_output *output;
205 struct wl_list *list = &m_aglShell->m_shell_data->output_list;
206 wl_list_for_each(output, list, link) {
207 auto m_output = response->add_outputs();
208 m_output->set_name(output->name);
211 grpc::ServerUnaryReactor* reactor = context->DefaultReactor();
212 reactor->Finish(grpc::Status::OK);
216 grpc::ServerWriteReactor<::agl_shell_ipc::AppStateResponse>*
217 GrpcServiceImpl::AppStatusState(grpc::CallbackServerContext* context,
218 const ::agl_shell_ipc::AppStateRequest* /*request */)
221 Lister *n = new Lister(m_aglShell);
223 m_aglShell->m_shell_data->server_context_list.push_back(std::pair(context, n));
224 LOG("added lister %p\n", static_cast<void *>(n));
226 // just return a Lister to keep the channel open