Switch to unified view

a/libupnpp/device.hxx b/libupnpp/device.hxx
...
...
31
 */
31
 */
32
class UpnpDevice {
32
class UpnpDevice {
33
public:
33
public:
34
    UpnpDevice(const std::string& deviceId, 
34
    UpnpDevice(const std::string& deviceId, 
35
               const std::unordered_map<std::string, std::string>& xmlfiles);
35
               const std::unordered_map<std::string, std::string>& xmlfiles);
36
37
    /**
38
     * Add serviceId to serviceType mapping. 
39
     *
40
     * This exists only so that we can prefill the 
41
     * Soap answer structure with the service type on account of the specific
42
     * device (pure convenience, but mandatory). We get the serviceId
43
     * in the callbacks but not the serviceType, and the latter needs
44
     * to be set in the reply.
45
     */
36
    void addServiceType(const std::string& serviceId, 
46
    void addServiceType(const std::string& serviceId, 
37
                        const std::string& serviceType);
47
                        const std::string& serviceType);
48
49
    /**
50
     * Add mapping from action-name to handler function.
51
     */
38
    void addActionMapping(const std::string& actName, soapfun fun);
52
    void addActionMapping(const std::string& actName, soapfun fun);
39
53
54
    /** 
55
     * Poll to retrieve evented data changed since last call.
56
     *
40
    /** To be implemented by the derived class.
57
     * To be implemented by the derived class.
41
        Called by the library when a control point subscribes, to
58
     * Called by the library when a control point subscribes, to
42
        retrieve eventable data. Return name/value pairs in the data array 
59
     * retrieve eventable data. Return name/value pairs in the data array 
43
    */
60
     */
44
    virtual bool getEventData(bool all, const std::string& serviceid,
61
    virtual bool getEventData(bool all, const std::string& serviceid,
45
                              std::vector<std::string>& names, 
62
                              std::vector<std::string>& names, 
46
                              std::vector<std::string>& values) = 0;
63
                              std::vector<std::string>& values) = 0;
47
64
65
    /** 
66
     * Generate event.
67
     *
48
    /** To be called by the device layer when data changes and an
68
     * To be called by the device layer when data changes and an
49
     * event should happen. */
69
     * event should happen. Use is not mandatory because the polling by 
70
     * getEventData() may be sufficient.
71
     */
50
    void notifyEvent(const std::string& serviceId,
72
    void notifyEvent(const std::string& serviceId,
51
                     const std::vector<std::string>& names, 
73
                     const std::vector<std::string>& names, 
52
                     const std::vector<std::string>& values);
74
                     const std::vector<std::string>& values);
53
75
76
    /** 
77
     * Main routine. To be called by main() when done with initialization. 
78
     *
54
    /** This loop polls getEventData and generates an UPnP event if
79
     * This loop mostly polls getEventData and generates an UPnP event if
55
     * there is anything to broadcast. To be called by main() when
80
     * there is anything to broadcast. The UPnP action calls happen in
56
     * done with initialization. */
81
     * other threads with which we synchronize, currently using a global lock.
82
     */
57
    void eventloop();
83
    void eventloop();
58
84
59
    /** Called from a callback to Wakeup the event loop early if we
85
    /** 
60
     * need to broadcast something quickly. Will only do something if
86
     * To be called from a service action callback to wake up the
87
     * event loop early if something needs to be broadcast without
88
     * waiting for the normal delay.
89
     *
61
     * the previous event is not too recent.
90
     * Will only do something if the previous event is not too recent.
62
     */
91
     */
63
    void loopWakeup(); // To trigger an early event
92
    void loopWakeup(); // To trigger an early event
64
93
94
    /** Check status */
65
    bool ok() {return m_lib != 0;}
95
    bool ok() {return m_lib != 0;}
66
96
67
private:
97
private:
68
    const std::string& serviceType(const std::string& serviceId);
98
    const std::string& serviceType(const std::string& serviceId);
69
            
99
            
...
...
71
    std::string m_deviceId;
101
    std::string m_deviceId;
72
    std::unordered_map<std::string, std::string> m_serviceTypes;
102
    std::unordered_map<std::string, std::string> m_serviceTypes;
73
    std::unordered_map<std::string, soapfun> m_calls;
103
    std::unordered_map<std::string, soapfun> m_calls;
74
104
75
    static unordered_map<std::string, UpnpDevice *> o_devices;
105
    static unordered_map<std::string, UpnpDevice *> o_devices;
106
107
    /* Static callback for libupnp. This looks up the appropriate
108
     * device using the device ID (UDN), the calls its callback
109
     * method */
76
    static int sCallBack(Upnp_EventType et, void* evp, void*);
110
    static int sCallBack(Upnp_EventType et, void* evp, void*);
111
112
    /* Gets called when something needs doing */
77
    int callBack(Upnp_EventType et, void* evp);
113
    int callBack(Upnp_EventType et, void* evp);
78
};
114
};
79
115
80
116
81
#endif /* _DEVICE_H_X_INCLUDED_ */
117
#endif /* _DEVICE_H_X_INCLUDED_ */