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
|
/*
* Copyright (C) 2012 Intel Corporation.
*
* Author: Jens Georg <jensg@openismus.com>
*
* This file is part of Rygel.
*
* 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;
public enum Rygel.SerializerType {
/// Normal serialization of container/item using DIDL-Lite
GENERIC_DIDL,
/// Special version of a DIDL-Lite document for playlists, defined by DLNA
DIDL_S,
/// M3UEXT format as used by various media players
M3UEXT
}
/**
* Proxy class hiding the different serializers (DIDL, DIDL_S, M3U) behind a
* single implementation.
*/
public class Rygel.Serializer : Object {
private DIDLLiteWriter writer;
private MediaCollection collection;
private M3UPlayList playlist;
// private properties
public SerializerType serializer_type { construct; private get; }
public Serializer (SerializerType type) {
Object (serializer_type: type);
}
public override void constructed () {
switch (this.serializer_type) {
case SerializerType.GENERIC_DIDL:
this.writer = new DIDLLiteWriter (null);
break;
case SerializerType.DIDL_S:
this.collection = new MediaCollection ();
break;
case SerializerType.M3UEXT:
this.playlist = new M3UPlayList ();
break;
default:
assert_not_reached ();
}
base.constructed ();
}
public DIDLLiteItem? add_item () {
switch (this.serializer_type) {
case SerializerType.GENERIC_DIDL:
return this.writer.add_item ();
case SerializerType.DIDL_S:
return this.collection.add_item ();
case SerializerType.M3UEXT:
return this.playlist.add_item ();
default:
return null;
}
}
public DIDLLiteContainer? add_container () {
if (this.writer != null) {
return this.writer.add_container ();
} else {
return null;
}
}
public void filter (string filter_string) {
if (writer != null) {
this.writer.filter (filter_string);
}
}
public string get_string () {
switch (this.serializer_type) {
case SerializerType.GENERIC_DIDL:
return this.writer.get_string ();
case SerializerType.DIDL_S:
return this.collection.get_string ();
case SerializerType.M3UEXT:
return this.playlist.get_string ();
default:
return "";
}
}
}
|