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
|
using GLib;
using GUPnP;
/*
* TODO:
* * call setlocale
* * SIGTERM handler?
*/
public class Test.ProxyTest : Object {
public static int main (string[] args) {
Context ctxt;
try {
ctxt = new Context (null, null, 0);
} catch (Error err) {
critical (err.message);
return 1;
}
ControlPoint cp = new ControlPoint
(ctxt, "urn:schemas-upnp-org:service:ContentDirectory:1");
cp.service_proxy_available.connect (on_service_proxy_available);
cp.service_proxy_unavailable.connect (on_service_proxy_unavailable);
cp.active = true;
MainLoop loop = new MainLoop (null, false);
loop.run();
return 0;
}
private static void on_service_proxy_available (ControlPoint cp,
ServiceProxy proxy) {
print ("ContentDirectory available:\n");
print ("\tlocation: %s\n", proxy.location);
/* We want to be notified whenever SystemUpdateID changes */
proxy.add_notify ("SystemUpdateID", typeof (uint), on_notify);
/* subscribe */
proxy.subscription_lost.connect (on_subscription_lost);
proxy.subscribed = true;
/* test action IO */
try {
string result;
uint count, total;
proxy.send_action
("Browse",
/* IN args */
"ObjectID", typeof (string), "0",
"BrowseFlag", typeof (string), "BrowseDirectChildren",
"Filter", typeof (string), "*",
"StartingIndex", typeof (uint), 0,
"RequestedCount", typeof (uint), 0,
"SortCriteria", typeof (string), "",
null,
/* OUT args */
"Result", typeof (string), out result,
"NumberReturned", typeof (uint), out count,
"TotalMatches", typeof (uint), out total,
null);
print ("Browse returned:\n");
print ("\tResult: %s\n", result);
print ("\tNumberReturned: %u\n", count);
print ("\tTotalMatches: %u\n", total);
} catch (Error err) {
printerr ("Error: %s\n", err.message);
}
}
private static void on_service_proxy_unavailable (ControlPoint cp,
ServiceProxy proxy) {
print ("ContentDirectory unavailable:\n");
print ("\tlocation: %s\n", proxy.location);
}
private static void on_notify (ServiceProxy proxy,
string variable,
Value value) {
print ("Received a notification for variable '%s':\n",
variable);
print ("\tvalue: %u\n", value.get_uint ());
}
private static void on_subscription_lost (ServiceProxy proxy,
Error reason) {
print ("Lost subscription: %s\n", reason.message);
}
}
|