|
1 /** @file |
|
2 * Copyright (c) 2008-2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implements algoritms for modereted events |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "upnpmoderatedeventqueuemanager.h" |
|
20 #include "upnpgenamessagefactory.h" |
|
21 #include "upnpsubscriberlibraryelement.h" |
|
22 #include "upnphttpmoderatedeventtransaction.h" |
|
23 #include "upnpnotifytimer.h" |
|
24 |
|
25 // ----------------------------------------------------------------------------- |
|
26 // CUpnpModeratedEventQueueManager::CUpnpModeratedEventQueueManager |
|
27 // ----------------------------------------------------------------------------- |
|
28 // |
|
29 CUpnpModeratedEventQueueManager::CUpnpModeratedEventQueueManager( |
|
30 CUpnpServiceImplementation& aServiceImpl, |
|
31 CUpnpEventController& aEventController, |
|
32 CUpnpSubscriberLibrary* aSubscriberLibrary |
|
33 ) |
|
34 :CUpnpEventQueueManagerBase( aServiceImpl, aEventController , aSubscriberLibrary ) |
|
35 { |
|
36 // No implementation required |
|
37 } |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CUpnpModeratedEventQueueManager::~CUpnpModeratedEventQueueManager |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 CUpnpModeratedEventQueueManager::~CUpnpModeratedEventQueueManager() |
|
44 { |
|
45 delete iModerationTimer; |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // CUpnpModeratedEventQueueManager::CUpnpModeratedEventQueueManager |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 CUpnpModeratedEventQueueManager* CUpnpModeratedEventQueueManager::NewLC( |
|
53 CUpnpServiceImplementation& aServiceImpl, |
|
54 CUpnpEventController& aEventController, |
|
55 CUpnpSubscriberLibrary* aSubscriberLibrary |
|
56 ) |
|
57 { |
|
58 CUpnpModeratedEventQueueManager* self = |
|
59 new (ELeave) CUpnpModeratedEventQueueManager( aServiceImpl, |
|
60 aEventController, |
|
61 aSubscriberLibrary |
|
62 ); |
|
63 CleanupStack::PushL( self ); |
|
64 self->ConstructL(); |
|
65 return self; |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CUpnpModeratedEventQueueManager::NewL |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 CUpnpModeratedEventQueueManager* CUpnpModeratedEventQueueManager::NewL( |
|
73 CUpnpServiceImplementation& aServiceImpl, |
|
74 CUpnpEventController& aEventController, |
|
75 CUpnpSubscriberLibrary* aSubscriberLibrary |
|
76 ) |
|
77 { |
|
78 CUpnpModeratedEventQueueManager* self= |
|
79 CUpnpModeratedEventQueueManager::NewLC( aServiceImpl, |
|
80 aEventController, |
|
81 aSubscriberLibrary ); |
|
82 CleanupStack::Pop( self ); |
|
83 return self; |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CUpnpModeratedEventQueueManager::ConstructL |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 void CUpnpModeratedEventQueueManager::ConstructL() |
|
91 { |
|
92 BaseConstructL(); |
|
93 iModerationTimer = CUpnpNotifyTimer::NewL( this ); |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // CUpnpModeratedEventQueueManager::StartSendingEventL |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 void CUpnpModeratedEventQueueManager::StartSendingEventL() |
|
101 { |
|
102 if ( !iSubscriberLibrary->SubscriberLibrary().Count() ) |
|
103 { |
|
104 return; |
|
105 } |
|
106 |
|
107 if ( iIsSending ) |
|
108 { |
|
109 iNewValuesWaitingToBeSend = ETrue; |
|
110 return; |
|
111 } |
|
112 |
|
113 iIsSending = ETrue; |
|
114 |
|
115 iCurrentSubscriberIndex = 0; |
|
116 for ( TInt i = 0; i < iServiceImpl.EventedStateVariables().Count(); i++ ) |
|
117 { |
|
118 if ( iServiceImpl.EventedStateVariables()[i]->MaxEventRate() > 0 ) |
|
119 { |
|
120 iServiceImpl.EventedStateVariables()[i]->EventTick(); |
|
121 } |
|
122 } |
|
123 |
|
124 delete iBody; |
|
125 iBody = NULL; |
|
126 |
|
127 iBody = CreateEventL( iServiceImpl.StateVariableList() ); |
|
128 ClearVariables(); |
|
129 |
|
130 PrepareTransactionAndStartSendingL( KFirstSubscriberInQueue ); |
|
131 } |
|
132 |
|
133 // ----------------------------------------------------------------------------- |
|
134 // CUpnpModeratedEventQueueManager::SendEvent |
|
135 // ----------------------------------------------------------------------------- |
|
136 // |
|
137 void CUpnpModeratedEventQueueManager::SendEvent() |
|
138 { |
|
139 if ( ! iSubscriberLibrary->SubscriberLibrary().Count() ) |
|
140 { |
|
141 return; |
|
142 } |
|
143 |
|
144 iModerationTimer->Cancel(); |
|
145 iModerationTimer->After( KMaxEventRate ); |
|
146 } |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CUpnpModeratedEventQueueManager::CreateTransactionL |
|
150 // ----------------------------------------------------------------------------- |
|
151 // |
|
152 CUpnpHttpTransaction* CUpnpModeratedEventQueueManager::CreateTransactionL( CUpnpHttpMessage* aMessage ) |
|
153 { |
|
154 return CUpnpHttpModeratedEventTransaction::NewL( aMessage, *this ); |
|
155 } |
|
156 |
|
157 // ----------------------------------------------------------------------------- |
|
158 // CUpnpModeratedEventQueueManager::WaitBeforeSending |
|
159 // ----------------------------------------------------------------------------- |
|
160 // |
|
161 void CUpnpModeratedEventQueueManager::WaitBeforeSending() |
|
162 { |
|
163 iModerationTimer->Cancel(); |
|
164 iModerationTimer->After( KMaxEventRate ); |
|
165 } |
|
166 |
|
167 // ----------------------------------------------------------------------------- |
|
168 // CUpnpModeratedEventQueueManager::FillEventBodyL |
|
169 // ----------------------------------------------------------------------------- |
|
170 // |
|
171 TInt CUpnpModeratedEventQueueManager::FillEventBodyL( TDes8& aEvent, |
|
172 const RPointerArray<CUpnpStateVariable>& aVariableList |
|
173 ) |
|
174 { |
|
175 TInt eventableVariableCount(0); |
|
176 for ( TInt i = 0; i < aVariableList.Count(); i++ ) |
|
177 { |
|
178 if ( aVariableList[i]->Eventable().CompareF( KYes() ) == 0 |
|
179 && aVariableList[i]->ReadyForEventing() |
|
180 && aVariableList[i]->IsModerated() ) |
|
181 { |
|
182 AddVariableToEventBody( aEvent , aVariableList[i] ); |
|
183 |
|
184 iServiceImpl.StateVariableEvented( aVariableList[i]->Name() ); |
|
185 eventableVariableCount++; |
|
186 } |
|
187 } |
|
188 return eventableVariableCount; |
|
189 } |
|
190 |
|
191 // ----------------------------------------------------------------------------- |
|
192 // CUpnpModeratedEventQueueManager::TimerEventL |
|
193 // ----------------------------------------------------------------------------- |
|
194 // |
|
195 void CUpnpModeratedEventQueueManager::TimerEventL( CUpnpNotifyTimer* /*aTimer*/ ) |
|
196 { |
|
197 if ( iModerationTimer->iStatus.Int() == KErrNone ) |
|
198 { |
|
199 if ( !iIsSending ) |
|
200 { |
|
201 TRAPD( err ,StartSendingEventL() ); |
|
202 if( err ) |
|
203 { |
|
204 SendingCompleted(); |
|
205 } |
|
206 } |
|
207 else |
|
208 { |
|
209 WaitBeforeSending(); |
|
210 } |
|
211 } |
|
212 } |
|
213 //end of file |