libupnpp  0.16.0
A C++ wrapper for the Portable UPnP reference library
cdirectory.hxx
1 /* Copyright (C) 2006-2016 J.F.Dockes
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16  * 02110-1301 USA
17  */
18 #ifndef _UPNPDIR_HXX_INCLUDED_
19 #define _UPNPDIR_HXX_INCLUDED_
20 
21 #include <unordered_map>
22 #include <set>
23 #include <string>
24 #include <vector>
25 
26 #include "libupnpp/control/service.hxx"
27 
28 namespace UPnPClient {
29 
30 class ContentDirectory;
31 class UPnPDeviceDesc;
32 class UPnPDirContent;
33 class UPnPServiceDesc;
34 
35 typedef std::shared_ptr<ContentDirectory> CDSH;
36 
53 class UPNPP_API ContentDirectory : public Service {
54 public:
55 
57  ContentDirectory(const UPnPDeviceDesc& dev, const UPnPServiceDesc& srv);
58  virtual ~ContentDirectory() {}
59 
62 
63  enum ServiceKind {CDSKIND_UNKNOWN, CDSKIND_BUBBLE, CDSKIND_MEDIATOMB,
64  CDSKIND_MINIDLNA, CDSKIND_MINIM, CDSKIND_TWONKY
65  };
66 
67  ServiceKind getKind() {
68  return m_serviceKind;
69  }
70 
72  static bool isCDService(const std::string& st);
73  virtual bool serviceTypeMatch(const std::string& tp);
74 
76  static bool getServices(std::vector<CDSH>&);
77 
79  static bool getServerByName(const std::string& friendlyName,
80  CDSH& server);
81 
88  int readDir(const std::string& objectId, UPnPDirContent& dirbuf);
89 
103  int readDirSlice(const std::string& objectId, int offset,
104  int count, UPnPDirContent& dirbuf,
105  int *didread, int *total);
106 
107  int goodSliceSize()
108  {
109  return m_rdreqcnt;
110  }
111 
123  int search(const std::string& objectId, const std::string& searchstring,
124  UPnPDirContent& dirbuf);
126  int searchSlice(const std::string& objectId,
127  const std::string& searchstring,
128  int offset, int count, UPnPDirContent& dirbuf,
129  int *didread, int *total);
130 
138  int getMetadata(const std::string& objectId, UPnPDirContent& dirbuf);
139 
146  int getSearchCapabilities(std::set<std::string>& result);
147 
148 protected:
149  virtual bool serviceInit(const UPnPDeviceDesc& device,
150  const UPnPServiceDesc& service);
151  /* My service type string */
152  static const std::string SType;
153 
154 private:
155  int m_rdreqcnt{200}; // Slice size to use when reading
156  ServiceKind m_serviceKind{CDSKIND_UNKNOWN};
157 
158  void UPNPP_LOCAL
159  evtCallback(const std::unordered_map<std::string, std::string>&);
160  void UPNPP_LOCAL registerCallback();
161 };
162 
163 }
164 
165 #endif /* _UPNPDIR_HXX_INCLUDED_ */
Definition: service.hxx:82
ContentDirectory()
An empty one.
Definition: cdirectory.hxx:61
Image of a MediaServer Directory Service container (directory), possibly containing items and subordi...
Definition: cdircontent.hxx:286
Content Directory Service client class.
Definition: cdirectory.hxx:53
Data holder for a UPnP service, parsed from the device XML description.
Definition: description.hxx:46
Data holder for a UPnP device, parsed from the XML description obtained during discovery.
Definition: description.hxx:142
UPnP Description phase: interpreting the device description which we downloaded from the URL obtained...
Definition: avlastchg.cxx:27