summaryrefslogtreecommitdiffstats
path: root/grpc-proxy/main-grpc.h
AgeCommit message (Collapse)AuthorFilesLines
2024-01-02grpc-proxy: Re-work bound_ok/bound_fail events handlingMarius Vlad1-0/+8
This bigger patch changes the way gRPC proxy client connects to the server, more specifically how it binds to the same agl_shell interface as the shell client. I debated if this should be split into more pieces but I think it makes more sense to have contained into a single patch as it doesn't make sense to have some bits off and some bits on, as both the server and the client side need to be changed at the same time. This biggest change with this patch is to avoid a potential race condition between the gRPC proxy client and the shell-client, but also to simplify the way the gRPC client connects to the server as there aren't sufficient guards in the server to the provent various corner cases to take place. Rather than attempting to fix that, simplifying the entire bit and allow only a single agl-shell client and a sigle gRPC proxy client connected at a single time and remove any other potential clients trying to connect at all, later on. Context and usage: Both the gRPC proxy and shell-client bind to the same agl_shell interface, meaning that both use the shell-client (homescreen, flutter-ics-homescreen, flutter-auto, wam) and the gRPC proxy can issue agl_shell requests, with some minor differences -- setting background and panels which do not make sense for gRPC proxy client. The compositor can signal back to clients when a bind was OK or not with the bound_ok/bound_fail event. Previously to adding the bound_ok/bound_fail events, any other client trying to use agl_shell interface, more than once, would get a protocol violation. With the bound_ok/bound_fail events clients would instead receive this event and could theoretically act upon it. The race that this patch tries to overcome is that the gRPC client will periodically attempt to verify if there's a shell-client already connected to server by binding to agl_shell interface and waiting for bound_fail event. In case it got bound_ok, it would disconnect and attempt at latter point in time, until it got the bound_failed event, and thus signalling that there's shell client already connected, allowing to proceed further. This worked fine most of the time, depending on how fast the shell client also bind to agl_shell. For a brief period of time, it might be that shell client also gets a bound_fail, requiring it to retry at a later point in time. The disconnected/reconnect of the gRPC proxy would then complicate matters as the client resources will get overwritten. So rather than trying to try that fix that, a better approach is to simplify the way this works entirely. The change in this patch is that the gRPC proxy doesn't connect/disconnect periodically but rather it waits for the compositor to signal when it is ready to bind to agl_shell interface. That happens with the help of the doas event status, from the agl_shell_ext interface. If this event status is alright (OK) then it means the gRPC can then bind to agl_shell interface. If it gets a failed status it would just wait and then issue another doas request and continue as such forever until it got an alright status. The distinct is that in this case the gRPC proxy would not disconnect and then reconnect retrying the same thing. This change to simplify some of the assumption in server, and client side implementation would just race with the shell client when binding to the agl_shell interface. Bug-AGL: SPEC-4977 Signed-off-by: Marius Vlad <marius.vlad@collabora.com> Change-Id: Ib74f789553d3b130ee8e61d0068e617dc2209a58
2022-12-13grpc-proxy: Init gRPCsandbox/mvlad/grpc-async-cbMarius Vlad1-0/+64
This brings in support for accessing agl-shell protocol indirectly by using a gRPC interface which bridges the communication between a particular client (the client issuing gRPC requests) and the AGL compositor which does that by re-using the same agl-shell protocol. In order to achieve that, and further more, to avoid having ifdefs code in the compositor and deal with threading, we instead resorted to using a helper client. On one side this helper implements the gRPC server API, and on the other, a wayland native client that implements the agl_shell interface. It uses the agl_shell_ext interface added previously to communicate with the compositor that it requires access to agl_shell interface as well. The helper expects that agl_shell interface was already bounded to another client before starting it so it waits until that happens and then it implements the protocol specification, for each interface. Launching the helper client automatically can be done by adding the following entry to the ini file: [shell-client-ext] command=/path/to/agl-shell-grpc-server The gRPC server implementation only handles the agl_shell interface until to this point, specifically, the activate_app request, and the events that were adedd with version 3 of the agl-shell protocol. Also the implementation uses the Reactor pattern, with Callback service that greatly simplifies the async version and avoids putting locks to to handle multiple clients. This should allow multiple clients being connected to the gRPC server and receive events / send requests. Bug-AGL: SPEC-4503 Signed-off-by: Marius Vlad <marius.vlad@collabora.com> Change-Id: Ie870da3caa138394d8dd30f9d22a5552d585d63a