1 /*****************************************************************
2 |
3 |   Platinum - Event
4 |
5 | Copyright (c) 2004-2010, Plutinosoft, LLC.
6 | All rights reserved.
7 | http://www.plutinosoft.com
8 |
9 | This program is free software; you can redistribute it and/or
10 | modify it under the terms of the GNU General Public License
11 | as published by the Free Software Foundation; either version 2
12 | of the License, or (at your option) any later version.
13 |
14 | OEMs, ISVs, VARs and other distributors that combine and
15 | distribute commercially licensed software with Platinum software
16 | and do not wish to distribute the source code for the commercially
17 | licensed software under version 2, or (at your option) any later
18 | version, of the GNU General Public License (the "GPL") must enter
19 | into a commercial license agreement with Plutinosoft, LLC.
20 | licensing@plutinosoft.com
21 |
22 | This program is distributed in the hope that it will be useful,
23 | but WITHOUT ANY WARRANTY; without even the implied warranty of
24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25 | GNU General Public License for more details.
26 |
27 | You should have received a copy of the GNU General Public License
28 | along with this program; see the file LICENSE.txt. If not, write to
29 | the Free Software Foundation, Inc.,
30 | 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
31 | http://www.gnu.org/licenses/gpl-2.0.html
32 |
33 ****************************************************************/
34 
35 /** @file
36  UPnP Eventing
37  */
38 
39 #ifndef _PLT_EVENT_H_
40 #define _PLT_EVENT_H_
41 
42 /*----------------------------------------------------------------------
43 |   includes
44 +---------------------------------------------------------------------*/
45 #include "Neptune.h"
46 #include "PltHttpClientTask.h"
47 
48 /*----------------------------------------------------------------------
49 |   forward declarations
50 +---------------------------------------------------------------------*/
51 class PLT_StateVariable;
52 class PLT_DeviceData;
53 class PLT_Service;
54 class PLT_TaskManager;
55 class PLT_CtrlPoint;
56 
57 /*----------------------------------------------------------------------
58 |   PLT_EventNotification class
59 +---------------------------------------------------------------------*/
60 /**
61  The PLT_EventNotification class represents an event notification for a given
62  service to a given subscriber
63  */
64 class PLT_EventNotification
65 {
66 public:
~PLT_EventNotification()67     ~PLT_EventNotification() {}
68 
69     static PLT_EventNotification* Parse(const NPT_HttpRequest&        request,
70                                         const NPT_HttpRequestContext& context,
71                                         NPT_HttpResponse&             response);
72 
73 
74     NPT_TimeStamp                 m_ReceptionTime;
75     NPT_HttpUrl                   m_RequestUrl;
76     NPT_String                    m_SID;
77     NPT_Ordinal                   m_EventKey;
78     NPT_String                    m_XmlBody;
79 
80 protected:
PLT_EventNotification()81     PLT_EventNotification() {}
82 };
83 
84 /*----------------------------------------------------------------------
85 |   PLT_EventSubscriber class
86 +---------------------------------------------------------------------*/
87 /**
88  The PLT_EventSubscriber class represents an event subscription for a given service
89  from a UPnP ControlPoint.
90  */
91 class PLT_EventSubscriber
92 {
93 public:
94     PLT_EventSubscriber(PLT_TaskManager* task_manager,
95                         PLT_Service*     service,
96                         const char*      sid,
97                         NPT_Timeout      timeout_secs = -1);
98     ~PLT_EventSubscriber();
99 
100     PLT_Service*      GetService();
101     NPT_Ordinal       GetEventKey();
102     NPT_Result        SetEventKey(NPT_Ordinal value);
103     NPT_SocketAddress GetLocalIf();
104     NPT_Result        SetLocalIf(NPT_SocketAddress value);
105     NPT_TimeStamp     GetExpirationTime();
106     NPT_Result        SetTimeout(NPT_Timeout seconds = -1);
GetSID()107     const NPT_String& GetSID() const { return m_SID; }
108     NPT_Result        FindCallbackURL(const char* callback_url);
109     NPT_Result        AddCallbackURL(const char* callback_url);
110     NPT_Result        Notify(NPT_List<PLT_StateVariable*>& vars);
111 
112 protected:
113     //members
114     PLT_TaskManager*          m_TaskManager;
115     PLT_Service*              m_Service;
116     NPT_Ordinal               m_EventKey;
117     PLT_HttpClientSocketTask* m_SubscriberTask;
118     NPT_String                m_SID;
119     NPT_SocketAddress         m_LocalIf;
120     NPT_Array<NPT_String>     m_CallbackURLs;
121     NPT_TimeStamp             m_ExpirationTime;
122 };
123 
124 typedef NPT_Reference<PLT_EventSubscriber> PLT_EventSubscriberReference;
125 
126 /*----------------------------------------------------------------------
127 |   PLT_EventSubscriberFinderBySID
128 +---------------------------------------------------------------------*/
129 /**
130  The PLT_EventSubscriberFinderBySID class returns an instance of a PLT_EventSubscriber
131  given its subscriber ID.
132  */
133 class PLT_EventSubscriberFinderBySID
134 {
135 public:
136     // methods
PLT_EventSubscriberFinderBySID(const char * sid)137     PLT_EventSubscriberFinderBySID(const char* sid) : m_SID(sid) {}
138 
operator()139     bool operator()(PLT_EventSubscriberReference const & sub) const {
140         return m_SID.Compare(sub->GetSID(), true) ? false : true;
141     }
142 
143 private:
144     // members
145     NPT_String m_SID;
146 };
147 
148 /*----------------------------------------------------------------------
149 |   PLT_EventSubscriberFinderByCallbackURL
150 +---------------------------------------------------------------------*/
151 /**
152  The PLT_EventSubscriberFinderByCallbackURL class returns an instance of a
153  PLT_EventSubscriber given its subscriber callback url.
154  */
155 class PLT_EventSubscriberFinderByCallbackURL
156 {
157 public:
158     // methods
PLT_EventSubscriberFinderByCallbackURL(const char * callback_url)159     PLT_EventSubscriberFinderByCallbackURL(const char* callback_url) :
160       m_CallbackURL(callback_url) {}
161 
operator()162     bool operator()(PLT_EventSubscriberReference const & sub) const {
163         return NPT_SUCCEEDED(sub->FindCallbackURL(m_CallbackURL));
164     }
165 
166 private:
167     // members
168     NPT_String m_CallbackURL;
169 };
170 
171 /*----------------------------------------------------------------------
172 |   PLT_EventSubscriberFinderByService
173 +---------------------------------------------------------------------*/
174 /**
175  The PLT_EventSubscriberFinderByService class returns an instance of a
176  PLT_EventSubscriber given a UPnP service.
177  */
178 class PLT_EventSubscriberFinderByService
179 {
180 public:
181     // methods
PLT_EventSubscriberFinderByService(PLT_Service * service)182     PLT_EventSubscriberFinderByService(PLT_Service* service) : m_Service(service) {}
~PLT_EventSubscriberFinderByService()183     virtual ~PLT_EventSubscriberFinderByService() {}
184     bool operator()(PLT_EventSubscriberReference const & eventSub) const;
185 
186 private:
187     // members
188     PLT_Service* m_Service;
189 };
190 
191 #endif /* _PLT_EVENT_H_ */
192