[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet-gtk4] branch master updated: integrate event loops
From: |
gnunet |
Subject: |
[gnunet-gtk4] branch master updated: integrate event loops |
Date: |
Mon, 01 Jul 2024 12:39:13 +0200 |
This is an automated email from the git hooks/post-receive script.
martin-schanzenbach pushed a commit to branch master
in repository gnunet-gtk4.
The following commit(s) were added to refs/heads/master by this push:
new 44cd43e integrate event loops
44cd43e is described below
commit 44cd43ea1d021b00aef97cbed1ef5f8a221e887c
Author: Martin Schanzenbach <schanzen@gnunet.org>
AuthorDate: Mon Jul 1 12:39:10 2024 +0200
integrate event loops
---
src/statistics/gnunet-statistics-application.c | 7 +-
src/statistics/gnunet-statistics-gtk4.c | 128 ++++++++++++++++++++++++-
src/statistics/gnunet-statistics-window.c | 4 +
3 files changed, 133 insertions(+), 6 deletions(-)
diff --git a/src/statistics/gnunet-statistics-application.c
b/src/statistics/gnunet-statistics-application.c
index c80bea5..3c527c6 100644
--- a/src/statistics/gnunet-statistics-application.c
+++ b/src/statistics/gnunet-statistics-application.c
@@ -28,6 +28,8 @@
#include "gnunet-statistics-application.h"
#include "gnunet-statistics-window.h"
+#include "gnunet/gnunet_statistics_service.h"
+#include "gnunet/gnunet_util_lib.h"
#define GNUNET_STATISTICS_DESCRIPTION ("- Manage GNUnet Statistics via GUI")
@@ -86,7 +88,7 @@ gnunet_statistics_application_handle_local_options
(GApplication *app,
if (g_variant_dict_contains (options, "version")) {
g_print ("GNUnet Statistics %s %s\n",
PACKAGE_VERSION,
- GNUNET_STATISTICS_DESCRIPTION);
+ GNUNET_STATISTICS_DESCRIPTION); bb
return 0;
}
@@ -136,6 +138,9 @@ gnunet_statistics_application_quit_action (GSimpleAction
*action,
g_assert (GNUNET_STATISTICS_IS_APPLICATION (self));
g_application_quit (G_APPLICATION (self));
+ // FIXME We need to disconnect from statistics, but we have to tell
+ // The GtkWindow that!
+ GNUNET_SCHEDULER_shutdown();
}
static const GActionEntry app_actions[] = {
diff --git a/src/statistics/gnunet-statistics-gtk4.c
b/src/statistics/gnunet-statistics-gtk4.c
index d4229cb..8cd64f7 100644
--- a/src/statistics/gnunet-statistics-gtk4.c
+++ b/src/statistics/gnunet-statistics-gtk4.c
@@ -28,32 +28,150 @@
#include <glib/gi18n.h>
+#include "gio/gio.h"
+#include "glib.h"
#include "gnunet-statistics-application.h"
+#include "gnunet/gnunet_common.h"
#include <gnunet/gnunet_util_lib.h>
#include <gnunet/gnunet_statistics_service.h>
+#include <sys/select.h>
+#include <time.h>
+
+struct GNUNET_SCHEDULER_Task *run_task;
+struct GNUNET_SCHEDULER_Task *gtk_select_task;
+
+static void
+schedule_loop (void *cls);
+
+static void
+cleanup (void *cls)
+{
+ printf ("Shutting down\n");
+ if (NULL != run_task)
+ GNUNET_SCHEDULER_cancel (run_task);
+ run_task = NULL;
+ if (NULL != gtk_select_task)
+ {
+ GNUNET_SCHEDULER_cancel (gtk_select_task);
+ gtk_select_task = NULL;
+ }
+ g_application_quit ((GApplication*) cls);
+}
+
+
+static void
+run_loop (void*cls)
+{
+ gtk_select_task = NULL;
+ GNUNET_assert (NULL == run_task);
+ printf ("Running context iteration\n");
+ g_main_context_iteration (NULL, FALSE);
+ run_task = GNUNET_SCHEDULER_add_now (&schedule_loop, NULL);
+ return;
+}
+
+
+static void
+schedule_loop (void *cls)
+{
+ struct GNUNET_TIME_Relative to;
+ GPollFD fds[100];
+ fd_set rfds;
+ fd_set wfds;
+ gint have_fds = 0;
+ gint gtk_to;
+ int nrfds = 0;
+ int nwfds = 0;
+ struct GNUNET_NETWORK_FDSet *gn_rfd;
+ struct GNUNET_NETWORK_FDSet *gn_wfd;
+
+ run_task = NULL;
+ FD_ZERO (&rfds);
+ FD_ZERO (&wfds);
+ have_fds = g_main_context_query (NULL, 0, >k_to, fds,
+ sizeof (fds));
+ to.rel_value_us = gtk_to;
+ for (int i = 0; i < have_fds; i++)
+ {
+ if (fds[i].events & (G_IO_IN | G_IO_PRI))
+ {
+ FD_SET (fds[i].fd, &rfds);
+ nrfds++;
+ }
+ if (fds[i].events & (G_IO_OUT))
+ {
+ FD_SET (fds[i].fd, &wfds);
+ nwfds++;
+ }
+ printf ("Got fd %d, flag %d\n", fds[i].fd, fds[i].events);
+ }
+ if (g_main_context_pending (g_main_context_default()) || (-1 != gtk_to))
+ {
+ gn_rfd = GNUNET_NETWORK_fdset_create ();
+ gn_wfd = GNUNET_NETWORK_fdset_create ();
+ GNUNET_NETWORK_fdset_copy_native (gn_rfd, &rfds, nrfds);
+ GNUNET_NETWORK_fdset_copy_native (gn_wfd, &rfds, nwfds);
+ }
+ else
+ {
+ gn_rfd = NULL;
+ gn_wfd = NULL;
+ }
+ printf ("Have %d fds from gtk, to=%d; have pending: %d (%d/%d)\n", have_fds,
gtk_to,
+ g_main_context_pending(NULL) == TRUE,
+ nrfds, nwfds);
+ if (0 == have_fds)
+ return;
+ gtk_select_task = GNUNET_SCHEDULER_add_select (
+ GNUNET_SCHEDULER_PRIORITY_DEFAULT, to, gn_rfd, gn_wfd, &run_loop, NULL);
+}
+
+
+static void
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *c)
+{
+ (void) args;
+ (void) cfgfile;
+ run_task = GNUNET_SCHEDULER_add_now (&schedule_loop, NULL);
+ g_application_activate (G_APPLICATION(cls));
+ GNUNET_SCHEDULER_add_shutdown (&cleanup, cls);
+}
+
int
main (int argc, char *argv[])
{
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_END
+ };
g_autoptr (GMainLoop) mainloop = NULL;
- g_autoptr(GnunetStatisticsApplication) app = NULL;
+ g_autoptr (GnunetStatisticsApplication) app = NULL;
int ret;
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
- app = gnunet_statistics_application_new ("org.gnunet.gnunet-gtk",
G_APPLICATION_DEFAULT_FLAGS);
- ret = g_application_run (G_APPLICATION (app), argc, argv);
+ g_main_context_push_thread_default(NULL);
+ app = gnunet_statistics_application_new ("org.gnunet.gnunet-gtk",
+ G_APPLICATION_DEFAULT_FLAGS);
+ g_application_register (G_APPLICATION (app), NULL, NULL);
+ GNUNET_assert (TRUE == g_main_context_acquire(g_main_context_default()));
+// ret = g_application_run (G_APPLICATION (app), argc, argv);
- mainloop = g_main_loop_new (NULL, FALSE);
+ ret = GNUNET_PROGRAM_run (argc, argv, "gnunet-gtk4", NULL,
+ options, &run, app);
+ /*mainloop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (mainloop);
while (g_list_model_get_n_items (gtk_window_get_toplevels ()) > 0)
g_main_context_iteration (NULL, TRUE);
-
+ */
return ret;
}
diff --git a/src/statistics/gnunet-statistics-window.c
b/src/statistics/gnunet-statistics-window.c
index 3c1bc5b..1555943 100644
--- a/src/statistics/gnunet-statistics-window.c
+++ b/src/statistics/gnunet-statistics-window.c
@@ -27,10 +27,13 @@
#include "config.h"
#include "gnunet-statistics-window.h"
+#include "glib.h"
+#include "gnunet/gnunet_configuration_lib.h"
#include "gtk-statistics.h"
#include <gnunet/gnunet_util_lib.h>
#include <gnunet/gnunet_statistics_service.h>
+#include <time.h>
#define MAX_HISTORY 1280
@@ -222,6 +225,7 @@ gnunet_statistics_window_init (GnunetStatisticsWindow *self)
GNUNET_free (self->ipath2);
GNUNET_free (self->ipath);
+ //g_main_context_invoke(NULL, &init_stats, self);
self->statistics = GNUNET_STATISTICS_create ("gnunet-statistics-gtk",
self->config);
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnunet-gtk4] branch master updated: integrate event loops,
gnunet <=