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 "libupnpp/config.h"
22 
23 #include <unordered_map>
24 #include <set>
25 #include <string>
26 #include <vector>
27 
28 #include "libupnpp/control/service.hxx"
29 
30 
31 namespace UPnPClient {
32 
33 class ContentDirectory;
34 class UPnPDeviceDesc;
35 class UPnPDirContent;
36 class UPnPServiceDesc;
37 
38 typedef std::shared_ptr<ContentDirectory> CDSH;
39 
56 class ContentDirectory : public Service {
57 public:
58 
60  ContentDirectory(const UPnPDeviceDesc& dev, const UPnPServiceDesc& srv);
61  virtual ~ContentDirectory() {}
62 
65 
66  enum ServiceKind {CDSKIND_UNKNOWN, CDSKIND_BUBBLE, CDSKIND_MEDIATOMB,
67  CDSKIND_MINIDLNA, CDSKIND_MINIM, CDSKIND_TWONKY
68  };
69 
70  ServiceKind getKind() {
71  return m_serviceKind;
72  }
73 
75  static bool isCDService(const std::string& st);
76  virtual bool serviceTypeMatch(const std::string& tp);
77 
79  static bool getServices(std::vector<CDSH>&);
80 
82  static bool getServerByName(const std::string& friendlyName,
83  CDSH& server);
84 
91  int readDir(const std::string& objectId, UPnPDirContent& dirbuf);
92 
106  int readDirSlice(const std::string& objectId, int offset,
107  int count, UPnPDirContent& dirbuf,
108  int *didread, int *total);
109 
110  int goodSliceSize()
111  {
112  return m_rdreqcnt;
113  }
114 
126  int search(const std::string& objectId, const std::string& searchstring,
127  UPnPDirContent& dirbuf);
129  int searchSlice(const std::string& objectId,
130  const std::string& searchstring,
131  int offset, int count, UPnPDirContent& dirbuf,
132  int *didread, int *total);
133 
141  int getMetadata(const std::string& objectId, UPnPDirContent& dirbuf);
142 
149  int getSearchCapabilities(std::set<std::string>& result);
150 
151 protected:
152  virtual bool serviceInit(const UPnPDeviceDesc& device,
153  const UPnPServiceDesc& service);
154  /* My service type string */
155  static const std::string SType;
156 
157 private:
158  int m_rdreqcnt{200}; // Slice size to use when reading
159  ServiceKind m_serviceKind{CDSKIND_UNKNOWN};
160 
161  void evtCallback(const std::unordered_map<std::string, std::string>&);
162  void registerCallback();
163 };
164 
165 }
166 
167 #endif /* _UPNPDIR_HXX_INCLUDED_ */
int readDir(const std::string &objectId, UPnPDirContent &dirbuf)
Read a full container&#39;s children list.
Definition: cdirectory.cxx:288
static bool getServices(std::vector< CDSH > &)
Retrieve the directory services currently seen on the network.
Definition: cdirectory.cxx:207
Definition: service.hxx:73
int getSearchCapabilities(std::set< std::string > &result)
Retrieve search capabilities.
Definition: cdirectory.cxx:378
int readDirSlice(const std::string &objectId, int offset, int count, UPnPDirContent &dirbuf, int *didread, int *total)
Read a partial slice of a container&#39;s children list.
Definition: cdirectory.cxx:240
ContentDirectory()
An empty one.
Definition: cdirectory.hxx:64
int search(const std::string &objectId, const std::string &searchstring, UPnPDirContent &dirbuf)
Search the content directory service.
Definition: cdirectory.cxx:354
static bool isCDService(const std::string &st)
Test service type from discovery message.
Definition: cdirectory.cxx:56
int searchSlice(const std::string &objectId, const std::string &searchstring, int offset, int count, UPnPDirContent &dirbuf, int *didread, int *total)
Same to search() as readDirSlice to readDir()
Definition: cdirectory.cxx:311
static bool getServerByName(const std::string &friendlyName, CDSH &server)
Retrieve specific service designated by its friendlyName.
Definition: cdirectory.cxx:216
int getMetadata(const std::string &objectId, UPnPDirContent &dirbuf)
Read metadata for a given node.
Definition: cdirectory.cxx:409
Image of a MediaServer Directory Service container (directory), possibly containing items and subordi...
Definition: cdircontent.hxx:240
virtual bool serviceTypeMatch(const std::string &tp)
Perform a comparison to the service type string for this specific service.
Definition: cdirectory.cxx:61
Content Directory Service client class.
Definition: cdirectory.hxx:56
Data holder for a UPnP service, parsed from the device XML description.
Definition: description.hxx:46
virtual bool serviceInit(const UPnPDeviceDesc &device, const UPnPServiceDesc &service)
Service-specific part of initialization.
Definition: cdirectory.cxx:172
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:28