|
a |
|
b/libupnpp/device.hxx |
|
|
1 |
/* Copyright (C) 2014 J.F.Dockes
|
|
|
2 |
* This program is free software; you can redistribute it and/or modify
|
|
|
3 |
* it under the terms of the GNU General Public License as published by
|
|
|
4 |
* the Free Software Foundation; either version 2 of the License, or
|
|
|
5 |
* (at your option) any later version.
|
|
|
6 |
*
|
|
|
7 |
* This program is distributed in the hope that it will be useful,
|
|
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
10 |
* GNU General Public License for more details.
|
|
|
11 |
*
|
|
|
12 |
* You should have received a copy of the GNU General Public License
|
|
|
13 |
* along with this program; if not, write to the
|
|
|
14 |
* Free Software Foundation, Inc.,
|
|
|
15 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
16 |
*/
|
|
|
17 |
#ifndef _DEVICE_H_X_INCLUDED_
|
|
|
18 |
#define _DEVICE_H_X_INCLUDED_
|
|
|
19 |
|
|
|
20 |
#include <unordered_map>
|
|
|
21 |
#include <functional>
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
#include "soaphelp.hxx"
|
|
|
25 |
|
|
|
26 |
class UpnpDevice;
|
|
|
27 |
|
|
|
28 |
//typedef int (*soapfun)(const SoapArgs&, void *, SoapData&) ;
|
|
|
29 |
|
|
|
30 |
typedef function<int (const SoapArgs&, SoapData&)> soapfun;
|
|
|
31 |
|
|
|
32 |
/** Define a virtual interface to link libupnp operations to a device
|
|
|
33 |
* implementation
|
|
|
34 |
*/
|
|
|
35 |
class UpnpDevice {
|
|
|
36 |
public:
|
|
|
37 |
UpnpDevice(const std::string& deviceId);
|
|
|
38 |
void addServiceType(const std::string& serviceId,
|
|
|
39 |
const std::string& serviceType);
|
|
|
40 |
void addActionMapping(const std::string& actName, soapfun fun);
|
|
|
41 |
|
|
|
42 |
/** Called by the library when a control point subscribes, to
|
|
|
43 |
retrieve eventable data. Return name/value pairs in the data array
|
|
|
44 |
To be overriden by the derived class.
|
|
|
45 |
*/
|
|
|
46 |
virtual bool getEventData(std::vector<std::string>& names,
|
|
|
47 |
std::vector<std::string>& values)
|
|
|
48 |
{
|
|
|
49 |
return true;
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
/** To be called by the device layer when data changes and an
|
|
|
53 |
event should happen */
|
|
|
54 |
void notifyEvent(const std::string& serviceId,
|
|
|
55 |
const std::vector<std::string>& names,
|
|
|
56 |
const std::vector<std::string>& values);
|
|
|
57 |
bool ok() {return m_lib != 0;}
|
|
|
58 |
private:
|
|
|
59 |
const std::string& serviceType(const std::string& serviceId);
|
|
|
60 |
std::string serviceKey(const std::string& UDN, const std::string& servId)
|
|
|
61 |
{
|
|
|
62 |
return UDN + "|" + servId;
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
LibUPnP *m_lib;
|
|
|
66 |
std::string m_deviceId;
|
|
|
67 |
std::unordered_map<std::string, std::string> m_serviceTypes;
|
|
|
68 |
std::unordered_map<std::string, soapfun> m_calls;
|
|
|
69 |
|
|
|
70 |
static unordered_map<std::string, UpnpDevice *> o_devices;
|
|
|
71 |
static int sCallBack(Upnp_EventType et, void* evp, void*);
|
|
|
72 |
int callBack(Upnp_EventType et, void* evp);
|
|
|
73 |
};
|
|
|
74 |
|
|
|
75 |
|
|
|
76 |
#endif /* _DEVICE_H_X_INCLUDED_ */
|