From 667fa186b463fe2016cda485ea8322b585a74513 Mon Sep 17 00:00:00 2001 From: Maniraj Devadoss Date: Tue, 23 Jan 2018 20:04:14 +0530 Subject: simple-weston-client: use the weston-debug protocol to print the weston-debug logs to the stdout, user desired debug-scopes are read from weston-ini thorugh ivi-controller. Signed-off-by: Maniraj Devadoss --- .../simple-weston-client/CMakeLists.txt | 45 ++++++- .../src/simple-weston-client.c | 148 +++++++++++++++++++++ 2 files changed, 192 insertions(+), 1 deletion(-) diff --git a/ivi-layermanagement-examples/simple-weston-client/CMakeLists.txt b/ivi-layermanagement-examples/simple-weston-client/CMakeLists.txt index 8a29d96..420c513 100644 --- a/ivi-layermanagement-examples/simple-weston-client/CMakeLists.txt +++ b/ivi-layermanagement-examples/simple-weston-client/CMakeLists.txt @@ -22,6 +22,15 @@ project (simple-weston-client) find_package(PkgConfig) pkg_check_modules(WAYLAND_CLIENT wayland-client REQUIRED) pkg_check_modules(WAYLAND_CURSOR wayland-cursor REQUIRED) +pkg_check_modules(LIBWESTON_PROTOCOLS libweston-2-protocols QUIET) + +if(${LIBWESTON_PROTOCOLS_FOUND}) + #import the pkgdatadir from libweston-protocols pkgconfig file + execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=pkgdatadir libweston-2-protocols + OUTPUT_VARIABLE WestonProtocols_PKGDATADIR) + string(REGEX REPLACE "[\r\n]" "" WestonProtocols_PKGDATADIR "${WestonProtocols_PKGDATADIR}") + SET(LIBWESTON_PROTOCOLS_PKGDATADIR ${WestonProtocols_PKGDATADIR}) +endif(${LIBWESTON_PROTOCOLS_FOUND}) find_program(WAYLAND_SCANNER_EXECUTABLE NAMES wayland-scanner) @@ -41,6 +50,32 @@ add_custom_command( DEPENDS ${CMAKE_SOURCE_DIR}/protocol/ivi-application.xml ) +if(${LIBWESTON_PROTOCOLS_FOUND}) + add_custom_command( + OUTPUT weston-debug-client-protocol.h + COMMAND ${WAYLAND_SCANNER_EXECUTABLE} client-header + < ${LIBWESTON_PROTOCOLS_PKGDATADIR}/weston-debug.xml + > ${CMAKE_CURRENT_BINARY_DIR}/weston-debug-client-protocol.h + DEPENDS ${LIBWESTON_PROTOCOLS_PKGDATADIR}/weston-debug.xml + ) + + add_custom_command( + OUTPUT weston-debug-server-protocol.h + COMMAND ${WAYLAND_SCANNER_EXECUTABLE} server-header + < ${LIBWESTON_PROTOCOLS_PKGDATADIR}/weston-debug.xml + > ${CMAKE_CURRENT_BINARY_DIR}/weston-debug-server-protocol.h + DEPENDS ${LIBWESTON_PROTOCOLS_PKGDATADIR}/weston-debug.xml + ) + + add_custom_command( + OUTPUT weston-debug-protocol.c + COMMAND ${WAYLAND_SCANNER_EXECUTABLE} code + < ${LIBWESTON_PROTOCOLS_PKGDATADIR}/weston-debug.xml + > ${CMAKE_CURRENT_BINARY_DIR}/weston-debug-protocol.c + DEPENDS ${LIBWESTON_PROTOCOLS_PKGDATADIR}/weston-debug.xml + ) +endif(${LIBWESTON_PROTOCOLS_FOUND}) + include_directories( ${WAYLAND_CLIENT_INCLUDE_DIR} ${WAYLAND_CURSOR_INCLUDE_DIR} @@ -63,7 +98,15 @@ SET(SRC_FILES ivi-application-client-protocol.h ) -add_executable(${PROJECT_NAME} ${SRC_FILES}) +if(${LIBWESTON_PROTOCOLS_FOUND}) + SET(WESTON_DEBUG_SRC_FILES + ${CMAKE_CURRENT_BINARY_DIR}/weston-debug-protocol.c + ${CMAKE_CURRENT_BINARY_DIR}/weston-debug-client-protocol.h + ${CMAKE_CURRENT_BINARY_DIR}/weston-debug-server-protocol.h +) +endif(${LIBWESTON_PROTOCOLS_FOUND}) + +add_executable(${PROJECT_NAME} ${SRC_FILES} ${WESTON_DEBUG_SRC_FILES}) add_dependencies(${PROJECT_NAME} ${LIBS}) diff --git a/ivi-layermanagement-examples/simple-weston-client/src/simple-weston-client.c b/ivi-layermanagement-examples/simple-weston-client/src/simple-weston-client.c index 5b2c960..e101bf4 100644 --- a/ivi-layermanagement-examples/simple-weston-client/src/simple-weston-client.c +++ b/ivi-layermanagement-examples/simple-weston-client/src/simple-weston-client.c @@ -27,10 +27,17 @@ #include #include #include +#include #include #include +#include "weston-debug-client-protocol.h" + +#ifndef MIN +#define MIN(x,y) (((x) < (y)) ? (x) : (y)) +#endif + typedef struct _BkGndSettings { uint32_t surface_id; @@ -45,6 +52,7 @@ typedef struct _WaylandContext { struct wl_compositor *wl_compositor; struct wl_shm *wl_shm; struct wl_seat *wl_seat; + struct weston_debug_v1 *debug_iface; struct wl_pointer *wl_pointer; struct wl_surface *wl_pointer_surface; struct ivi_application *ivi_application; @@ -56,8 +64,16 @@ typedef struct _WaylandContext { struct wl_cursor *cursor; void *bkgnddata; uint32_t formats; + struct wl_list stream_list; + int debug_fd; }WaylandContextStruct; +struct debug_stream { + struct wl_list link; + char *name; + struct weston_debug_stream_v1 *obj; +}; + static const char *left_ptrs[] = { "left_ptr", "default", @@ -88,6 +104,112 @@ get_bkgnd_settings(void) return bkgnd_settings; } +static struct debug_stream * +stream_alloc(WaylandContextStruct* wlcontext, const char *name) +{ + struct debug_stream *stream; + + stream = calloc(1, (sizeof *stream)); + if (!stream) + return NULL; + + stream->name = strdup(name); + if (!stream->name) { + free(stream); + return NULL; + } + + wl_list_insert(wlcontext->stream_list.prev, &stream->link); + + return stream; +} + +static void +stream_destroy(struct debug_stream *stream) +{ + if (stream->obj) + weston_debug_stream_v1_destroy(stream->obj); + + wl_list_remove(&stream->link); + free(stream->name); + free(stream); +} + +static void +destroy_streams(WaylandContextStruct* wlcontext) +{ + struct debug_stream *stream; + struct debug_stream *tmp; + + wl_list_for_each_safe(stream, tmp, &wlcontext->stream_list, link) { + stream_destroy(stream); + } +} + +static void +handle_stream_complete(void *data, struct weston_debug_stream_v1 *obj) +{ + struct debug_stream *stream = data; + + assert(stream->obj == obj); + + stream_destroy(stream); +} + +static void +handle_stream_failure(void *data, struct weston_debug_stream_v1 *obj, + const char *msg) +{ + struct debug_stream *stream = data; + + assert(stream->obj == obj); + + fprintf(stderr, "Debug stream '%s' aborted: %s\n", stream->name, msg); + + stream_destroy(stream); +} + +static const struct weston_debug_stream_v1_listener stream_listener = { + handle_stream_complete, + handle_stream_failure +}; + +static void +start_streams(WaylandContextStruct* wlcontext) +{ + struct debug_stream *stream; + + wl_list_for_each(stream, &wlcontext->stream_list, link) { + stream->obj = weston_debug_v1_subscribe(wlcontext->debug_iface, + stream->name, + wlcontext->debug_fd); + weston_debug_stream_v1_add_listener(stream->obj, + &stream_listener, stream); + } +} + +static void +get_debug_streams(WaylandContextStruct* wlcontext) +{ + char *stream_names; + char *stream; + const char separator[2] = " "; + + stream_names = getenv("IVI_CLIENT_DEBUG_STREAM_NAMES"); + + if(NULL == stream_names) + return; + + /* get the first stream */ + stream = strtok(stream_names, separator); + + /* walk through other streams */ + while( stream != NULL ) { + stream_alloc(wlcontext, stream); + stream = strtok(NULL, separator); + } +} + static void shm_format(void *data, struct wl_shm *wl_shm, uint32_t format) { @@ -299,6 +421,17 @@ registry_handle_global(void *data, struct wl_registry *registry, uint32_t name, wl_registry_bind(registry, name, &wl_seat_interface, 1); wl_seat_add_listener(wlcontext->wl_seat, &seat_Listener, data); } + if (!strcmp(interface, weston_debug_v1_interface.name)) { + uint32_t myver; + + if (wlcontext->debug_iface || wl_list_empty(&wlcontext->stream_list)) + return; + + myver = MIN(1, version); + wlcontext->debug_iface = + wl_registry_bind(registry, name, + &weston_debug_v1_interface, myver); + } } static void @@ -348,6 +481,9 @@ void destroy_wayland_context(WaylandContextStruct* wlcontext) if(wlcontext->wl_display) wl_display_disconnect(wlcontext->wl_display); + + if(wlcontext->debug_iface) + weston_debug_v1_destroy(wlcontext->debug_iface); } int @@ -500,6 +636,12 @@ int main (int argc, const char * argv[]) /*init wayland context*/ wlcontext = (WaylandContextStruct*)calloc(1, sizeof(WaylandContextStruct)); wlcontext->bkgnd_settings = bkgnd_settings; + + /*init debug stream list*/ + wl_list_init(&wlcontext->stream_list); + get_debug_streams(wlcontext); + wlcontext->debug_fd = STDOUT_FILENO; + if (init_wayland_context(wlcontext)) { fprintf(stderr, "init_wayland_context failed\n"); goto ErrorContext; @@ -512,6 +654,11 @@ int main (int argc, const char * argv[]) wl_display_roundtrip(wlcontext->wl_display); + if (!wl_list_empty(&wlcontext->stream_list) && + wlcontext->debug_iface) { + start_streams(wlcontext); + } + /*draw the bkgnd display*/ draw_bkgnd_surface(wlcontext); @@ -519,6 +666,7 @@ int main (int argc, const char * argv[]) ret = wl_display_dispatch(wlcontext->wl_display); Error: + destroy_streams(wlcontext); destroy_bkgnd_surface(wlcontext); ErrorContext: destroy_wayland_context(wlcontext); -- cgit v1.2.1