File: test-urfkill-client.c

package info (click to toggle)
urfkill 0.5.0-7.3
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 712 kB
  • sloc: ansic: 6,558; xml: 715; makefile: 382; javascript: 87; sh: 31
file content (113 lines) | stat: -rw-r--r-- 2,388 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <time.h>
#include <urfkill.h>
#include <stdio.h>
#include <glib.h>

static GMainLoop *loop = NULL;

static void
print_urf_device (UrfDevice *device)
{
	guint index, type;
	gboolean soft, hard;
	char *name;

	g_object_get (device,
		      "index", &index,
		      "type", &type,
		      "soft", &soft,
		      "hard", &hard,
		      "name", &name,
		      NULL);

	printf ("index = %u\n", index);
	printf ("type  = %u\n", type);
	printf ("soft  = %d\n", soft);
	printf ("hard  = %d\n", hard);
	printf ("name  = %s\n", name);
}

static void
device_added_cb (UrfClient *client, UrfDevice *device, gpointer data)
{
	printf ("== Added ==\n");
	print_urf_device (device);
	printf ("\n");
}

static void
device_removed_cb (UrfClient *client, UrfDevice *device, gpointer data)
{
	printf ("== removed ==\n");
	print_urf_device (device);
	printf ("\n");
}

static void
device_changed_cb (UrfClient *client, UrfDevice *device, gpointer data)
{
	printf ("== Changed ==\n");
	print_urf_device (device);
	printf ("\n");
}

static void
main_sigint_handler (gint sig)
{
	signal (SIGINT, SIG_DFL);
	g_main_loop_quit (loop);
}

int
main ()
{
	UrfClient *client = NULL;
	gboolean status;
	GList *devices, *item;
	UrfDevice *device;

#if !GLIB_CHECK_VERSION(2,36,0)
	g_type_init();
#endif

	client = urf_client_new ();
	urf_client_enumerate_devices_sync (client, NULL, NULL);

	g_signal_connect (client, "device-added", G_CALLBACK (device_added_cb), NULL);
	g_signal_connect (client, "device-removed", G_CALLBACK (device_removed_cb), NULL);
	g_signal_connect (client, "device-changed", G_CALLBACK (device_changed_cb), NULL);

	status = urf_client_set_wlan_block (client, TRUE);
	printf ("Status of block: %d\n", status);

	sleep (2);

	status = urf_client_set_wlan_block (client, FALSE);
	printf ("Status of unblock: %d\n", status);

	g_object_get (client, "key-control", &status, NULL);
	printf ("Key control is %s\n", status?"on":"off");

	status = urf_client_is_inhibited (client, NULL);
	printf ("Key control is %s\n", status?"inhibitied":"uninhibited");

	sleep (2);

	devices = urf_client_get_devices (client);

	for (item = devices; item; item = item->next) {
		device = (UrfDevice *)item->data;
		print_urf_device (device);
		printf ("\n");
	}

	loop = g_main_loop_new (NULL, FALSE);

	signal (SIGINT, main_sigint_handler);

	g_main_loop_run (loop);

	g_object_unref (client);

	return 0;
}