37
33
#include <sys/wait.h>
38
34
#include <string.h>
41
#include <dbus/dbus.h>
42
#include <libnm_glib.h>
45
36
#include "common.h"
50
#include "ui/liferea_htmlview.h"
51
40
#include "ui/liferea_shell.h"
52
41
#include "ui/ui_tray.h"
54
43
/** global update job list, used for lookups when cancelling */
55
44
static GSList *jobs = NULL;
57
/* We use a communication queue for limiting the number
58
of concurrent requests to avoid hitting the file descriptor
59
limit of the glibcurl code. */
60
46
static GAsyncQueue *pendingHighPrioJobs = NULL;
61
47
static GAsyncQueue *pendingJobs = NULL;
62
48
static guint numberOfActiveJobs = 0;
63
49
#define MAX_ACTIVE_JOBS 5
66
/* State for NM support */
67
static libnm_glib_ctx *nm_ctx = NULL;
68
static guint nm_id = 0;
71
51
/* update state interface */
321
301
g_assert (NULL != job->result);
324
srcDoc = xml_parse (job->result->data, job->result->size, FALSE, NULL);
304
srcDoc = xml_parse (job->result->data, job->result->size, NULL);
326
306
g_warning("fatal: parsing request result XML source failed (%s)!", job->request->filtercmd);
490
470
if (!pendingJobs)
491
471
return FALSE; /* we must be in shutdown */
493
if (numberOfActiveJobs >= MAX_ACTIVE_JOBS)
494
return TRUE; /* let's continue later */
473
if (numberOfActiveJobs >= MAX_ACTIVE_JOBS)
474
return FALSE; /* we'll be called again when a job finishes */
496
477
job = (updateJobPtr)g_async_queue_try_pop(pendingHighPrioJobs);
533
514
if (flags & FEED_REQ_PRIORITY_HIGH) {
534
515
g_async_queue_push (pendingHighPrioJobs, (gpointer)job);
535
update_dequeue_job (NULL);
537
517
g_async_queue_push (pendingJobs, (gpointer)job);
520
g_idle_add (update_dequeue_job, NULL);
588
570
g_idle_add (update_process_result_idle_cb, job);
593
update_network_monitor (libnm_glib_ctx *ctx, gpointer user_data)
595
libnm_glib_state state;
598
g_return_if_fail (ctx != NULL);
600
state = libnm_glib_get_network_state (ctx);
601
online = network_is_online ();
603
if (online && state == LIBNM_NO_NETWORK_CONNECTION) {
604
debug0 (DEBUG_UPDATE, "network manager: no network connection -> going offline");
605
network_set_online (FALSE);
606
} else if (!online && state == LIBNM_ACTIVE_NETWORK_CONNECTION) {
607
debug0 (DEBUG_UPDATE, "network manager: active connection -> going online");
608
network_set_online (TRUE);
613
update_nm_initialize (void)
615
debug0 (DEBUG_UPDATE, "network manager: registering network state change callback");
618
nm_ctx = libnm_glib_init ();
620
fprintf (stderr, "Could not initialize libnm.\n");
625
nm_id = libnm_glib_register_callback (nm_ctx, update_network_monitor, NULL, NULL);
631
update_nm_cleanup (void)
633
debug0 (DEBUG_UPDATE, "network manager: unregistering network state change callback");
635
if (nm_id != 0 && nm_ctx != NULL) {
636
libnm_glib_unregister_callback (nm_ctx, nm_id);
637
libnm_glib_shutdown (nm_ctx);
645
575
update_init (void)
647
577
pendingJobs = g_async_queue_new ();
648
578
pendingHighPrioJobs = g_async_queue_new ();
651
g_timeout_add (500, update_dequeue_job, NULL);
655
DBusConnection *connection;
657
connection = dbus_bus_get (DBUS_BUS_SYSTEM, NULL);
660
dbus_connection_set_exit_on_disconnect (connection, FALSE);
662
if (dbus_bus_name_has_owner (connection, "org.freedesktop.NetworkManager", NULL)) {
663
update_nm_initialize ();
664
/* network manager will set online state right after initialization... */
666
network_set_online (TRUE);
669
dbus_connection_unref(connection);
675
network_set_online (TRUE);