X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fmain.c;h=3fa41327d6faad9df44932e9df809561e3760e26;hb=edbfbad7344c4de62cbf5a4a5c8935afa50d8b4a;hp=d7de96e915ca8ea7ccf25224e2f65c2d01554b8c;hpb=a17bac48464b5f2b6359856a75caae882d9a48f6;p=src%2Fagl-compositor.git diff --git a/src/main.c b/src/main.c index d7de96e..3fa4132 100644 --- a/src/main.c +++ b/src/main.c @@ -24,6 +24,7 @@ */ #include "ivi-compositor.h" +#include "policy.h" #include #include @@ -38,15 +39,22 @@ #include #include +#ifdef HAVE_BACKEND_X11 #include +#endif #include #include #include +#include #include "shared/os-compatibility.h" +#include "shared/helpers.h" #include "agl-shell-server-protocol.h" +static int cached_tm_mday = -1; +static struct weston_log_scope *log_scope; + struct ivi_compositor * to_ivi_compositor(struct weston_compositor *ec) { @@ -536,7 +544,7 @@ load_drm_backend(struct ivi_compositor *ivi, int *argc, char *argv[]) struct weston_config_section *section; int use_current_mode = 0; int use_pixman = 0; - int use_shadow; + bool use_shadow; int ret; const struct weston_option options[] = { @@ -582,7 +590,7 @@ windowed_parse_common_options(struct ivi_compositor *ivi, int *argc, char *argv[ bool *use_pixman, bool *fullscreen, int *output_count) { struct weston_config_section *section; - int pixman; + bool pixman; int fs = 0; const struct weston_option options[] = { @@ -709,6 +717,7 @@ load_wayland_backend(struct ivi_compositor *ivi, int *argc, char *argv[]) return windowed_create_outputs(ivi, output_count, "WL", "wayland"); } +#ifdef HAVE_BACKEND_X11 static int load_x11_backend(struct ivi_compositor *ivi, int *argc, char *argv[]) { @@ -746,6 +755,13 @@ load_x11_backend(struct ivi_compositor *ivi, int *argc, char *argv[]) return windowed_create_outputs(ivi, output_count, "X", "screen"); } +#else +static int +load_x11_backend(struct ivi_compositor *ivi, int *argc, char *argv[]) +{ + return -1; +} +#endif static int load_backend(struct ivi_compositor *ivi, const char *backend, @@ -785,8 +801,8 @@ compositor_init_config(struct weston_compositor *compositor, struct xkb_rule_names xkb_names; struct weston_config_section *section; int repaint_msec; - int vt_switching; - int require_input; + bool vt_switching; + bool require_input; /* agl-compositor.ini [keyboard] */ section = weston_config_get_section(config, "keyboard", NULL, NULL); @@ -967,39 +983,46 @@ load_config(struct weston_config **config, bool no_config, } static FILE *logfile; -//static struct weston_log_scope *log_scope; -//static struct weston_log_scope *protocol_scope; -static int -log_timestamp(void) +static char * +log_timestamp(char *buf, size_t len) { - static int cached_tm_mday = -1; - struct timespec ts; - struct tm brokendown_time; - char buf[128]; + struct timeval tv; + struct tm *brokendown_time; + char datestr[128]; + char timestr[128]; - clock_gettime(CLOCK_REALTIME, &ts); - if (!localtime_r(&ts.tv_sec, &brokendown_time)) - return fprintf(logfile, "[(NULL)localtime] "); + gettimeofday(&tv, NULL); - if (brokendown_time.tm_mday != cached_tm_mday) { - strftime(buf, sizeof buf, "%Y-%m-%d %Z", &brokendown_time); - fprintf(logfile, "Date: %s\n", buf); + brokendown_time = localtime(&tv.tv_sec); + if (brokendown_time == NULL) { + snprintf(buf, len, "%s", "[(NULL)localtime] "); + return buf; + } - cached_tm_mday = brokendown_time.tm_mday; + memset(datestr, 0, sizeof(datestr)); + if (brokendown_time->tm_mday != cached_tm_mday) { + strftime(datestr, sizeof(datestr), "Date: %Y-%m-%d %Z\n", + brokendown_time); + cached_tm_mday = brokendown_time->tm_mday; } - strftime(buf, sizeof buf, "%H:%M:%S", &brokendown_time); + strftime(timestr, sizeof(timestr), "%H:%M:%S", brokendown_time); + /* if datestr is empty it prints only timestr*/ + snprintf(buf, len, "%s[%s.%03li]", datestr, + timestr, (tv.tv_usec / 1000)); - return fprintf(logfile, "[%s.%03ld] ", buf, ts.tv_nsec / 1000000); + return buf; } static void custom_handler(const char *fmt, va_list arg) { - log_timestamp(); - fprintf(logfile, "libwayland: "); - vfprintf(logfile, fmt, arg); + char timestr[512]; + + weston_log_scope_printf(log_scope, "%s libwayland: ", + log_timestamp(timestr, sizeof(timestr))); + weston_log_scope_vprintf(log_scope, fmt, arg); } static void @@ -1029,18 +1052,33 @@ log_file_close(void) static int vlog(const char *fmt, va_list ap) { - int l; - - l = log_timestamp(); - l += vfprintf(logfile, fmt, ap); + const char *oom = "Out of memory"; + char timestr[128]; + int len = 0; + char *str; + + if (weston_log_scope_is_enabled(log_scope)) { + int len_va; + char *xlog_timestamp = log_timestamp(timestr, sizeof(timestr)); + len_va = vasprintf(&str, fmt, ap); + if (len_va >= 0) { + len = weston_log_scope_printf(log_scope, "%s %s", + xlog_timestamp, str); + free(str); + } else { + len = weston_log_scope_printf(log_scope, "%s %s", + xlog_timestamp, oom); + } + } - return l; + return len; } + static int vlog_continue(const char *fmt, va_list ap) { - return vfprintf(logfile, fmt, ap); + return weston_log_scope_vprintf(log_scope, fmt, ap); } static int @@ -1117,7 +1155,9 @@ int main(int argc, char *argv[]) int version = 0; int no_config = 0; char *config_file = NULL; - int debug_protocol = 0; + struct weston_log_context *log_ctx = NULL; + struct weston_log_subscriber *logger; + int ret = EXIT_FAILURE; const struct weston_option core_options[] = { { WESTON_OPTION_STRING, "backend", 'B', &backend }, @@ -1127,12 +1167,15 @@ int main(int argc, char *argv[]) { WESTON_OPTION_BOOLEAN, "version", 0, &version }, { WESTON_OPTION_BOOLEAN, "no-config", 0, &no_config }, { WESTON_OPTION_STRING, "config", 'c', &config_file }, - { WESTON_OPTION_BOOLEAN, "debug", 0, &debug_protocol }, }; wl_list_init(&ivi.outputs); wl_list_init(&ivi.surfaces); wl_list_init(&ivi.pending_surfaces); + wl_list_init(&ivi.popup_pending_apps); + wl_list_init(&ivi.fullscreen_pending_apps); + wl_list_init(&ivi.split_pending_apps); + wl_list_init(&ivi.desktop_clients); /* Prevent any clients we spawn getting our stdin */ os_fd_set_cloexec(STDIN_FILENO); @@ -1147,9 +1190,22 @@ int main(int argc, char *argv[]) return EXIT_SUCCESS; } + log_ctx = weston_log_ctx_compositor_create(); + if (!log_ctx) { + fprintf(stderr, "Failed to initialize weston debug framework.\n"); + return ret; + } + + log_scope = weston_compositor_add_log_scope(log_ctx, "log", + "agl-compositor log\n", + NULL, NULL, NULL); + log_file_open(log); weston_log_set_handler(vlog, vlog_continue); + logger = weston_log_subscriber_create_log(logfile); + weston_log_subscribe(log_ctx, logger, "log"); + if (load_config(&ivi.config, no_config, config_file) < 0) goto error_signals; section = weston_config_get_section(ivi.config, "core", NULL, NULL); @@ -1181,7 +1237,7 @@ int main(int argc, char *argv[]) if (!signals[i]) goto error_signals; - ivi.compositor = weston_compositor_create(display, &ivi); + ivi.compositor = weston_compositor_create(display, log_ctx, &ivi); if (!ivi.compositor) { weston_log("fatal: failed to create compositor.\n"); goto error_signals; @@ -1202,6 +1258,9 @@ int main(int argc, char *argv[]) if (ivi_desktop_init(&ivi) < 0) goto error_compositor; + if (ivi_policy_init(&ivi) < 0) + goto error_compositor; + if (ivi_shell_init(&ivi) < 0) goto error_compositor; @@ -1224,11 +1283,23 @@ int main(int argc, char *argv[]) wl_display_run(display); + ret = ivi.compositor->exit_code; + wl_display_destroy_clients(display); error_compositor: + weston_compositor_tear_down(ivi.compositor); + + weston_compositor_log_scope_destroy(log_scope); + log_scope = NULL; + + weston_log_ctx_compositor_destroy(ivi.compositor); weston_compositor_destroy(ivi.compositor); + weston_log_subscriber_destroy_log(logger); + + ivi_policy_destroy(ivi.policy); + error_signals: for (size_t i = 0; i < ARRAY_LENGTH(signals); ++i) if (signals[i]) @@ -1239,4 +1310,6 @@ error_signals: log_file_close(); if (ivi.config) weston_config_destroy(ivi.config); + + return ret; }