[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1335761711-31403-8-git-send-email-namhyung.kim@lge.com>
Date: Mon, 30 Apr 2012 13:55:11 +0900
From: Namhyung Kim <namhyung.kim@....com>
To: Arnaldo Carvalho de Melo <acme@...stprotocols.net>
Cc: Peter Zijlstra <a.p.zijlstra@...llo.nl>,
Paul Mackerras <paulus@...ba.org>,
Ingo Molnar <mingo@...hat.com>,
Namhyung Kim <namhyung@...il.com>,
LKML <linux-kernel@...r.kernel.org>,
Pekka Enberg <penberg@...nel.org>
Subject: [PATCH 7/7] perf ui/gtk: Use struct perf_error_ops
Define and use perf_gtk_eops to provide a GTK2 message
dialog for error reporting. To do that, we need global
main_window variable for tracking UI state.
Signed-off-by: Namhyung Kim <namhyung.kim@....com>
---
tools/perf/ui/gtk/browser.c | 6 ++++--
tools/perf/ui/gtk/gtk.h | 4 ++++
tools/perf/ui/gtk/setup.c | 6 ++++++
tools/perf/ui/gtk/util.c | 47 +++++++++++++++++++++++++++++++++++++++++++
4 files changed, 61 insertions(+), 2 deletions(-)
diff --git a/tools/perf/ui/gtk/browser.c b/tools/perf/ui/gtk/browser.c
index 0656c381a89c..64286437a553 100644
--- a/tools/perf/ui/gtk/browser.c
+++ b/tools/perf/ui/gtk/browser.c
@@ -12,7 +12,7 @@
static void perf_gtk__signal(int sig)
{
psignal(sig, "perf");
- gtk_main_quit();
+ perf_gtk__exit(false);
}
static void perf_gtk__resize_window(GtkWidget *window)
@@ -137,7 +137,7 @@ int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist,
signal(SIGQUIT, perf_gtk__signal);
signal(SIGTERM, perf_gtk__signal);
- window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ main_window = window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "perf report");
@@ -174,5 +174,7 @@ int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist,
gtk_main();
+ main_window = NULL;
+
return 0;
}
diff --git a/tools/perf/ui/gtk/gtk.h b/tools/perf/ui/gtk/gtk.h
index 75177ee04032..eb08cbea0da1 100644
--- a/tools/perf/ui/gtk/gtk.h
+++ b/tools/perf/ui/gtk/gtk.h
@@ -5,4 +5,8 @@
#include <gtk/gtk.h>
#pragma GCC diagnostic error "-Wstrict-prototypes"
+#include "../../util/debug.h"
+
+extern GtkWidget *main_window;
+
#endif /* _PERF_GTK_H_ */
diff --git a/tools/perf/ui/gtk/setup.c b/tools/perf/ui/gtk/setup.c
index 829529957766..ef74e043eba2 100644
--- a/tools/perf/ui/gtk/setup.c
+++ b/tools/perf/ui/gtk/setup.c
@@ -1,12 +1,18 @@
#include "gtk.h"
#include "../../util/cache.h"
+#include "../../util/debug.h"
+
+
+extern struct perf_error_ops perf_gtk_eops;
int perf_gtk__init(void)
{
+ perf_error__register_functions(&perf_gtk_eops);
return gtk_init_check(NULL, NULL) ? 0 : -1;
}
void perf_gtk__exit(bool wait_for_ok __used)
{
+ perf_error__unregister_functions(&perf_gtk_eops);
gtk_main_quit();
}
diff --git a/tools/perf/ui/gtk/util.c b/tools/perf/ui/gtk/util.c
index a727fe394e91..0d0ed2ed3937 100644
--- a/tools/perf/ui/gtk/util.c
+++ b/tools/perf/ui/gtk/util.c
@@ -2,6 +2,53 @@
#include "../../util/debug.h"
#include "gtk.h"
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+
+GtkWidget *main_window;
+
+static int message_dialog(const char *title, const char *format, va_list args)
+{
+ char *msg;
+ GtkWidget *dialog;
+ GtkMessageType message_type = GTK_MESSAGE_WARNING;
+
+ if (!main_window || vasprintf(&msg, format, args) < 0) {
+ fprintf(stderr, "%s:\n", title);
+ vfprintf(stderr, format, args);
+ return -1;
+ }
+
+ if (strcmp(title, "Error") == 0)
+ message_type = GTK_MESSAGE_ERROR;
+
+ dialog = gtk_message_dialog_new_with_markup(GTK_WINDOW(main_window),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ message_type,
+ GTK_BUTTONS_CLOSE,
+ "<b>%s</b>\n\n%s", title, msg);
+ gtk_dialog_run(GTK_DIALOG(dialog));
+ gtk_widget_destroy(dialog);
+ free(msg);
+ return 0;
+}
+
+static int perf_gtk__error(const char *format, va_list args)
+{
+ return message_dialog("Error", format, args);
+}
+
+static int perf_gtk__warning(const char *format, va_list args)
+{
+ return message_dialog("Warning", format, args);
+}
+
+struct perf_error_ops perf_gtk_eops = {
+ .error = perf_gtk__error,
+ .warning = perf_gtk__warning,
+};
/*
* FIXME: Functions below should be implemented properly.
--
1.7.10
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists