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 LOG("m_aglShell not set-up\n");
97 m_aglShell->ActivateApp(request->app_id(), request->output_name());
99 grpc::ServerUnaryReactor* reactor = context->DefaultReactor();
100 reactor->Finish(grpc::Status::OK);
104 grpc::ServerUnaryReactor *
105 GrpcServiceImpl::DeactivateApp(grpc::CallbackServerContext *context,
106 const ::agl_shell_ipc::DeactivateRequest* request,
107 ::agl_shell_ipc::DeactivateResponse* /*response*/)
110 LOG("m_aglShell not set-up\n");
114 m_aglShell->DeactivateApp(request->app_id());
116 grpc::ServerUnaryReactor* reactor = context->DefaultReactor();
117 reactor->Finish(grpc::Status::OK);
121 grpc::ServerUnaryReactor *
122 GrpcServiceImpl::SetAppFloat(grpc::CallbackServerContext *context,
123 const ::agl_shell_ipc::FloatRequest* request,
124 ::agl_shell_ipc::FloatResponse* /* response */)
127 LOG("m_aglShell not set-up\n");
130 m_aglShell->SetAppFloat(request->app_id(),
131 request->x_pos(), request->y_pos());
133 grpc::ServerUnaryReactor* reactor = context->DefaultReactor();
134 reactor->Finish(grpc::Status::OK);
138 grpc::ServerUnaryReactor *
139 GrpcServiceImpl::SetAppNormal(grpc::CallbackServerContext *context,
140 const ::agl_shell_ipc::NormalRequest* request,
141 ::agl_shell_ipc::NormalResponse* /* response */)
144 LOG("m_aglShell not set-up\n");
147 m_aglShell->SetAppNormal(request->app_id());
149 grpc::ServerUnaryReactor* reactor = context->DefaultReactor();
150 reactor->Finish(grpc::Status::OK);
154 grpc::ServerUnaryReactor *
155 GrpcServiceImpl::SetAppFullscreen(grpc::CallbackServerContext *context,
156 const ::agl_shell_ipc::FullscreenRequest* request,
157 ::agl_shell_ipc::FullscreenResponse* /* response */)
160 LOG("m_aglShell not set-up\n");
163 m_aglShell->SetAppFullscreen(request->app_id());
165 grpc::ServerUnaryReactor* reactor = context->DefaultReactor();
166 reactor->Finish(grpc::Status::OK);
170 grpc::ServerUnaryReactor *
171 GrpcServiceImpl::SetAppOnOutput(grpc::CallbackServerContext *context,
172 const ::agl_shell_ipc::AppOnOutputRequest* request,
173 ::agl_shell_ipc::AppOnOutputResponse* /* response */)
176 LOG("m_aglShell not set-up\n");
179 m_aglShell->SetAppOnOutput(request->app_id(), request->output());
181 grpc::ServerUnaryReactor* reactor = context->DefaultReactor();
182 reactor->Finish(grpc::Status::OK);
186 grpc::ServerUnaryReactor *
187 GrpcServiceImpl::SetAppPosition(grpc::CallbackServerContext *context,
188 const ::agl_shell_ipc::AppPositionRequest* request,
189 ::agl_shell_ipc::AppPositionResponse* /* response */)
192 LOG("m_aglShell not set-up\n");
195 m_aglShell->SetAppPosition(request->app_id(), request->x(), request->y());
197 grpc::ServerUnaryReactor* reactor = context->DefaultReactor();
198 reactor->Finish(grpc::Status::OK);
202 grpc::ServerUnaryReactor *
203 GrpcServiceImpl::SetAppScale(grpc::CallbackServerContext *context,
204 const ::agl_shell_ipc::AppScaleRequest* request,
205 ::agl_shell_ipc::AppScaleResponse* /* response */)
208 LOG("m_aglShell not set-up\n");
211 m_aglShell->SetAppScale(request->app_id(),
212 request->width(), request->height());
214 grpc::ServerUnaryReactor* reactor = context->DefaultReactor();
215 reactor->Finish(grpc::Status::OK);
219 grpc::ServerUnaryReactor *
220 GrpcServiceImpl::SetAppSplit(grpc::CallbackServerContext *context,
221 const ::agl_shell_ipc::SplitRequest* request,
222 ::agl_shell_ipc::SplitResponse* /*response*/)
225 LOG("m_aglShell not set-up\n");
228 m_aglShell->SetAppSplit(request->app_id(), request->tile_orientation(),
229 request->width(), request->sticky(),
230 request->output_name());
232 grpc::ServerUnaryReactor* reactor = context->DefaultReactor();
233 reactor->Finish(grpc::Status::OK);
237 grpc::ServerUnaryReactor *
238 GrpcServiceImpl::GetOutputs(grpc::CallbackServerContext *context,
239 const ::agl_shell_ipc::OutputRequest* /* request */,
240 ::agl_shell_ipc::ListOutputResponse* response)
242 struct window_output *output;
245 LOG("m_aglShell not set-up\n");
249 struct wl_list *list = &m_aglShell->m_shell_data->output_list;
250 wl_list_for_each(output, list, link) {
251 auto m_output = response->add_outputs();
252 m_output->set_name(output->name);
255 grpc::ServerUnaryReactor* reactor = context->DefaultReactor();
256 reactor->Finish(grpc::Status::OK);
260 grpc::ServerWriteReactor<::agl_shell_ipc::AppStateResponse>*
261 GrpcServiceImpl::AppStatusState(grpc::CallbackServerContext* context,
262 const ::agl_shell_ipc::AppStateRequest* /*request */)
267 LOG(">> m_aglShell not set-up\n");
271 Lister *n = new Lister(m_aglShell);
272 m_aglShell->m_shell_data->server_context_list.push_back(std::pair(context, n));
273 LOG("added lister %p\n", static_cast<void *>(n));
275 // just return a Lister to keep the channel open