Switch to unified view

a/src/upmpd.hxx b/src/upmpd.hxx
1
/* Copyright (C) 2014 J.F.Dockes
1
/* Copyright (C) 2014 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
17
18
#ifndef _UPMPD_H_X_INCLUDED_
18
#ifndef _UPMPD_H_X_INCLUDED_
19
#define _UPMPD_H_X_INCLUDED_
19
#define _UPMPD_H_X_INCLUDED_
20
20
21
#include <string>
21
#include <string>
22
#include <unordered_map>
22
#include <unordered_map>
23
#include <vector>
23
#include <vector>
24
#include <unordered_set>
24
25
25
#include "libupnpp/device/device.hxx"
26
#include "libupnpp/device/device.hxx"
26
#include "libupnpp/ptmutex.hxx"
27
#include "libupnpp/ptmutex.hxx"
27
28
28
class MPDCli;
29
class MPDCli;
...
...
32
extern std::string g_datadir;
33
extern std::string g_datadir;
33
class ConfSimple;
34
class ConfSimple;
34
extern UPnPP::PTMutexInit g_configlock;
35
extern UPnPP::PTMutexInit g_configlock;
35
extern ConfSimple *g_config;
36
extern ConfSimple *g_config;
36
extern std::string g_protocolInfo;
37
extern std::string g_protocolInfo;
38
extern std::unordered_set<std::string> g_supportedFormats;
37
39
38
typedef struct ohInfoDesc {
40
typedef struct ohInfoDesc {
39
  std::string name;
41
    std::string name;
40
  std::string info;
42
    std::string info;
41
  std::string url;
43
    std::string url;
42
  std::string imageUri;
44
    std::string imageUri;
43
} ohInfoDesc_t;
45
} ohInfoDesc_t;
44
46
45
typedef struct ohProductDesc {
47
typedef struct ohProductDesc {
46
  ohInfoDesc_t manufacturer;
48
    ohInfoDesc_t manufacturer;
47
  ohInfoDesc_t model;
49
    ohInfoDesc_t model;
48
  ohInfoDesc_t product;
50
    ohInfoDesc_t product;
49
  std::string room;
51
    std::string room;
50
} ohProductDesc_t;
52
} ohProductDesc_t;
51
53
52
using namespace UPnPProvider;
54
using namespace UPnPProvider;
53
55
56
class UpSong;
54
class UpMpdRenderCtl;
57
class UpMpdRenderCtl;
55
class UpMpdAVTransport;
58
class UpMpdAVTransport;
56
class OHInfo;
59
class OHInfo;
57
class OHPlaylist;
60
class OHPlaylist;
58
class OHProduct;
61
class OHProduct;
...
...
70
    friend class OHProduct;
73
    friend class OHProduct;
71
    friend class OHReceiver;
74
    friend class OHReceiver;
72
    friend class OHVolume;
75
    friend class OHVolume;
73
    friend class SenderReceiver;
76
    friend class SenderReceiver;
74
    friend class OHRadio;
77
    friend class OHRadio;
75
    
78
76
    enum OptFlags {
79
    enum OptFlags {
77
        upmpdNone = 0,
80
        upmpdNone = 0,
78
        // If set, the MPD queue belongs to us, we shall clear
81
        // If set, the MPD queue belongs to us, we shall clear
79
        // it as we like.
82
        // it as we like.
80
        upmpdOwnQueue = 1, 
83
        upmpdOwnQueue = 1,
81
        // Export OpenHome services
84
        // Export OpenHome services
82
        upmpdDoOH = 2,
85
        upmpdDoOH = 2,
83
        // Save queue metadata to disk for persistence across restarts
86
        // Save queue metadata to disk for persistence across restarts
84
        // (mpd does it)
87
        // (mpd does it)
85
        upmpdOhMetaPersist = 4,
88
        upmpdOhMetaPersist = 4,
...
...
87
        upmpdOhReceiver = 8,
90
        upmpdOhReceiver = 8,
88
        // Do not publish UPnP AV services (avtransport and renderer).
91
        // Do not publish UPnP AV services (avtransport and renderer).
89
        upmpdNoAV = 16,
92
        upmpdNoAV = 16,
90
        // mpd2sc et al were found: advertise songcast sender/receiver mode
93
        // mpd2sc et al were found: advertise songcast sender/receiver mode
91
        upmpdOhSenderReceiver = 32,
94
        upmpdOhSenderReceiver = 32,
95
        // Do not check content format from input metadata against our protocolinfo
96
        upmpdNoContentFormatCheck = 64,
92
    };
97
    };
93
    struct Options {
98
    struct Options {
94
        Options() : options(upmpdNone), ohmetasleep(0), schttpport(0),
99
        Options() : options(upmpdNone), ohmetasleep(0), schttpport(0),
95
                    sendermpdport(0) {}
100
            sendermpdport(0) {}
96
        unsigned int options;
101
        unsigned int options;
97
        std::string  cachefn;
102
        std::string  cachefn;
98
        std::string  radioconf;
103
        std::string  radioconf;
99
        unsigned int ohmetasleep;
104
        unsigned int ohmetasleep;
100
        int schttpport;
105
        int schttpport;
...
...
107
          ohProductDesc_t& ohProductDesc,
112
          ohProductDesc_t& ohProductDesc,
108
          const std::unordered_map<std::string, VDirContent>& files,
113
          const std::unordered_map<std::string, VDirContent>& files,
109
          MPDCli *mpdcli, Options opts);
114
          MPDCli *mpdcli, Options opts);
110
    ~UpMpd();
115
    ~UpMpd();
111
116
112
    const MpdStatus &getMpdStatus();
117
    const MpdStatus& getMpdStatus();
113
    const MpdStatus &getMpdStatusNoUpdate()
118
    const MpdStatus& getMpdStatusNoUpdate() {
114
        {
115
            if (m_mpds == 0)
119
        if (m_mpds == 0) {
116
                return getMpdStatus();
120
            return getMpdStatus();
117
            else
121
        } else {
118
                return *m_mpds;
122
            return *m_mpds;
119
        }
123
        }
124
    }
120
125
121
    const std::string& getMetaCacheFn()
126
    const std::string& getMetaCacheFn() {
122
        {
123
            return m_mcachefn;
127
        return m_mcachefn;
124
        }
128
    }
125
129
130
    // Check that the metadata resource element matching the uri is
131
    // present in the input set. Convert the metadata to an mpdcli song
132
    // while we are at it.
133
    bool checkContentFormat(const std::string& uri, const std::string& didl,
134
                            UpSong *ups = 0);
135
    
126
private:
136
private:
127
    MPDCli *m_mpdcli;
137
    MPDCli *m_mpdcli;
128
    const MpdStatus *m_mpds;
138
    const MpdStatus *m_mpds;
129
    unsigned int m_options;
139
    unsigned int m_options;
130
    std::string m_mcachefn;
140
    std::string m_mcachefn;