Switch to unified view

a/libupnpp/control/cdircontent.hxx b/libupnpp/control/cdircontent.hxx
...
...
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
#include "libupnpp/upnpavutils.hxx"
26
25
/** 
27
/** 
26
 * UPnP resource. A resource describes one of the entities associated with 
28
 * UPnP resource. A resource describes one of the entities associated with 
27
 * a directory entry. This would be typically the audio file URI, and
29
 * a directory entry. This would be typically the audio file URI, and
28
 * its characteristics (sample rate etc.) as attributes, but there can
30
 * its characteristics (sample rate etc.) as attributes, but there can
29
 * be several resources associated to one entry, for example for
31
 * be several resources associated to one entry, for example for
...
...
34
    // Value
36
    // Value
35
    std::string m_uri;
37
    std::string m_uri;
36
    // Attributes
38
    // Attributes
37
    std::map<std::string, std::string> m_props;
39
    std::map<std::string, std::string> m_props;
38
};
40
};
41
42
class UPnPDirParser;
39
43
40
/**
44
/**
41
 * UPnP Media Server directory entry, converted from XML data.
45
 * UPnP Media Server directory entry, converted from XML data.
42
 *
46
 *
43
 * This is a dumb data holder class, a struct with helpers.
47
 * This is a dumb data holder class, a struct with helpers.
...
...
62
    // Properties as gathered from the XML document (url, artist, etc.),
66
    // Properties as gathered from the XML document (url, artist, etc.),
63
    // except for title which has a proper field.
67
    // except for title which has a proper field.
64
    // The map keys are the XML tag names
68
    // The map keys are the XML tag names
65
    std::map<std::string, std::string> m_props;
69
    std::map<std::string, std::string> m_props;
66
70
67
    // Resource URIs: there may be several, for example for different
71
    // Resources: there may be several, for example for different
68
    // audio formats of the same track
72
    // audio formats of the same track, each with an URI and descriptor fields
69
    std::vector<UPnPResource> m_resources;
73
    std::vector<UPnPResource> m_resources;
70
74
71
    /** Get named property
75
    /** Get named property
72
     * @param property name (e.g. upnp:artist, upnp:album,
76
     * @param property name (e.g. upnp:artist, upnp:album,
73
     *     upnp:originalTrackNumber, upnp:genre). Use m_title instead
77
     *     upnp:originalTrackNumber, upnp:genre). Use m_title instead
...
...
82
        if (it == m_props.end())
86
        if (it == m_props.end())
83
            return false;
87
            return false;
84
        value = it->second;
88
        value = it->second;
85
        return true;
89
        return true;
86
    }
90
    }
91
92
    /** Get named property for resource 
93
     * Field names: "bitrate", "duration" (H:mm:ss.ms), "nrAudioChannels",
94
     * "protocolInfo", "sampleFrequency" (Hz), "size" (bytes)
95
     */
96
    bool getrprop(unsigned int ridx, const std::string& nm, std::string& val) 
97
    const
87
    
98
    {
99
        if (ridx >= m_resources.size())
100
            return false;
101
        std::map<std::string, std::string>::const_iterator it =
102
            m_resources[ridx].m_props.find(nm);
103
        if (it == m_resources[ridx].m_props.end())
104
            return false;
105
        val = it->second;
106
        return true;
107
108
    }
109
110
    int getDurationSeconds(unsigned ridx = 0)
111
    {
112
        std::string sdur;
113
        if (!getrprop(ridx, "duration", sdur)) {
114
            //?? Avoid returning 0, who knows...
115
            return 1;
116
        }
117
        return upnpdurationtos(sdur);
118
    }
119
120
    /** 
121
     * Get a DIDL document suitable for sending to a mediaserver. Only
122
     * works for items, not containers. The idea is that we may have
123
     * missed useful stuff while parsing the data from the content
124
     * directory, so we send the original if we can.
125
     */
126
    std::string getdidl();
127
88
    void clear()
128
    void clear()
89
    {
129
    {
90
        m_id.clear();
130
        m_id.clear();
91
        m_pid.clear();
131
        m_pid.clear();
92
        m_title.clear();
132
        m_title.clear();
93
        m_type = (ObjType)-1;
133
        m_type = (ObjType)-1;
94
        m_iclass = (ItemClass)-1;
134
        m_iclass = (ItemClass)-1;
95
        m_props.clear();
135
        m_props.clear();
96
        m_resources.clear();
136
        m_resources.clear();
137
        m_didlfrag.clear();
97
    }
138
    }
98
139
99
    std::string dump()
140
    std::string dump()
100
    {
141
    {
101
        std::ostringstream os;
142
        std::ostringstream os;
...
...
117
            }
158
            }
118
        }
159
        }
119
        os << std::endl;
160
        os << std::endl;
120
        return os.str();
161
        return os.str();
121
    }
162
    }
163
164
private:
165
    friend class UPnPDirParser;
166
    // didl text for element, sans header
167
    std::string m_didlfrag;
122
};
168
};
123
169
124
/**
170
/**
125
 * Image of a MediaServer Directory Service container (directory),
171
 * Image of a MediaServer Directory Service container (directory),
126
 * possibly containing items and subordinate containers.
172
 * possibly containing items and subordinate containers.