LINUX.ORG.RU

wayland server имплементация, создание глобальных объектов

 ,


1

3

В ходе соединения ничего не происходит.

Как сделать так чтобы вызывалась wl_output_handle_bind() из wl_output_interface по запросу на биндинг от клиента?

wl_global_create() шаблон исходя из /usr/include/wayland-server-core.h это:

struct wl_global *
wl_global_create(struct wl_display *display,
         const struct wl_interface *interface,
         int version,
         void *data, wl_global_bind_func_t bind);

Текущий вывод приложения таков:

client
  info: wl_output
  info: binding
server
  unable to lock lockfile /run/user/1000/wayland-0.lock, maybe another compositor is running
  running wayland display on wayland-1

Код серверной реализации:

// server.c
#include <stdlib.h>
#include <stdio.h>
#include <wayland-server.h>

struct server_state { void *data; };
struct composed_output { struct server_state *state; struct wl_resource *resource; };
// resource_container_flush () ..
// resource_container_add () ..

static void wl_output_handle_resource_destroy (struct wl_resource *resource) {
  struct composed_output *client_output = wl_resource_get_user_data (resource);
  // to do: clean up global{,s} resourcing
  // resource_container_flush (client_output->state->data, client_output);
}

static void wl_output_handle_release (struct wl_client *client,
                                      struct wl_resource *resource) {
  printf ("info: release event handler: processing global remove event\n");
  wl_resource_destroy (resource);
}

static const struct wl_output_interface wl_output_implementation = {
  .release = wl_output_handle_release,
};

static void wl_output_handle_bind (struct wl_client *client,
                                   void *data,
                                   uint32_t version, uint32_t id) {
  struct server_state *state = data;
  struct composed_output *client_output = calloc (1, sizeof (struct composed_output));
  printf ("info: binding event handler\n");
}

int main (int argc, char *argv[]) {
  struct wl_display *display = wl_display_create ();
  if (!display) {
    fprintf (stderr, "unable to create wayland display\n");
    return 1;
  }
  
  const char *socket = wl_display_add_socket_auto (display);
  if (!socket) {
    fprintf (stderr, "unable to add socket to wayland display\n");
    return 1;
  }
  
  struct server_state state = { .data = NULL };
  
  wl_global_create (display, &wl_output_interface,
                    1, &state, wl_output_handle_bind);
  
  fprintf (stderr, "running wayland display on %s\n", socket);
  wl_display_run (display);
  
  wl_display_destroy (display);
  return 0;
}

Код клиентской реализации:

// client.c
#include <stdint.h>
#include <stdio.h>
#include <wayland-client.h>

static void registry_handle_global (void *data,
                                    struct wl_registry *registry,
                                    uint32_t name,
                                    const char *interface,
                                    uint32_t version) {
  printf ("info: %s\n", interface);
  if (strcmp (interface, wl_output_interface.name) == 0) {
    printf ("info: binding\n");
    wl_registry_bind (registry, name, &wl_output_interface, 1);
  }
}

static void registry_handle_global_remove (void *data,
                                           struct wl_registry *registry,
                                           uint32_t name) {
  // this function implementation from handle is blank in this exercise
}

static const struct wl_registry_listener registry_listener = {
  .global = registry_handle_global,
  .global_remove = registry_handle_global_remove,
};

int main (int argc, char *argv[]) {
  struct wl_display *display = wl_display_connect ("wayland-1");
  struct wl_registry *registry = wl_display_get_registry (display);
  if (display == NULL) { fprintf (stderr, "can't connect to display\n"); return 1; }
  if (registry == NULL) { fprintf (stderr, "can't connect to registry\n"); return 1; }
  wl_registry_add_listener (registry, &registry_listener, NULL);
  wl_display_roundtrip (display);
  return 0;
}

Отладочный лог (в т.ч. и через coredump значения те же):

 export WAYLAND_DEBUG=1; ./server
unable to lock lockfile /run/user/1000/wayland-0.lock, maybe another compositor is running
running wayland display on wayland-1
[1960331.814] wl_display@1.get_registry(new id wl_registry@2)
[1960331.839]  -> wl_registry@2.global(1, "wl_output", 3)
[1960331.860] wl_display@1.sync(new id wl_callback@3)
[1960331.866]  -> wl_callback@3.done(0)
[1960331.871]  -> wl_display@1.delete_id(3)
[1960331.946] wl_registry@2.bind(1, "wl_output", 3, new id [unknown]@4)
info: wl_output binding event handler; interface version: 3
zsh: segmentation fault (core dumped)  ./server

Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.