Simple example to demonstrate use of cpukeepalive_t objects to block device from suspending.
Simple example to demonstrate use of cpukeepalive_t objects to block device from suspending.
#include <stdio.h>
#include <stdlib.h>
#include <glib.h>
#include <dbus/dbus.h>
#include "../dbus-gmain/dbus-gmain.h"
#include <keepalive-glib/keepalive-cpukeepalive.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 exit_timer_cb(gpointer aptr)
{
g_main_loop_quit(mainloop_handle);
return FALSE;
}
int main(int argc, char **argv)
{
(void)argc, (void)argv;
mainloop_handle = g_main_loop_new(0, 0);
connect_to_system_bus();
g_timeout_add_seconds(20, exit_timer_cb, 0);
printf("BLOCK SUSPEND\n");
printf("ENTER MAINLOOP\n");
g_main_loop_run(mainloop_handle);
printf("LEAVE MAINLOOP\n");
printf("ALLOW SUSPEND\n");
disconnect_from_systembus();
g_main_loop_unref(mainloop_handle);
return 0;
}
void cpukeepalive_stop(cpukeepalive_t *self)
cpukeepalive_t * cpukeepalive_new(void)
void cpukeepalive_start(cpukeepalive_t *self)
struct cpukeepalive_t cpukeepalive_t
Definition keepalive-cpukeepalive.h:50
void cpukeepalive_unref(cpukeepalive_t *self)