aboutsummaryrefslogtreecommitdiffstats
path: root/src/wth-receiver-comm.c
diff options
context:
space:
mode:
authorMarius Vlad <marius.vlad@collabora.com>2020-11-02 16:51:08 +0200
committerMarius Vlad <marius.vlad@collabora.com>2020-12-01 13:07:57 +0200
commit8fcbed84cfefcfe648584941587e6d06abf59c3e (patch)
tree4a370a19465e12543e74563fc136cf916554ca6f /src/wth-receiver-comm.c
parent2373db4b31a646d4936f6700ecc2af857302444b (diff)
wth-receiver: Handle events from the remote side and from the local compositor
With this, we fork and let the child deal with the gstreamer pipeline while the parent is still able to process events from the transimtter. Using blocking dispatching function will make the main loop be stuck in processing events without being able to dispatch any handlers that might be due to the requests from the transmistter side. So in order to allow the mainloop (still) handle the events, we fork and let child deal with the gstreamer pipeline. Bug-AGL: SPEC-3675 Signed-off-by: Marius Vlad <marius.vlad@collabora.com> Change-Id: I50e1d49b55849dc32f611538bad2ce1c676c9a97
Diffstat (limited to 'src/wth-receiver-comm.c')
-rw-r--r--src/wth-receiver-comm.c60
1 files changed, 40 insertions, 20 deletions
diff --git a/src/wth-receiver-comm.c b/src/wth-receiver-comm.c
index e6c0266..0527ecd 100644
--- a/src/wth-receiver-comm.c
+++ b/src/wth-receiver-comm.c
@@ -34,12 +34,16 @@
** **
** **
*******************************************************************************/
+#include <sys/types.h>
+#include <signal.h>
#include "wth-receiver-comm.h"
#include "wth-receiver-surface.h"
#include "wth-receiver-seat.h"
#include "wth-receiver-buffer.h"
+#include <waltham-util.h>
+
extern uint16_t tcp_port;
extern const char *my_app_id;
@@ -59,9 +63,17 @@ static void
wthp_ivi_surface_destroy(struct wthp_ivi_surface * ivi_surface)
{
struct ivisurface *ivisurf = wth_object_get_user_data((struct wth_object *)ivi_surface);
-
- if (ivisurf->surf->ivi_app_id)
- free(ivisurf->surf->ivi_app_id);
+ struct client *client = ivisurf->appid->client;
+
+ if (client) {
+ client->pid_destroying = true;
+ fprintf(stdout, "client pid_destroying to true for client %p pid %d\n",
+ client, client->pid);
+ if (kill(client->pid, SIGINT) < 0) {
+ fprintf(stderr, "Failed to send SIGINT to child %d\n",
+ client->pid);
+ }
+ }
free(ivisurf);
}
@@ -80,34 +92,42 @@ wthp_ivi_app_id_surface_create(struct wthp_ivi_app_id *ivi_application,
struct wthp_surface * wthp_surface,
struct wthp_ivi_surface *obj)
{
- struct surface *surface = wth_object_get_user_data((struct wth_object *)wthp_surface);
-
- /* we destroy it wthp_ivi_surface_implementation:: */
- if (my_app_id) {
- surface->ivi_app_id = strdup(my_app_id);
- surface->shm_window->app_id = surface->ivi_app_id;
- }
-
- struct ivisurface *ivisurf;
+ struct surface *surface =
+ wth_object_get_user_data((struct wth_object *)wthp_surface);
+ struct application_id *appid =
+ wth_object_get_user_data((struct wth_object *) ivi_application);
+ pid_t cpid;
- ivisurf = zalloc(sizeof *ivisurf);
+ struct ivisurface *ivisurf = zalloc(sizeof *ivisurf);
if (!ivisurf) {
return;
}
ivisurf->obj = obj;
ivisurf->surf = surface;
+ ivisurf->appid = appid;
wthp_ivi_surface_set_interface(obj,
&wthp_ivi_surface_implementation, ivisurf);
- if (my_app_id)
- wth_receiver_weston_main(surface->shm_window, my_app_id, tcp_port);
- else
- wth_receiver_weston_main(surface->shm_window, app_id, tcp_port);
+ cpid = fork();
+ if (cpid == -1) {
+ fprintf(stderr, "Failed to fork()\n");
+ exit(EXIT_FAILURE);
+ }
+
+ if (cpid == 0) {
+ if (my_app_id)
+ wth_receiver_weston_main(surface->shm_window, my_app_id, tcp_port);
+ else
+ wth_receiver_weston_main(surface->shm_window, app_id, tcp_port);
+ } else {
+ /* this is parent, in wthp_ivi_surface_destroy() we mark that the
+ * client should be waited for so wait4() will be blocked.
+ */
+ appid->client->pid = cpid;
+ }
- while (!surface->shm_window->ready)
- usleep(1);
}
static const struct wthp_ivi_app_id_interface wthp_ivi_app_id_implementation = {
@@ -387,6 +407,7 @@ client_create(struct receiver *srv, struct wth_connection *conn)
disp = wth_connection_get_display(c->connection);
wth_display_set_interface(disp, &display_implementation, c);
+ fprintf(stdout, "Client %p created\n", c);
return c;
}
@@ -444,7 +465,6 @@ receiver_accept_client(struct receiver *srv)
wth_error("Failed to accept a connection.\n");
return;
}
-
client = client_create(srv, conn);
if (!client) {
wth_error("Failed client_create().\n");