#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <dbus/dbus.h>
#include "../dbus-gmain/dbus-gmain.h"
#include <keepalive-glib/keepalive-backgroundactivity.h>
#include <assert.h>
#define failure(FMT, ARGS...) do {\
fprintf(stderr, "%s: "FMT"\n", __FUNCTION__, ## ARGS);\
exit(EXIT_FAILURE); \
} while(0)
static DBusConnection *system_bus = 0;
static GMainLoop *mainloop_handle = 0;
static void disconnect_from_systembus(void)
{
if( system_bus )
dbus_connection_unref(system_bus), system_bus = 0;
}
static void connect_to_system_bus(void)
{
DBusError err = DBUS_ERROR_INIT;
system_bus = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
if( !system_bus )
failure("%s: %s", err.name, err.message);
dbus_gmain_set_up_connection(system_bus, 0);
dbus_error_free(&err);
}
static gboolean continue_cb(gpointer aptr)
{
printf("%s()\n", __FUNCTION__);
return FALSE;
}
static gboolean stop_cb(gpointer aptr)
{
printf("%s()\n", __FUNCTION__);
printf("EXIT MAINLOOP\n");
g_main_loop_quit(mainloop_handle);
return FALSE;
}
{
static int count = 0;
printf("%s(%s) #%d\n", __FUNCTION__, (char *)user_data, ++count);
if( count < 3 ) {
g_timeout_add_seconds(10, continue_cb, activity);
}
else {
g_timeout_add_seconds(10, stop_cb, activity);
}
}
{
printf("%s(%s)\n", __FUNCTION__, (char *)user_data);
}
{
printf("%s(%s)\n", __FUNCTION__, (char *)user_data);
}
int main(int argc, char **argv)
{
(void)argc, (void)argv;
mainloop_handle = g_main_loop_new(0, 0);
connect_to_system_bus();
printf("ENTER MAINLOOP\n");
g_main_loop_run(mainloop_handle);
printf("LEAVE MAINLOOP\n");
disconnect_from_systembus();
g_main_loop_unref(mainloop_handle);
return 0;
}
void background_activity_set_wakeup_slot(background_activity_t *self, background_activity_frequency_t slot)
void background_activity_wait(background_activity_t *self)
background_activity_frequency_t
Definition keepalive-backgroundactivity.h:80
@ BACKGROUND_ACTIVITY_FREQUENCY_THIRTY_SECONDS
Definition keepalive-backgroundactivity.h:85
void background_activity_set_user_data(background_activity_t *self, void *user_data, background_activity_free_fn free_cb)
void background_activity_unref(background_activity_t *self)
void background_activity_stop(background_activity_t *self)
background_activity_t * background_activity_new(void)
void background_activity_set_waiting_callback(background_activity_t *self, background_activity_event_fn cb)
void background_activity_set_stopped_callback(background_activity_t *self, background_activity_event_fn cb)
void background_activity_set_running_callback(background_activity_t *self, background_activity_event_fn cb)
struct background_activity_t background_activity_t
Definition keepalive-backgroundactivity.h:53