#include <stdio.h>
#include <stdlib.h>

#include <gio/gio.h>

static GMainLoop *loop = NULL;

static void print_mount_list(GList *mount_list) {
	GList *tmp_mnt_list = NULL;
	printf("[");
	if (mount_list) {
		printf(g_mount_get_name(mount_list->data));
		tmp_mnt_list = mount_list->next;
	}
	while (tmp_mnt_list) {
		printf(", %s", g_mount_get_name(tmp_mnt_list->data));
		tmp_mnt_list = tmp_mnt_list->next;
	}
	printf("]\n");
}

static gboolean timeout_cb (GVolumeMonitor *gvm) {
	GList *mount_list;
	mount_list = g_volume_monitor_get_mounts(gvm);
	print_mount_list(mount_list);

	g_main_loop_quit (loop);

        g_list_free_full (mount_list, g_object_unref);
	
	return FALSE;
}

int main(int argc, char * argv[]) {
	GVolumeMonitor *gvm;
	gvm = g_volume_monitor_get();

	GList *mount_list;
	mount_list = g_volume_monitor_get_mounts(gvm);
	print_mount_list(mount_list);
	printf("Sleeping for 20 seconds. Time to mount or unmount.\n");
	g_timeout_add_seconds (20, (GSourceFunc) timeout_cb, gvm);

	loop = g_main_loop_new (NULL, FALSE);
        g_main_loop_run (loop);
	g_main_loop_unref (loop);

        g_list_free_full (mount_list, g_object_unref);	
	g_object_unref (gvm);

	return 0;
}