Switch to unified view

a/libupnpp/description.hxx b/libupnpp/description.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 _UPNPDEV_HXX_INCLUDED_
17
#ifndef _UPNPDEV_HXX_INCLUDED_
18
#define _UPNPDEV_HXX_INCLUDED_
18
#define _UPNPDEV_HXX_INCLUDED_
19
19
20
/**
20
/**
...
...
30
30
31
/**
31
/**
32
 * Data holder for a UPnP service, parsed from the XML description
32
 * Data holder for a UPnP service, parsed from the XML description
33
 * downloaded after discovery yielded its URL.
33
 * downloaded after discovery yielded its URL.
34
 */
34
 */
35
class UPnPService {
35
class UPnPServiceDesc {
36
public:
36
public:
37
  // e.g. urn:schemas-upnp-org:service:ConnectionManager:1
37
    // e.g. urn:schemas-upnp-org:service:ConnectionManager:1
38
  std::string serviceType;
38
    std::string serviceType;
39
  // Unique Id inside device: e.g here THE ConnectionManager
39
    // Unique Id inside device: e.g here THE ConnectionManager
40
  std::string serviceId; // e.g. urn:upnp-org:serviceId:ConnectionManager
40
    std::string serviceId; // e.g. urn:upnp-org:serviceId:ConnectionManager
41
  std::string SCPDURL; // Service description URL. e.g.: cm.xml
41
    std::string SCPDURL; // Service description URL. e.g.: cm.xml
42
  std::string controlURL; // e.g.: /upnp/control/cm
42
    std::string controlURL; // e.g.: /upnp/control/cm
43
  std::string eventSubURL; // e.g.: /upnp/event/cm
43
    std::string eventSubURL; // e.g.: /upnp/event/cm
44
44
45
  void clear()
45
    void clear()
46
  {
46
    {
47
        serviceType.clear();
47
        serviceType.clear();
48
        serviceId.clear();
48
        serviceId.clear();
49
        SCPDURL.clear();
49
        SCPDURL.clear();
50
        controlURL.clear();
50
        controlURL.clear();
51
        eventSubURL.clear();
51
        eventSubURL.clear();
52
    }
52
    }
53
53
  std::string dump() const
54
    std::string dump() const
54
  {
55
    {
55
        std::ostringstream os;
56
        std::ostringstream os;
56
        os << "SERVICE {serviceType [" << serviceType <<
57
        os << "SERVICE {serviceType [" << serviceType <<
57
            "] serviceId [" << serviceId <<
58
            "] serviceId [" << serviceId <<
58
            "] SCPDURL [" << SCPDURL <<
59
            "] SCPDURL [" << SCPDURL <<
59
            "] controlURL [" << controlURL <<
60
            "] controlURL [" << controlURL <<
...
...
67
 * Data holder for a UPnP device, parsed from the XML description obtained
68
 * Data holder for a UPnP device, parsed from the XML description obtained
68
 * during discovery.
69
 * during discovery.
69
 * A device may include several services. To be of interest to us,
70
 * A device may include several services. To be of interest to us,
70
 * one of them must be a ContentDirectory.
71
 * one of them must be a ContentDirectory.
71
 */
72
 */
72
class UPnPDevice {
73
class UPnPDeviceDesc {
73
public:
74
public:
74
  /** Build device from xml description downloaded from discovery
75
    /** Build device from xml description downloaded from discovery
75
   * @param url where the description came from
76
     * @param url where the description came from
76
   * @param description the xml device description
77
     * @param description the xml device description
77
   */
78
     */
78
  UPnPDevice(const string& url, const string& description);
79
    UPnPDeviceDesc(const string& url, const string& description);
79
80
80
  UPnPDevice() : ok(false) {}
81
    UPnPDeviceDesc() : ok(false) {}
81
82
82
  bool ok;
83
    bool ok;
83
  // e.g. urn:schemas-upnp-org:device:MediaServer:1
84
    // e.g. urn:schemas-upnp-org:device:MediaServer:1
84
  std::string deviceType;
85
    std::string deviceType;
85
  // e.g. MediaTomb
86
    // e.g. MediaTomb
86
  std::string friendlyName;
87
    std::string friendlyName;
87
  // Unique device number. This should match the deviceID in the
88
    // Unique device number. This should match the deviceID in the
88
  // discovery message. e.g. uuid:a7bdcd12-e6c1-4c7e-b588-3bbc959eda8d
89
    // discovery message. e.g. uuid:a7bdcd12-e6c1-4c7e-b588-3bbc959eda8d
89
  std::string UDN;
90
    std::string UDN;
90
  // Base for all relative URLs. e.g. http://192.168.4.4:49152/
91
    // Base for all relative URLs. e.g. http://192.168.4.4:49152/
91
  std::string URLBase;
92
    std::string URLBase;
92
  // Manufacturer: e.g. D-Link, PacketVideo ("manufacturer")
93
    // Manufacturer: e.g. D-Link, PacketVideo ("manufacturer")
93
  std::string manufacturer;
94
    std::string manufacturer;
94
  // Model name: e.g. MediaTomb, DNS-327L ("modelName")
95
    // Model name: e.g. MediaTomb, DNS-327L ("modelName")
95
  std::string modelName;
96
    std::string modelName;
96
  // Services provided by this device.
97
    // Services provided by this device.
97
  std::vector<UPnPService> services;
98
    std::vector<UPnPServiceDesc> services;
98
99
99
  std::string dump() const
100
    std::string dump() const
100
  {
101
    {
101
        std::ostringstream os;
102
        std::ostringstream os;
102
        os << "DEVICE " << " {deviceType [" << deviceType <<
103
        os << "DEVICE " << " {deviceType [" << deviceType <<
103
            "] friendlyName [" << friendlyName <<
104
            "] friendlyName [" << friendlyName <<
104
            "] UDN [" << UDN <<
105
            "] UDN [" << UDN <<
105
            "] URLBase [" << URLBase << "] Services:" << std::endl;
106
            "] URLBase [" << URLBase << "] Services:" << std::endl;
106
      for (std::vector<UPnPService>::const_iterator it = services.begin();
107
      for (auto& serv: services) {
107
           it != services.end(); it++) {
108
          os << "    " << serv.dump();
108
          os << it->dump();
109
        }
109
        }
110
        os << "}" << std::endl;
110
        os << "}" << std::endl;
111
        return os.str();
111
        return os.str();
112
    }
112
    }
113
};
113
};
114
114
115
typedef std::vector<UPnPService>::iterator DevServIt;
115
typedef std::vector<UPnPServiceDesc>::iterator DevServIt;
116
116
117
#endif /* _UPNPDEV_HXX_INCLUDED_ */
117
#endif /* _UPNPDEV_HXX_INCLUDED_ */
118
/* Local Variables: */
119
/* mode: c++ */
120
/* c-basic-offset: 4 */
121
/* tab-width: 4 */
122
/* indent-tabs-mode: t */
123
/* End: */