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
33namespace UPnPClient {
34
35class UPnPDeviceDesc;
36class UPnPServiceDesc;
37class Service;
38
55class UPNPP_API VarEventReporter {
56public:
57 virtual ~VarEventReporter() = default;
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
78typedef
79std::function<void (const std::unordered_map<std::string, std::string>&)>
81
82enum ActionOptionsMask {AOM_TIMEOUTMS = 0x1};
84 uint32_t active_options{0};
85 int timeoutms{-1};
86};
87
88class UPNPP_API Service {
89public:
91 Service(const UPnPDeviceDesc& device, const UPnPServiceDesc& service);
92
96 Service();
97
98 virtual ~Service();
99
100 // Can't copy these because this does not make sense for the
101 // member function callback.
102 Service(const Service&) = delete;
103 Service& operator=(const Service&) = delete;
104
112 bool initFromDescription(const UPnPDeviceDesc& description);
113
118 bool ok();
119
124 virtual bool reSubscribe();
125
128 const std::string& getFriendlyName() const;
129 const std::string& getDeviceId() const;
130 const std::string& getServiceType() const;
131 const std::string& getActionURL() const;
132 const std::string& getModelName() const;
133 const std::string& getManufacturer() const;
134
141 virtual int runAction(const UPnPP::SoapOutgoing& args,
142 UPnPP::SoapIncoming& data, ActionOptions *opts=nullptr);
143
146 int runTrivialAction(const std::string& actionName, ActionOptions *opts=nullptr);
147
150 template <class T> int runSimpleGet(const std::string& actnm,
151 const std::string& valnm,
152 T *valuep, ActionOptions *opts=nullptr);
153
155 template <class T> int runSimpleAction(const std::string& actnm,
156 const std::string& valnm,
157 T value, ActionOptions *opts=nullptr);
158
165 virtual VarEventReporter *getReporter();
166
171 virtual void installReporter(VarEventReporter* reporter);
172
181 virtual bool serviceTypeMatch(const std::string& tp) = 0;
182
183protected:
184
190 virtual bool serviceInit(const UPnPDeviceDesc&, const UPnPServiceDesc&) {
191 return true;
192 }
193
198 bool registerCallback(evtCBFunc c);
199
210 virtual void registerCallback() {}
211
213 void unregisterCallback();
214
215private:
216 class UPNPP_LOCAL Internal;
217 Internal *m{nullptr};
218};
219
220} // namespace UPnPClient
221
222#endif /* _SERVICE_H_X_INCLUDED_ */
Definition service.hxx:88
virtual bool serviceTypeMatch(const std::string &tp)=0
Perform a comparison to the service type string for this specific service.
virtual bool serviceInit(const UPnPDeviceDesc &, const UPnPServiceDesc &)
Service-specific part of initialization.
Definition service.hxx:190
virtual void registerCallback()
This method will be called by installReporter() and should be overridden in classes which actually su...
Definition service.hxx:210
Data holder for a UPnP device, parsed from the XML description obtained during discovery.
Definition description.hxx:139
UPnP Media Server directory entry, converted from XML data.
Definition cdircontent.hxx:60
Data holder for a UPnP service, parsed from the device XML description.
Definition description.hxx:46
To be implemented by upper-level client code for event reporting.
Definition service.hxx:55
virtual void changed(const char *nm, const char *val)=0
Report change to named character string state variable.
virtual void autorenew_failed()
Subscription autorenew failed.
Definition service.hxx:69
virtual void changed(const char *, UPnPDirObject)
Report change to track metadata (parsed as as Content Directory entry).
Definition service.hxx:64
virtual void changed(const char *nm, int val)=0
Report change to named integer state variable.
virtual void changed(const char *, std::vector< int >)
Special for ohplaylist.
Definition service.hxx:66
Store incoming Soap data: device action input parameters, or response to CP.
Definition soaphelp.hxx:36
Store the values to be encoded in outgoing SOAP data: device response or CP args.
Definition soaphelp.hxx:88
UPnP Description phase: interpreting the device description which we downloaded from the URL obtained...
Definition avlastchg.cxx:28
std::function< void(const std::unordered_map< std::string, std::string > &)> evtCBFunc
Type of the event callbacks.
Definition service.hxx:80
Definition service.hxx:83