blob: 93061d3fca29cbda4717bfcd8e5f632a3ad39d0a (
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
|
/*
* Copyright (C) 2012 Openismus GmbH
*
* Author: Krzesimir Nowak <krnowak@openismus.com>
*
* Rygel is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Rygel is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
using GUPnP;
using Gee;
// Helper class for building ContentDirectory LastChange messages
internal class Rygel.LastChange : Object {
private const string HEADER =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<StateEvent " +
"xmlns=\"urn:schemas-upnp-org:av:cds-event\" " +
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
"xsi:schemaLocation=\"" +
"urn:schemas-upnp-org:av:cds-event" +
"http://www.upnp.org/schemas/av/cds-events.xsd\">";
private const string FOOTER = "</StateEvent>";
private LinkedList<LastChangeEntry> entries;
private StringBuilder str;
private bool update;
private bool clear_on_add;
public LastChange () {
this.entries = new LinkedList<LastChangeEntry> ();
this.str = new StringBuilder ();
this.update = true;
this.clear_on_add = false;
}
public void add_event (LastChangeEntry entry) {
if (this.clear_on_add) {
this.entries.clear ();
}
this.entries.add (entry);
this.update = true;
}
public void clear_on_new_event () {
this.clear_on_add = true;
}
public string get_log () {
if (this.update) {
this.str.erase ();
this.str.append (HEADER);
foreach (LastChangeEntry entry in this.entries) {
str.append (entry.to_string ());
}
this.str.append (FOOTER);
this.update = false;
}
return this.str.str;
}
}
|