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
114
115
116
117
118
119
120
121
122
123
124
125
|
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "connman-glib.h"
void manager_event_cb(const gchar *path,
connman_manager_event_t event,
GVariant *properties,
gpointer user_data)
{
printf("%s - enter\n", __FUNCTION__);
switch(event) {
case CONNMAN_MANAGER_EVENT_TECHNOLOGY_ADD:
printf("technology %s add\n", path);
break;
case CONNMAN_MANAGER_EVENT_TECHNOLOGY_REMOVE:
printf("technology %s remove\n", path);
break;
case CONNMAN_MANAGER_EVENT_SERVICE_CHANGE:
printf("service %s change: ...\n", path);
break;
case CONNMAN_MANAGER_EVENT_SERVICE_REMOVE:
printf("service %s remove: ...\n", path);
break;
case CONNMAN_MANAGER_EVENT_PROPERTY_CHANGE:
printf("property %s change: %s\n",
path,
properties ? g_variant_print(properties, TRUE) : "(null)");
break;
default:
break;
}
printf("%s - exit\n\n", __FUNCTION__);
}
void technology_property_event_cb(const gchar *technology,
GVariant *properties,
gpointer user_data)
{
printf("%s - enter\n", __FUNCTION__);
printf("technology %s properties: %s\n",
technology,
properties ? g_variant_print(properties, TRUE) : "(null)");
printf("%s - exit\n\n", __FUNCTION__);
}
void service_property_event_cb(const gchar *service,
GVariant *properties,
gpointer user_data)
{
printf("%s - enter\n", __FUNCTION__);
printf("service %s properties: %s\n",
service,
properties ? g_variant_print(properties, TRUE) : "(null)");
printf("%s - exit\n\n", __FUNCTION__);
}
int main(int argc, char *argv[])
{
gboolean rc;
connman_add_manager_event_callback(manager_event_cb, NULL);
connman_add_technology_property_event_callback(technology_property_event_cb, NULL);
connman_add_service_property_event_callback(service_property_event_cb, NULL);
// FIXME: should pass callback here and wait for it to report success
rc = connman_init(TRUE);
printf("connman_init rc = %d\n", rc);
GVariant *reply = NULL;
rc = connman_get_technologies(&reply);
if(rc) {
//printf("technologies: %s\n\n", reply ? g_variant_print(reply, TRUE) : "(null)");
GVariantIter *array = NULL;
g_variant_get(reply, "(a(oa{sv}))", &array);
const gchar *path = NULL;
GVariant *var = NULL;
printf("technologies:\n");
while (g_variant_iter_next(array, "(o@a{sv})", &path, &var)) {
printf("%s: %s\n", path, g_variant_print(var, TRUE));
g_variant_unref(var);
}
g_variant_iter_free(array);
g_variant_unref(reply);
}
reply = NULL;
rc = connman_get_services(&reply);
if(rc) {
printf("services: %s\n", reply ? g_variant_print(reply, TRUE) : "(null)");
g_variant_unref(reply);
}
gchar *state = NULL;
if(connman_manager_get_state(&state)) {
printf("\nconnman manager state = %s\n", state);
g_free(state);
}
rc = connman_technology_enable("wifi");
sleep(5);
rc = connman_technology_scan_services("wifi");
if(!rc) {
printf("wifi scan failed!\n");
exit(1);
}
sleep(20);
reply = NULL;
rc = connman_get_services(&reply);
if(rc) {
printf("services: %s\n", reply ? g_variant_print(reply, TRUE) : "(null)");
g_variant_unref(reply);
}
rc = connman_technology_disable("wifi");
return 0;
}
|