|
a/libupnpp/cdircontent.hxx |
|
b/libupnpp/cdircontent.hxx |
1 |
/* Copyright (C) 2013 J.F.Dockes
|
1 |
/* Copyright (C) 2013 J.F.Dockes
|
2 |
* This program is free software; you can redistribute it and/or modify
|
2 |
* This program is free software; you can redistribute it and/or modify
|
3 |
* it under the terms of the GNU General Public License as published by
|
3 |
* it under the terms of the GNU General Public License as published by
|
4 |
* the Free Software Foundation; either version 2 of the License, or
|
4 |
* the Free Software Foundation; either version 2 of the License, or
|
5 |
* (at your option) any later version.
|
5 |
* (at your option) any later version.
|
6 |
*
|
6 |
*
|
7 |
* This program is distributed in the hope that it will be useful,
|
7 |
* This program is distributed in the hope that it will be useful,
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
10 |
* GNU General Public License for more details.
|
10 |
* GNU General Public License for more details.
|
11 |
*
|
11 |
*
|
12 |
* You should have received a copy of the GNU General Public License
|
12 |
* You should have received a copy of the GNU General Public License
|
13 |
* along with this program; if not, write to the
|
13 |
* along with this program; if not, write to the
|
14 |
* Free Software Foundation, Inc.,
|
14 |
* Free Software Foundation, Inc.,
|
15 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
15 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
16 |
*/
|
16 |
*/
|
17 |
#ifndef _UPNPDIRCONTENT_H_X_INCLUDED_
|
17 |
#ifndef _UPNPDIRCONTENT_H_X_INCLUDED_
|
18 |
#define _UPNPDIRCONTENT_H_X_INCLUDED_
|
18 |
#define _UPNPDIRCONTENT_H_X_INCLUDED_
|
19 |
|
19 |
|
20 |
#include <string>
|
20 |
#include <string>
|
21 |
#include <vector>
|
21 |
#include <vector>
|
22 |
#include <map>
|
22 |
#include <map>
|
23 |
#include <sstream>
|
23 |
#include <sstream>
|
24 |
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* UPnP resource. A resource describes one of the entities associated with
|
|
|
27 |
* a directory entry. This would be typically the audio file URI, and
|
|
|
28 |
* its characteristics (sample rate etc.) as attributes, but there can
|
|
|
29 |
* be several resources associated to one entry, for example for
|
|
|
30 |
* multiple encoding formats.
|
|
|
31 |
*/
|
|
|
32 |
class UPnPResource {
|
|
|
33 |
public:
|
|
|
34 |
// Value
|
|
|
35 |
std::string m_uri;
|
|
|
36 |
// Attributes
|
|
|
37 |
std::map<std::string, std::string> m_props;
|
|
|
38 |
};
|
|
|
39 |
|
25 |
/**
|
40 |
/**
|
26 |
* UpnP Media Server directory entry, converted from XML data.
|
41 |
* UPnP Media Server directory entry, converted from XML data.
|
27 |
*
|
42 |
*
|
28 |
* This is a dumb data holder class, a struct with helpers.
|
43 |
* This is a dumb data holder class, a struct with helpers.
|
29 |
*/
|
44 |
*/
|
30 |
class UPnPDirObject {
|
45 |
class UPnPDirObject {
|
31 |
public:
|
46 |
public:
|
32 |
enum ObjType {item, container};
|
47 |
enum ObjType {item, container};
|
33 |
// There are actually several kinds of containers:
|
48 |
// There are actually several kinds of containers:
|
34 |
// object.container.storageFolder, object.container.person,
|
49 |
// object.container.storageFolder, object.container.person,
|
35 |
// object.container.playlistContainer etc., but they all seem to
|
50 |
// object.container.playlistContainer etc., but they all seem to
|
36 |
// behave the same as far as we're concerned. Otoh, musicTrack
|
51 |
// behave the same as far as we're concerned. Otoh, musicTrack
|
37 |
// items are special to us, and so should playlists, but I've not
|
52 |
// items are special to us, and so should playlists, but I've not
|
38 |
// seen one of the latter yet (servers seem to use containers for
|
53 |
// seen one of the latter yet (servers seem to use containers for
|
39 |
// playlists).
|
54 |
// playlists).
|
40 |
enum ItemClass {audioItem_musicTrack, audioItem_playlist};
|
55 |
enum ItemClass {audioItem_musicTrack, audioItem_playlist};
|
41 |
|
56 |
|
42 |
std::string m_id; // ObjectId
|
57 |
std::string m_id; // ObjectId
|
43 |
std::string m_pid; // Parent ObjectId
|
58 |
std::string m_pid; // Parent ObjectId
|
44 |
std::string m_title; // dc:title. Directory name for a container.
|
59 |
std::string m_title; // dc:title. Directory name for a container.
|
45 |
ObjType m_type; // item or container
|
60 |
ObjType m_type; // item or container
|
46 |
ItemClass m_iclass;
|
61 |
ItemClass m_iclass;
|
47 |
// Properties as gathered from the XML document (url, artist, etc.)
|
62 |
// Properties as gathered from the XML document (url, artist, etc.),
|
|
|
63 |
// except for title which has a proper field.
|
48 |
// The map keys are the XML tag or attribute names.
|
64 |
// The map keys are the XML tag names
|
49 |
std::map<std::string, std::string> m_props;
|
65 |
std::map<std::string, std::string> m_props;
|
50 |
|
66 |
|
51 |
/** Get named property
|
67 |
std::vector<UPnPResource> m_resources;
|
52 |
* @param property name (e.g. upnp:artist, upnp:album,
|
|
|
53 |
* upnp:originalTrackNumber, upnp:genre). Use m_title instead
|
|
|
54 |
* for dc:title.
|
|
|
55 |
* @param[out] value
|
|
|
56 |
* @return true if found.
|
|
|
57 |
*/
|
|
|
58 |
bool getprop(const string& name, string& value) const
|
|
|
59 |
{
|
|
|
60 |
std::map<std::string, std::string>::const_iterator it =
|
|
|
61 |
m_props.find(name);
|
|
|
62 |
if (it == m_props.end())
|
|
|
63 |
return false;
|
|
|
64 |
value = it->second;
|
|
|
65 |
return true;
|
|
|
66 |
}
|
|
|
67 |
|
68 |
|
|
|
69 |
/** Get named property
|
|
|
70 |
* @param property name (e.g. upnp:artist, upnp:album,
|
|
|
71 |
* upnp:originalTrackNumber, upnp:genre). Use m_title instead
|
|
|
72 |
* for dc:title.
|
|
|
73 |
* @param[out] value
|
|
|
74 |
* @return true if found.
|
|
|
75 |
*/
|
|
|
76 |
bool getprop(const string& name, string& value) const
|
|
|
77 |
{
|
|
|
78 |
std::map<std::string, std::string>::const_iterator it =
|
|
|
79 |
m_props.find(name);
|
|
|
80 |
if (it == m_props.end())
|
|
|
81 |
return false;
|
|
|
82 |
value = it->second;
|
|
|
83 |
return true;
|
|
|
84 |
}
|
|
|
85 |
|
68 |
void clear()
|
86 |
void clear()
|
69 |
{
|
87 |
{
|
70 |
m_id.clear();
|
88 |
m_id.clear();
|
71 |
m_pid.clear();
|
89 |
m_pid.clear();
|
72 |
m_title.clear();
|
90 |
m_title.clear();
|
73 |
m_type = (ObjType)-1;
|
91 |
m_type = (ObjType)-1;
|
74 |
m_iclass = (ItemClass)-1;
|
92 |
m_iclass = (ItemClass)-1;
|
75 |
m_props.clear();
|
93 |
m_props.clear();
|
76 |
}
|
94 |
m_resources.clear();
|
|
|
95 |
}
|
|
|
96 |
|
77 |
std::string dump()
|
97 |
std::string dump()
|
78 |
{
|
98 |
{
|
79 |
std::ostringstream os;
|
99 |
std::ostringstream os;
|
80 |
os << "UPnPDirObject: id [" << m_id << "] pid [" << m_pid <<
|
100 |
os << "UPnPDirObject: " << (m_type == item ? "item" : "container") <<
|
81 |
"] title [" << m_title << "] type [" <<
|
101 |
" id [" << m_id << "] pid [" << m_pid <<
|
82 |
(m_type == item ? "item" : "container") <<
|
102 |
"] title [" << m_title << "]" << std::endl;
|
83 |
"] properties: " << std::endl;
|
103 |
os << "Properties: " << std::endl;
|
84 |
for (std::map<std::string,std::string>::const_iterator it =
|
104 |
for (auto& entry: m_props) {
|
85 |
m_props.begin(); it != m_props.end(); it++) {
|
|
|
86 |
os << "[" << it->first << "]->[" << it->second << "] "
|
105 |
os << "[" << entry.first << "]->[" << entry.second << "] "
|
87 |
<< std::endl;
|
106 |
<< std::endl;
|
88 |
}
|
107 |
}
|
|
|
108 |
os << "Resources:" << std::endl;
|
|
|
109 |
for (auto& res: m_resources) {
|
|
|
110 |
os << " Uri [" << res.m_uri << "]" << std::endl;
|
|
|
111 |
os << " Resource attributes:" << std::endl;
|
|
|
112 |
for (auto& entry: res.m_props) {
|
|
|
113 |
os << " [" << entry.first << "]->[" << entry.second << "] "
|
|
|
114 |
<< std::endl;
|
|
|
115 |
}
|
|
|
116 |
}
|
89 |
os << std::endl;
|
117 |
os << std::endl;
|
90 |
return os.str();
|
118 |
return os.str();
|
91 |
}
|
119 |
}
|
92 |
};
|
120 |
};
|
93 |
|
121 |
|
94 |
/**
|
122 |
/**
|
95 |
* Image of a MediaServer Directory Service container (directory),
|
123 |
* Image of a MediaServer Directory Service container (directory),
|
96 |
* possibly containing items and subordinate containers.
|
124 |
* possibly containing items and subordinate containers.
|
97 |
*/
|
125 |
*/
|
98 |
class UPnPDirContent {
|
126 |
class UPnPDirContent {
|
99 |
public:
|
127 |
public:
|
100 |
std::vector<UPnPDirObject> m_containers;
|
128 |
std::vector<UPnPDirObject> m_containers;
|
101 |
std::vector<UPnPDirObject> m_items;
|
129 |
std::vector<UPnPDirObject> m_items;
|
102 |
|
130 |
|
103 |
/**
|
131 |
/**
|
104 |
* Parse from DIDL-Lite XML data.
|
132 |
* Parse from DIDL-Lite XML data.
|
105 |
*
|
133 |
*
|
106 |
* Normally only used by ContentDirectoryService::readDir()
|
134 |
* Normally only used by ContentDirectoryService::readDir()
|
107 |
* This is cumulative: in general, the XML data is obtained in
|
135 |
* This is cumulative: in general, the XML data is obtained in
|
108 |
* several documents corresponding to (offset,count) slices of the
|
136 |
* several documents corresponding to (offset,count) slices of the
|
109 |
* directory (container). parse() can be called repeatedly with
|
137 |
* directory (container). parse() can be called repeatedly with
|
110 |
* the successive XML documents and will accumulate entries in the item
|
138 |
* the successive XML documents and will accumulate entries in the item
|
111 |
* and container vectors. This makes more sense if the different
|
139 |
* and container vectors. This makes more sense if the different
|
112 |
* chunks are from the same container, but given that UPnP Ids are
|
140 |
* chunks are from the same container, but given that UPnP Ids are
|
113 |
* actually global, nothing really bad will happen if you mix
|
141 |
* actually global, nothing really bad will happen if you mix
|
114 |
* up...
|
142 |
* up...
|
115 |
*/
|
143 |
*/
|
116 |
bool parse(const std::string& didltext);
|
144 |
bool parse(const std::string& didltext);
|
117 |
};
|
145 |
};
|
118 |
|
146 |
|
119 |
#endif /* _UPNPDIRCONTENT_H_X_INCLUDED_ */
|
147 |
#endif /* _UPNPDIRCONTENT_H_X_INCLUDED_ */
|
120 |
/* Local Variables: */
|
|
|
121 |
/* mode: c++ */
|
|
|
122 |
/* c-basic-offset: 4 */
|
|
|
123 |
/* tab-width: 4 */
|
|
|
124 |
/* indent-tabs-mode: t */
|
|
|
125 |
/* End: */
|
|
|