|
1 /* |
|
2 * Copyright (c) 2002 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: Incoming data handler |
|
15 * it handles incoming data from the network server |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <e32std.h> |
|
23 #include "CPEngIncomingDataHandler.h" |
|
24 #include "MPEngIncomingTransactionHandler.h" |
|
25 #include "MPEngPureDataHandler.h" |
|
26 #include "MPEngTransactionFactory.h" |
|
27 #include "MPEngRequestHandlerObserver.h" |
|
28 |
|
29 |
|
30 // ============================ MEMBER FUNCTIONS =============================== |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // CPEngIncomingDataHandler::CPEngIncomingDataHandler |
|
34 // C++ default constructor can NOT contain any code, that |
|
35 // might leave. |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 CPEngIncomingDataHandler::CPEngIncomingDataHandler( |
|
39 MPEngPureDataHandler& aPureDataHandler, |
|
40 RPointerArray<MPEngTransactionFactory>& aTransactionFactories, |
|
41 MPEngRequestHandlerObserver& aRequestHandlerObserver ) |
|
42 : CActive( CActive::EPriorityStandard ), |
|
43 iPureDataHandler( aPureDataHandler ), |
|
44 iTransactionFactories( aTransactionFactories ), |
|
45 iRequestHandlerObserver( aRequestHandlerObserver ) |
|
46 |
|
47 |
|
48 |
|
49 { |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CPEngIncomingDataHandler::ConstructL |
|
54 // Symbian 2nd phase constructor can leave. |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 void CPEngIncomingDataHandler::ConstructL() |
|
58 { |
|
59 // add active object to the active scheduler |
|
60 CActiveScheduler::Add( this ); |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CPEngIncomingDataHandler::NewL |
|
65 // Two-phased constructor. |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 CPEngIncomingDataHandler* CPEngIncomingDataHandler::NewL( |
|
69 MPEngPureDataHandler& aPureDataHandler, |
|
70 RPointerArray<MPEngTransactionFactory>& aTransactionFactories, |
|
71 MPEngRequestHandlerObserver& aRequestHandlerObserver ) |
|
72 { |
|
73 CPEngIncomingDataHandler* self = NewLC( aPureDataHandler, aTransactionFactories, aRequestHandlerObserver ); |
|
74 |
|
75 CleanupStack::Pop(); |
|
76 |
|
77 return self; |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // CPEngIncomingDataHandler::NewL |
|
82 // Two-phased constructor. |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 CPEngIncomingDataHandler* CPEngIncomingDataHandler::NewLC( |
|
86 MPEngPureDataHandler& aPureDataHandler, |
|
87 RPointerArray<MPEngTransactionFactory>& |
|
88 aTransactionFactories, |
|
89 MPEngRequestHandlerObserver& aRequestHandlerObserver ) |
|
90 { |
|
91 CPEngIncomingDataHandler* self = |
|
92 new( ELeave ) CPEngIncomingDataHandler( |
|
93 aPureDataHandler, |
|
94 aTransactionFactories, |
|
95 aRequestHandlerObserver ); |
|
96 |
|
97 CleanupStack::PushL( self ); |
|
98 self->ConstructL(); |
|
99 |
|
100 return self; |
|
101 } |
|
102 |
|
103 |
|
104 // Destructor |
|
105 CPEngIncomingDataHandler::~CPEngIncomingDataHandler() |
|
106 { |
|
107 Cancel(); |
|
108 delete iTransactionHandler; |
|
109 // remove if from the list of the listener |
|
110 } |
|
111 |
|
112 ///////////////////////////////////////////////////////////////////////////////// |
|
113 // ============== Function from the Main class ================================= |
|
114 ///////////////////////////////////////////////////////////////////////////////// |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // CPEngIncomingDataHandler::StartListeningL |
|
118 // Start listening of the incoming data from the server |
|
119 // (other items were commented in a header). |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 void CPEngIncomingDataHandler::StartListeningL() |
|
123 { |
|
124 // start listening incoming data |
|
125 TInt count( iPureDataHandler.ListenIncomingData( iStatus ) ); |
|
126 SetActive(); |
|
127 for ( TInt x( 0 ) ; x < count ; ++x ) |
|
128 { |
|
129 HandleIncomingDataL(); |
|
130 } |
|
131 } |
|
132 |
|
133 ///////////////////////////////////////////////////////////////////////////////// |
|
134 // ============== Function from the CActive ===================================== |
|
135 ///////////////////////////////////////////////////////////////////////////////// |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // CPEngIncomingDataHandler::RunL |
|
139 // Handles an active object’s request completion event. |
|
140 // (other items were commented in a header). |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 void CPEngIncomingDataHandler::RunL() |
|
144 { |
|
145 // OK there is something from the WV server |
|
146 HandleIncomingDataL(); |
|
147 StartListeningL(); |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CPEngIncomingDataHandler::RunError |
|
152 // Handles a leave occurring in the request completion event handler RunL() |
|
153 // implementation should return KErrNone, if it handles the leave |
|
154 // (other items were commented in a header). |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 TInt CPEngIncomingDataHandler::RunError( |
|
158 TInt /* aError*/ ) |
|
159 { |
|
160 // restartt listening incoming data |
|
161 iPureDataHandler.ListenIncomingData( iStatus ); |
|
162 SetActive(); |
|
163 return KErrNone; |
|
164 } |
|
165 |
|
166 // ----------------------------------------------------------------------------- |
|
167 // CPEngIncomingDataHandler::DoCancel |
|
168 // Implements cancellation of an outstanding request. |
|
169 // (other items were commented in a header). |
|
170 // ----------------------------------------------------------------------------- |
|
171 // |
|
172 void CPEngIncomingDataHandler::DoCancel() |
|
173 { |
|
174 iPureDataHandler.CancelListening(); |
|
175 } |
|
176 |
|
177 ///////////////////////////////////////////////////////////////////////////////// |
|
178 // ============== New private Functions of the main class ======================= |
|
179 ///////////////////////////////////////////////////////////////////////////////// |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // CPEngIncomingDataHandler::HandleIncomingDataL |
|
183 // Handle here incoming data from the presence server |
|
184 // (other items were commented in a header). |
|
185 // ----------------------------------------------------------------------------- |
|
186 // |
|
187 void CPEngIncomingDataHandler::HandleIncomingDataL() |
|
188 { |
|
189 // first get new data from the pure data handler |
|
190 HBufC8* newData; |
|
191 newData = iPureDataHandler.ResponseL( 0 ); // zero is incoming Data |
|
192 if ( !newData ) |
|
193 { |
|
194 StartListeningL(); |
|
195 return; |
|
196 } |
|
197 CleanupStack::PushL( newData ); |
|
198 TPtr8 incomingData( newData->Des() ); |
|
199 // TO-DO create new listen handler, since this one will be bussy |
|
200 // with processing |
|
201 |
|
202 |
|
203 // ask transaction factories if we want this data |
|
204 TInt count( iTransactionFactories.Count() ); |
|
205 for ( TInt x( 0 ) ; x < count ; x++ ) |
|
206 { |
|
207 iTransactionHandler = |
|
208 iTransactionFactories[x]->IncomingTransactionHandlerL( |
|
209 incomingData ); |
|
210 if ( iTransactionHandler ) |
|
211 { |
|
212 // no process new Transaction Handler |
|
213 // TO-DO, do processing asynchronous |
|
214 iTransactionHandler->ProcessRequestL( incomingData, iStatus ); |
|
215 // check if transaction needs to perform more complicated answer |
|
216 delete iTransactionHandler; |
|
217 iTransactionHandler = NULL; // this is here for the destructor |
|
218 } |
|
219 } |
|
220 CleanupStack::PopAndDestroy(); // newData |
|
221 } |
|
222 |
|
223 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
224 |
|
225 // End of File |