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/control/cdircontent.hxx"
28 #include "libupnpp/log.hxx"
29 #include "libupnpp/soaphelp.hxx"
30 #include "libupnpp/upnperrcodes.hxx"
31 
32 namespace UPnPClient {
33 
34 class UPnPDeviceDesc;
35 class UPnPServiceDesc;
36 class Service;
37 
49 public:
50  virtual ~VarEventReporter() {}
52  virtual void changed(const char *nm, int val) = 0;
54  virtual void changed(const char *nm, const char *val) = 0;
57  virtual void changed(const char * /*nm*/, UPnPDirObject /*meta*/) {}
59  virtual void changed(const char * /*nm*/, std::vector<int> /*ids*/) {}
60 };
61 
67 typedef
68 std::function<void (const std::unordered_map<std::string, std::string>&)>
70 
71 class Service {
72 public:
74  Service(const UPnPDeviceDesc& device, const UPnPServiceDesc& service);
75 
79  Service();
80 
81  virtual ~Service();
82 
90  bool initFromDescription(const UPnPDeviceDesc& description);
91 
95  virtual void reSubscribe();
96 
99  const std::string& getFriendlyName() const;
100  const std::string& getDeviceId() const;
101  const std::string& getServiceType() const;
102  const std::string& getActionURL() const;
103  const std::string& getModelName() const;
104  const std::string& getManufacturer() const;
105 
112  virtual int runAction(const UPnPP::SoapOutgoing& args,
113  UPnPP::SoapIncoming& data);
114 
117  int runTrivialAction(const std::string& actionName);
118 
121  template <class T> int runSimpleGet(const std::string& actnm,
122  const std::string& valnm,
123  T *valuep);
124 
126  template <class T> int runSimpleAction(const std::string& actnm,
127  const std::string& valnm,
128  T value);
129 
136  virtual VarEventReporter *getReporter();
137 
139  virtual void installReporter(VarEventReporter* reporter);
140 
150  virtual bool serviceTypeMatch(const std::string& tp) = 0;
151 
152 protected:
153 
159  virtual bool serviceInit(const UPnPDeviceDesc&,
160  const UPnPServiceDesc&) {
161  return true;
162  }
163 
168  void registerCallback(evtCBFunc c);
169 
177  virtual void registerCallback() {}
178 
180  void unregisterCallback();
181 
182 private:
183  // Can't copy these because this does not make sense for the
184  // member function callback.
185  Service(Service const&);
186  Service& operator=(Service const&);
187 
188  class Internal;
189  Internal *m{nullptr};
190 };
191 
192 } // namespace UPnPClient
193 
194 #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:69
Store the values to be encoded in a SOAP response.
Definition: soaphelp.hxx:88
Decode incoming Soap call data.
Definition: soaphelp.hxx:33
virtual void changed(const char *, UPnPDirObject)
Report change to track metadata (parsed as as Content Directory entry).
Definition: service.hxx:57
virtual void changed(const char *nm, int val)=0
Report change to named integer state variable.
Definition: service.hxx:71
virtual void registerCallback()
To be overridden in classes which actually support events.
Definition: service.hxx:177
Data holder for a UPnP service, parsed from the device XML description.
Definition: description.hxx:44
virtual bool serviceInit(const UPnPDeviceDesc &, const UPnPServiceDesc &)
Service-specific part of initialization.
Definition: service.hxx:159
UPnP Media Server directory entry, converted from XML data.
Definition: cdircontent.hxx:62
Data holder for a UPnP device, parsed from the XML description obtained during discovery.
Definition: description.hxx:140
Definition: service.cxx:43
UPnP Description phase: interpreting the device description which we downloaded from the URL obtained...
Definition: avlastchg.cxx:28
To be implemented by upper-level client code for event reporting.
Definition: service.hxx:48
virtual void changed(const char *, std::vector< int >)
Special for ohplaylist.
Definition: service.hxx:59