6 #include <wayland-client-protocol.h>
8 #include "ivi-application-client-protocol.h"
9 #include "ivi-controller-client-protocol.h"
11 #define ASSERT(x) assert(x)
14 struct wl_display *display;
15 struct wl_registry *registry;
16 struct ivi_application *ivi_application;
17 struct ivi_controller *ivi_controller;
23 static int running = 1;
26 controller_event_screen(void *data, struct ivi_controller *ivi_controller,
27 uint32_t id_screen, struct ivi_controller_screen *screen)
33 controller_event_layer(void *data, struct ivi_controller *ivi_controller,
40 controller_event_surface(void *data, struct ivi_controller *ivi_controller,
47 controller_event_error(void *data, struct ivi_controller *ivi_controller,
48 int32_t object_id, int32_t object_type, int32_t error_code,
49 const char *error_text)
51 struct display *d = data;
53 printf("IVISurfaceCreator: receive event [error=%d]\n", error_code);
55 if (object_type == IVI_CONTROLLER_OBJECT_TYPE_SURFACE)
57 d->error_code = error_code;
62 controller_event_native_handle(void *data, struct ivi_controller *ivi_controller,
63 struct wl_surface *surface)
65 struct display *d = data;
67 printf("IVISurfaceCreator: receive event [native_handle]\n");
69 if (d && d->ivi_application)
71 printf("IVISurfaceCreator: create ivi_surface (ID:%u)\n", d->surface_id);
72 ivi_application_surface_create(d->ivi_application,
73 d->surface_id, surface);
75 d->surface_created = 1;
79 static const struct ivi_controller_listener controller_listener = {
80 controller_event_screen,
81 controller_event_layer,
82 controller_event_surface,
83 controller_event_error,
84 controller_event_native_handle
88 registry_handle_global(void *data, struct wl_registry *registry,
89 uint32_t name, const char *interface, uint32_t version)
91 struct display *d = data;
93 if (strcmp(interface, "ivi_application") == 0)
95 d->ivi_application = wl_registry_bind(registry, name,
96 &ivi_application_interface, 1);
98 else if (strcmp(interface, "ivi_controller") == 0)
100 d->ivi_controller = wl_registry_bind(registry, name,
101 &ivi_controller_interface, 1);
102 ivi_controller_add_listener(d->ivi_controller,
103 &controller_listener, data);
108 registry_handle_global_remove(void *data, struct wl_registry *registry,
114 static const struct wl_registry_listener registry_listener = {
115 registry_handle_global,
116 registry_handle_global_remove
120 signal_action(int signum)
128 fprintf(stderr, "Usage: IVISurfaceCreator <Process ID> <Window Title> <IVI-Surface ID>\n");
133 main(int argc, char **argv)
135 struct display display = {0};
136 struct sigaction sigact;
143 int32_t process_id = atoi(argv[1]);
144 char * window_title = NULL;
145 char * endptr = NULL;
146 display.surface_id = strtoul(argv[3], &endptr, 0);
148 if (strlen(argv[2]) > 0)
150 window_title = strdup(argv[2]);
153 sigact.sa_handler = signal_action;
154 sigemptyset(&sigact.sa_mask);
155 sigact.sa_flags = SA_RESETHAND;
156 sigaction(SIGINT, &sigact, NULL);
158 display.display = wl_display_connect(NULL);
159 ASSERT(display.display);
161 display.registry = wl_display_get_registry(display.display);
162 wl_registry_add_listener(display.registry,
163 ®istry_listener, &display);
165 wl_display_dispatch(display.display);
167 ASSERT(display.ivi_application &&
168 display.ivi_controller);
173 ivi_controller_get_native_handle(display.ivi_controller,
177 wl_display_roundtrip(display.display);
179 while (!display.error_code && running && (rc != -1))
181 rc = wl_display_dispatch(display.display);
184 if (display.error_code == IVI_CONTROLLER_ERROR_CODE_NATIVE_HANDLE_END)
186 if (display.surface_created){
190 printf("IVISurfaceCreator: Search of native handle was ended.\n"
191 " But no surface was created.\n"
192 " Retry get_native_handle.\n");
193 display.error_code = 0;
198 } while ((++retry_count < 10) && running);
200 wl_display_roundtrip(display.display);
202 printf("IVISurfaceCreator: exit\n");
204 wl_registry_destroy(display.registry);
205 wl_display_flush(display.display);
206 wl_display_disconnect(display.display);