summaryrefslogtreecommitdiff
path: root/.pc/tizen.patch/src/test-connectivity.c
blob: c8b7cf662a51e3cf5354603d43678851038fa91f (plain)
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

#include <connectivity.h>

static void
print_ap (gpointer key,
	  gpointer value,
	  gpointer data)
{
	g_message ("\t%s : %d dBm",
		   key,
		   GPOINTER_TO_INT (value));
}

static void
print_aps (GeoclueConnectivity *conn)
{
	GHashTable *ht;

	ht = geoclue_connectivity_get_aps (conn);
	if (ht == NULL) {
		g_message ("No Access Points available");
		return;
	}
	g_message ("APs:");
	g_hash_table_foreach (ht, print_ap, NULL);
}

static void
print_if_avail (GeoclueConnectivity *self,
		GeoclueNetworkStatus status)
{
	char *router, *ap;
	if (status != GEOCLUE_CONNECTIVITY_ONLINE)
		return;
	print_aps (self);
	ap = geoclue_connectivity_get_ap_mac (self);
	g_message ("AP is '%s'", ap ? ap : "Unavailable");
	g_free (ap);

	router = geoclue_connectivity_get_router_mac (self);
	g_message ("Router is '%s'", router);
	g_free (router);
}

static void
status_changed_cb (GeoclueConnectivity *self,
		   GeoclueNetworkStatus status,
		   gpointer data)
{
	const char *str;

	switch (status) {
	case GEOCLUE_CONNECTIVITY_UNKNOWN:
		str = "GEOCLUE_CONNECTIVITY_UNKNOWN";
		break;
	case GEOCLUE_CONNECTIVITY_OFFLINE:
		str = "GEOCLUE_CONNECTIVITY_OFFLINE";
		break;
	case GEOCLUE_CONNECTIVITY_ACQUIRING:
		str = "GEOCLUE_CONNECTIVITY_ACQUIRING";
		break;
	case GEOCLUE_CONNECTIVITY_ONLINE:
		str = "GEOCLUE_CONNECTIVITY_ONLINE";
		break;
	default:
		g_assert_not_reached ();
	}

	g_message ("Connectivity status switch to '%s'", str);

	print_if_avail (self, status);
}

int main (int argc, char **argv)
{
	GMainLoop *mainloop;
	GeoclueConnectivity *conn;
	char *router;

	g_type_init ();
	mainloop = g_main_loop_new (NULL, FALSE);
	conn = geoclue_connectivity_new ();

	if (conn == NULL) {
		router = geoclue_connectivity_get_router_mac (conn);
		g_message ("Router MAC is detected as '%s'", router ? router : "empty");

		return 1;
	}
	print_if_avail (conn, geoclue_connectivity_get_status (conn));
	g_signal_connect (conn, "status-changed",
			  G_CALLBACK (status_changed_cb), NULL);

	g_main_loop_run (mainloop);

	return 0;
}