summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarius Vlad <marius.vlad@collabora.com>2023-10-24 17:39:45 +0300
committerJan-Simon Moeller <jsmoeller@linuxfoundation.org>2023-11-03 17:46:25 +0000
commit73e82a6f346d2835f6d6b0752629b2d2446e871d (patch)
treec7b533e1eb3b05065527704a06dc9fef2cc24d13
parent53b470c60986fcfc83dc3a5eafcd9370a7264086 (diff)
grpc-proxy: Start the gRPC server and waiting thread much sooner
This change moves a bit the start-up sequence of the gRPC server and when it connects to the compositor. Changing the start-up sequence avoids waiting for the channel to change its state from disconnected to connected, and only wait for the wayland connection to take place. Otherwise, we would wait first for the wayland connection to take place, then wait for the gRPC server to start up and finally wait for the channel to be in connected state, all which would incur a massive waiting time. Moving it a bit early requires to at least verify that we have the proxy side (the wayland connection) is already set-up at that time. Bug-AGL: SPEC-4912 Signed-off-by: Marius Vlad <marius.vlad@collabora.com> Change-Id: Ied88a917df8ff98fefa601103ce04e13c8bb21ac
-rw-r--r--grpc-proxy/grpc-async-cb.cpp49
-rw-r--r--grpc-proxy/grpc-async-cb.h3
-rw-r--r--grpc-proxy/main-grpc.cpp30
3 files changed, 66 insertions, 16 deletions
diff --git a/grpc-proxy/grpc-async-cb.cpp b/grpc-proxy/grpc-async-cb.cpp
index 9cbbb4d..69466e0 100644
--- a/grpc-proxy/grpc-async-cb.cpp
+++ b/grpc-proxy/grpc-async-cb.cpp
@@ -89,6 +89,10 @@ GrpcServiceImpl::ActivateApp(grpc::CallbackServerContext *context,
{
LOG("activating app %s on output %s\n", request->app_id().c_str(),
request->output_name().c_str());
+ if (!m_aglShell) {
+ LOG("m_aglShell not set-up\n");
+ return nullptr;
+ }
m_aglShell->ActivateApp(request->app_id(), request->output_name());
@@ -102,6 +106,11 @@ GrpcServiceImpl::DeactivateApp(grpc::CallbackServerContext *context,
const ::agl_shell_ipc::DeactivateRequest* request,
::agl_shell_ipc::DeactivateResponse* /*response*/)
{
+ if (!m_aglShell) {
+ LOG("m_aglShell not set-up\n");
+ return nullptr;
+ }
+
m_aglShell->DeactivateApp(request->app_id());
grpc::ServerUnaryReactor* reactor = context->DefaultReactor();
@@ -114,6 +123,10 @@ GrpcServiceImpl::SetAppFloat(grpc::CallbackServerContext *context,
const ::agl_shell_ipc::FloatRequest* request,
::agl_shell_ipc::FloatResponse* /* response */)
{
+ if (!m_aglShell) {
+ LOG("m_aglShell not set-up\n");
+ return nullptr;
+ }
m_aglShell->SetAppFloat(request->app_id(),
request->x_pos(), request->y_pos());
@@ -127,6 +140,10 @@ GrpcServiceImpl::SetAppNormal(grpc::CallbackServerContext *context,
const ::agl_shell_ipc::NormalRequest* request,
::agl_shell_ipc::NormalResponse* /* response */)
{
+ if (!m_aglShell) {
+ LOG("m_aglShell not set-up\n");
+ return nullptr;
+ }
m_aglShell->SetAppNormal(request->app_id());
grpc::ServerUnaryReactor* reactor = context->DefaultReactor();
@@ -139,6 +156,10 @@ GrpcServiceImpl::SetAppFullscreen(grpc::CallbackServerContext *context,
const ::agl_shell_ipc::FullscreenRequest* request,
::agl_shell_ipc::FullscreenResponse* /* response */)
{
+ if (!m_aglShell) {
+ LOG("m_aglShell not set-up\n");
+ return nullptr;
+ }
m_aglShell->SetAppFullscreen(request->app_id());
grpc::ServerUnaryReactor* reactor = context->DefaultReactor();
@@ -151,6 +172,10 @@ GrpcServiceImpl::SetAppOnOutput(grpc::CallbackServerContext *context,
const ::agl_shell_ipc::AppOnOutputRequest* request,
::agl_shell_ipc::AppOnOutputResponse* /* response */)
{
+ if (!m_aglShell) {
+ LOG("m_aglShell not set-up\n");
+ return nullptr;
+ }
m_aglShell->SetAppOnOutput(request->app_id(), request->output());
grpc::ServerUnaryReactor* reactor = context->DefaultReactor();
@@ -163,6 +188,10 @@ GrpcServiceImpl::SetAppPosition(grpc::CallbackServerContext *context,
const ::agl_shell_ipc::AppPositionRequest* request,
::agl_shell_ipc::AppPositionResponse* /* response */)
{
+ if (!m_aglShell) {
+ LOG("m_aglShell not set-up\n");
+ return nullptr;
+ }
m_aglShell->SetAppPosition(request->app_id(), request->x(), request->y());
grpc::ServerUnaryReactor* reactor = context->DefaultReactor();
@@ -175,6 +204,10 @@ GrpcServiceImpl::SetAppScale(grpc::CallbackServerContext *context,
const ::agl_shell_ipc::AppScaleRequest* request,
::agl_shell_ipc::AppScaleResponse* /* response */)
{
+ if (!m_aglShell) {
+ LOG("m_aglShell not set-up\n");
+ return nullptr;
+ }
m_aglShell->SetAppScale(request->app_id(),
request->width(), request->height());
@@ -188,6 +221,10 @@ GrpcServiceImpl::SetAppSplit(grpc::CallbackServerContext *context,
const ::agl_shell_ipc::SplitRequest* request,
::agl_shell_ipc::SplitResponse* /*response*/)
{
+ if (!m_aglShell) {
+ LOG("m_aglShell not set-up\n");
+ return nullptr;
+ }
m_aglShell->SetAppSplit(request->app_id(), request->tile_orientation());
grpc::ServerUnaryReactor* reactor = context->DefaultReactor();
@@ -202,6 +239,11 @@ GrpcServiceImpl::GetOutputs(grpc::CallbackServerContext *context,
{
struct window_output *output;
+ if (!m_aglShell) {
+ LOG("m_aglShell not set-up\n");
+ return nullptr;
+ }
+
struct wl_list *list = &m_aglShell->m_shell_data->output_list;
wl_list_for_each(output, list, link) {
auto m_output = response->add_outputs();
@@ -218,8 +260,13 @@ GrpcServiceImpl::AppStatusState(grpc::CallbackServerContext* context,
const ::agl_shell_ipc::AppStateRequest* /*request */)
{
- Lister *n = new Lister(m_aglShell);
+ if (!m_aglShell) {
+ LOG(">> m_aglShell not set-up\n");
+ return nullptr;
+ }
+
+ Lister *n = new Lister(m_aglShell);
m_aglShell->m_shell_data->server_context_list.push_back(std::pair(context, n));
LOG("added lister %p\n", static_cast<void *>(n));
diff --git a/grpc-proxy/grpc-async-cb.h b/grpc-proxy/grpc-async-cb.h
index cb8adcb..342a6df 100644
--- a/grpc-proxy/grpc-async-cb.h
+++ b/grpc-proxy/grpc-async-cb.h
@@ -63,6 +63,7 @@ private:
class GrpcServiceImpl final : public agl_shell_ipc::AglShellManagerService::CallbackService {
public:
GrpcServiceImpl(Shell *aglShell) : m_aglShell(aglShell) {}
+ void setAglShell(Shell *_aglShell) { m_aglShell = _aglShell; }
grpc::ServerUnaryReactor *ActivateApp(grpc::CallbackServerContext *context,
const ::agl_shell_ipc::ActivateRequest* request,
@@ -109,5 +110,5 @@ public:
const ::agl_shell_ipc::AppStateRequest* /*request*/) override;
private:
- Shell *m_aglShell;
+ Shell *m_aglShell = nullptr;
};
diff --git a/grpc-proxy/main-grpc.cpp b/grpc-proxy/main-grpc.cpp
index ea75722..2f9350a 100644
--- a/grpc-proxy/main-grpc.cpp
+++ b/grpc-proxy/main-grpc.cpp
@@ -542,8 +542,19 @@ err:
}
static void
-start_grpc_server(Shell *aglShell)
+start_grpc_server(std::shared_ptr<grpc::Server> server)
{
+ LOG("gRPC server listening\n");
+ server->Wait();
+}
+
+int main(int argc, char **argv)
+{
+ (void) argc;
+ (void) argv;
+ Shell *aglShell = nullptr;
+ int ret = 0;
+
// instantiante the grpc server
std::string server_address(kDefaultGrpcServiceAddress);
GrpcServiceImpl service{aglShell};
@@ -555,18 +566,8 @@ start_grpc_server(Shell *aglShell)
builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
builder.RegisterService(&service);
- std::unique_ptr<grpc::Server> server(builder.BuildAndStart());
- LOG("gRPC server listening on %s\n", server_address.c_str());
-
- server->Wait();
-}
-
-int main(int argc, char **argv)
-{
- (void) argc;
- (void) argv;
- Shell *aglShell;
- int ret = 0;
+ std::shared_ptr<grpc::Server> server(builder.BuildAndStart());
+ std::thread thread(start_grpc_server, server);
// this blocks until we detect that another shell client started
// running
@@ -581,7 +582,8 @@ int main(int argc, char **argv)
std::shared_ptr<struct agl_shell> agl_shell{sh->shell, agl_shell_destroy};
aglShell = new Shell(agl_shell, sh);
- std::thread thread(start_grpc_server, aglShell);
+ // now that we have aglShell, set it to the gRPC proxy as well
+ service.setAglShell(aglShell);
// serve wayland requests
while (running && ret != -1) {