|
1 /** @file |
|
2 * Copyright (c) 2005-2006 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: CUpnpSubscriberLibrary |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "upnpsubscriberlibrary.h" |
|
22 #include "upnpgenamessage.h" |
|
23 #include "upnpcommonupnplits.h" |
|
24 #define KLogFile _L("UPnPStack.txt") |
|
25 #include "upnpcustomlog.h" |
|
26 #include "upnpsubscriberlibraryobserver.h" |
|
27 #include "upnpsubscriberlibraryelement.h" |
|
28 |
|
29 // ============================ MEMBER FUNCTIONS =============================== |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CUpnpSubscriberLibrary::CUpnpSubscriberLibrary |
|
33 // C++ default constructor can NOT contain any code, that |
|
34 // might leave. |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 CUpnpSubscriberLibrary::CUpnpSubscriberLibrary( |
|
38 MUpnpSubscriberLibraryObserver& aObserver ) |
|
39 : iObserver( aObserver ) |
|
40 { |
|
41 |
|
42 } |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CUpnpSubscriberLibrary::ConstructL |
|
46 // Symbian 2nd phase constructor can leave. |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 void CUpnpSubscriberLibrary::ConstructL() |
|
50 { |
|
51 |
|
52 } |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CUpnpSubscriberLibrary::NewL |
|
56 // Two-phased constructor. |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 CUpnpSubscriberLibrary* CUpnpSubscriberLibrary::NewL( |
|
60 MUpnpSubscriberLibraryObserver& aObserver ) |
|
61 { |
|
62 CUpnpSubscriberLibrary* self = new (ELeave) CUpnpSubscriberLibrary( aObserver ); |
|
63 |
|
64 CleanupStack::PushL( self ); |
|
65 self->ConstructL(); |
|
66 CleanupStack::Pop( self ); |
|
67 |
|
68 return self; |
|
69 } |
|
70 |
|
71 // Destructor |
|
72 CUpnpSubscriberLibrary::~CUpnpSubscriberLibrary() |
|
73 { |
|
74 iElementArray.ResetAndDestroy(); |
|
75 iElementArray.Close(); |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CUpnpSubscriberLibrary::SubscriberLibrary |
|
80 // |
|
81 // (other items were commented in a header). |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 RPointerArray<CUpnpSubscriberLibraryElement> |
|
85 CUpnpSubscriberLibrary::SubscriberLibrary() const |
|
86 { |
|
87 return iElementArray; |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CUpnpSubscriberLibrary::AddInfoL |
|
92 // |
|
93 // (other items were commented in a header). |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 TUpnpErrorCode CUpnpSubscriberLibrary::AddInfoL( |
|
97 CUpnpGenaMessage* aMessage, |
|
98 CUpnpSubscriberLibraryElement** aElement ) |
|
99 { |
|
100 if ( !aMessage || !aElement ) |
|
101 { |
|
102 return EUndefined; |
|
103 } |
|
104 LOGS("CUpnpSubscriberLibrary::AddInfoL"); |
|
105 |
|
106 |
|
107 if ( ( aMessage->Nt().Compare(KNoHeader) != 0 |
|
108 || aMessage->Callback().Compare(KNoHeader) != 0 ) |
|
109 && aMessage->Sid().Compare(KNoHeader) != 0 ) |
|
110 { |
|
111 return EBadRequest; |
|
112 } |
|
113 |
|
114 TInt index = Find( aMessage->Sid() ); |
|
115 TUpnpErrorCode error; |
|
116 |
|
117 if ( index != KErrNotFound ) |
|
118 { |
|
119 // already a subscriber -> renew |
|
120 CUpnpSubscriberLibraryElement* element = iElementArray[index]; |
|
121 *aElement = element; |
|
122 error = element->RenewSubscriberL( aMessage ); |
|
123 |
|
124 return error; |
|
125 } |
|
126 else |
|
127 { |
|
128 // not found -> new subscriber |
|
129 CUpnpSubscriberLibraryElement* element = |
|
130 CUpnpSubscriberLibraryElement::NewL( *this ); |
|
131 CleanupStack::PushL( element ); |
|
132 *aElement = element; |
|
133 error = element->AddSubscriberL( aMessage ); |
|
134 |
|
135 if ( error == EHttpOk ) |
|
136 { |
|
137 User::LeaveIfError(iElementArray.Append( *aElement )); |
|
138 CleanupStack::Pop( element ); |
|
139 } |
|
140 else |
|
141 { |
|
142 CleanupStack::PopAndDestroy( element ); |
|
143 *aElement = NULL; |
|
144 } |
|
145 |
|
146 return error; |
|
147 } |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CUpnpSubscriberLibrary::Find |
|
152 // |
|
153 // (other items were commented in a header). |
|
154 // ----------------------------------------------------------------------------- |
|
155 // |
|
156 TInt CUpnpSubscriberLibrary::Find( const TDesC8& aSid ) |
|
157 { |
|
158 if ( aSid.Length() > 0 ) |
|
159 { |
|
160 for ( TInt i = 0; i < iElementArray.Count(); i++ ) |
|
161 { |
|
162 if ( aSid.Compare( iElementArray[i]->Sid() ) == 0 ) |
|
163 { |
|
164 return i; |
|
165 } |
|
166 } |
|
167 } |
|
168 return KErrNotFound; |
|
169 } |
|
170 |
|
171 // ----------------------------------------------------------------------------- |
|
172 // CUpnpSubscriberLibrary::Remove |
|
173 // |
|
174 // (other items were commented in a header). |
|
175 // ----------------------------------------------------------------------------- |
|
176 // |
|
177 TUpnpErrorCode CUpnpSubscriberLibrary::Remove( const TDesC8& aSid ) |
|
178 { |
|
179 LOGS("CUpnpSubscriberLibrary::Remove"); |
|
180 |
|
181 |
|
182 TInt result = Find( aSid ); |
|
183 |
|
184 if ( result != KErrNotFound ) |
|
185 { |
|
186 CUpnpSubscriberLibraryElement* elem = iElementArray[result]; |
|
187 |
|
188 iElementArray.Remove( result ); |
|
189 iElementArray.GranularCompress(); |
|
190 |
|
191 iObserver.SubscriberRemoved( elem , result ); |
|
192 |
|
193 delete elem; |
|
194 LOGS1(" removed, count: %i", iElementArray.Count()); |
|
195 |
|
196 return EHttpOk; |
|
197 } |
|
198 return EPreconditionFailed; |
|
199 } |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // CUpnpSubscriberLibrary::TimeoutExpiredL |
|
203 // |
|
204 // (other items were commented in a header). |
|
205 // ----------------------------------------------------------------------------- |
|
206 // |
|
207 void CUpnpSubscriberLibrary::TimeoutExpiredL( CUpnpTimeoutElement* aElement ) |
|
208 { |
|
209 |
|
210 if ( !aElement ) |
|
211 { |
|
212 return; |
|
213 } |
|
214 CUpnpSubscriberLibraryElement* elem |
|
215 = static_cast<CUpnpSubscriberLibraryElement*>(aElement); |
|
216 |
|
217 LOGS("CUpnpSubscriberLibrary::TimeoutExpiredL"); |
|
218 |
|
219 switch ( elem->Renew() ) |
|
220 { |
|
221 case CUpnpTimeoutElement::ERenew: |
|
222 { |
|
223 LOGS(" is \"Infinite\", renewed"); |
|
224 |
|
225 elem->SetTimeout( KMaxRenewTimeout ); |
|
226 } |
|
227 break; |
|
228 |
|
229 case CUpnpTimeoutElement::EOnce: |
|
230 { |
|
231 for ( TInt i = 0; i < iElementArray.Count(); i++ ) |
|
232 { |
|
233 if ( elem == iElementArray[i] ) |
|
234 { |
|
235 iElementArray.Remove(i); |
|
236 iElementArray.GranularCompress(); |
|
237 |
|
238 iObserver.SubscriberRemoved( elem, i ); |
|
239 |
|
240 LOGS1(" expired, count: %i", iElementArray.Count()); |
|
241 delete elem; |
|
242 } |
|
243 } |
|
244 } |
|
245 break; |
|
246 |
|
247 default: |
|
248 break; |
|
249 } |
|
250 } |
|
251 |
|
252 // End of File |