libupnpp  0.16.0
A C++ wrapper for the Portable UPnP reference library
service.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 _SERVICE_H_X_INCLUDED_
19 #define _SERVICE_H_X_INCLUDED_
20 
21 #include <sys/types.h>
22 
23 #include <functional>
24 #include <iostream>
25 #include <string>
26 
27 #include "libupnpp/upnppexports.hxx"
28 #include "libupnpp/log.hxx"
29 #include "libupnpp/soaphelp.hxx"
30 #include "libupnpp/upnperrcodes.hxx"
31 #include "libupnpp/control/cdircontent.hxx"
32 
33 namespace UPnPClient {
34 
35 class UPnPDeviceDesc;
36 class UPnPServiceDesc;
37 class Service;
38 
55 class UPNPP_API VarEventReporter {
56 public:
57  virtual ~VarEventReporter() {}
59  virtual void changed(const char *nm, int val) = 0;
61  virtual void changed(const char *nm, const char *val) = 0;
64  virtual void changed(const char * /*nm*/, UPnPDirObject /*meta*/) {}
66  virtual void changed(const char * /*nm*/, std::vector<int> /*ids*/) {}
69  virtual void autorenew_failed() {}
70 };
71 
78 typedef
79 std::function<void (const std::unordered_map<std::string, std::string>&)>
81 
82 class UPNPP_API Service {
83 public:
85  Service(const UPnPDeviceDesc& device, const UPnPServiceDesc& service);
86 
90  Service();
91 
92  virtual ~Service();
93 
101  bool initFromDescription(const UPnPDeviceDesc& description);
102 
107  virtual bool reSubscribe();
108 
111  const std::string& getFriendlyName() const;
112  const std::string& getDeviceId() const;
113  const std::string& getServiceType() const;
114  const std::string& getActionURL() const;
115  const std::string& getModelName() const;
116  const std::string& getManufacturer() const;
117 
124  virtual int runAction(const UPnPP::SoapOutgoing& args,
125  UPnPP::SoapIncoming& data);
126 
129  int runTrivialAction(const std::string& actionName);
130 
133  template <class T> int runSimpleGet(const std::string& actnm,
134  const std::string& valnm,
135  T *valuep);
136 
138  template <class T> int runSimpleAction(const std::string& actnm,
139  const std::string& valnm,
140  T value);
141 
148  virtual VarEventReporter *getReporter();
149 
154  virtual void installReporter(VarEventReporter* reporter);
155 
165  virtual bool serviceTypeMatch(const std::string& tp) = 0;
166 
167 protected:
168 
174  virtual bool serviceInit(const UPnPDeviceDesc&,
175  const UPnPServiceDesc&) {
176  return true;
177  }
178 
183  bool registerCallback(evtCBFunc c);
184 
192  virtual void registerCallback() {}
193 
195  void unregisterCallback();
196 
197 private:
198  // Can't copy these because this does not make sense for the
199  // member function callback.
200  Service(Service const&);
201  Service& operator=(Service const&);
202 
203  class UPNPP_LOCAL Internal;
204  Internal *m{nullptr};
205 };
206 
207 } // namespace UPnPClient
208 
209 #endif /* _SERVICE_H_X_INCLUDED_ */
std::function< void(const std::unordered_map< std::string, std::string > &)> evtCBFunc
Type of the event callbacks.
Definition: service.hxx:80
Store the values to be encoded in a SOAP response.
Definition: soaphelp.hxx:90
Decode incoming Soap call data.
Definition: soaphelp.hxx:35
virtual void changed(const char *, UPnPDirObject)
Report change to track metadata (parsed as as Content Directory entry).
Definition: service.hxx:64
Definition: service.hxx:82
virtual void registerCallback()
To be overridden in classes which actually support events.
Definition: service.hxx:192
Data holder for a UPnP service, parsed from the device XML description.
Definition: description.hxx:46
virtual bool serviceInit(const UPnPDeviceDesc &, const UPnPServiceDesc &)
Service-specific part of initialization.
Definition: service.hxx:174
UPnP Media Server directory entry, converted from XML data.
Definition: cdircontent.hxx:62
virtual void autorenew_failed()
Subscription autorenew failed.
Definition: service.hxx:69
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
To be implemented by upper-level client code for event reporting.
Definition: service.hxx:55
virtual void changed(const char *, std::vector< int >)
Special for ohplaylist.
Definition: service.hxx:66