X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=grpc-proxy%2Fmain-grpc.cpp;h=2f9350a01a41d0ea1329f8203410348127120d8b;hb=73e82a6f346d2835f6d6b0752629b2d2446e871d;hp=5b07d647d6e8cdf4daf2613f35783de0f10bcaca;hpb=d8e72099ecbcadc6e8b242686cf012763a5f1a3a;p=src%2Fagl-compositor.git diff --git a/grpc-proxy/main-grpc.cpp b/grpc-proxy/main-grpc.cpp index 5b07d64..2f9350a 100644 --- a/grpc-proxy/main-grpc.cpp +++ b/grpc-proxy/main-grpc.cpp @@ -129,7 +129,7 @@ agl_shell_app_on_output(void *data, struct agl_shell *agl_shell, (void) data; (void) app_id; - LOG("got app_on_output event app_id %s on output\n", app_id, output_name); + LOG("got app_on_output event app_id %s on output %s\n", app_id, output_name); } @@ -386,6 +386,10 @@ __register_shell_init(void) struct shell_data_init *sh = new struct shell_data_init; wl_display = wl_display_connect(NULL); + if (!wl_display) { + ret = -1; + goto err_failed_display; + } registry = wl_display_get_registry(wl_display); sh->wait_for_bound = true; sh->bound_fail = false; @@ -413,6 +417,8 @@ __register_shell_init(void) err: wl_registry_destroy(registry); wl_display_disconnect(wl_display); + +err_failed_display: delete sh; return ret; } @@ -480,6 +486,10 @@ start_agl_shell_client(void) struct shell_data *sh = new struct shell_data; + if (!wl_display) { + goto err; + } + sh->wl_display = wl_display; sh->wait_for_doas = true; sh->wait_for_bound = true; @@ -532,8 +542,19 @@ err: } static void -start_grpc_server(Shell *aglShell) +start_grpc_server(std::shared_ptr 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}; @@ -545,18 +566,8 @@ start_grpc_server(Shell *aglShell) builder.AddListeningPort(server_address, grpc::InsecureServerCredentials()); builder.RegisterService(&service); - std::unique_ptr 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 server(builder.BuildAndStart()); + std::thread thread(start_grpc_server, server); // this blocks until we detect that another shell client started // running @@ -571,7 +582,8 @@ int main(int argc, char **argv) std::shared_ptr 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) {