15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 |
18 |
19 #include "harvesterclientao.h" |
19 #include "harvesterclientao.h" |
20 #include "harvesternotificationqueue.h" |
|
21 #include "harvestercommon.h" |
20 #include "harvestercommon.h" |
22 #include "harvesterlog.h" |
21 #include "harvesterlog.h" |
23 #include "mdsutils.h" |
22 #include "mdsutils.h" |
24 #include "OstTraceDefinitions.h" |
23 #include "OstTraceDefinitions.h" |
25 #ifdef OST_TRACE_COMPILER_IN_USE |
24 #ifdef OST_TRACE_COMPILER_IN_USE |
29 |
28 |
30 // --------------------------------------------------------------------------- |
29 // --------------------------------------------------------------------------- |
31 // NewL |
30 // NewL |
32 // --------------------------------------------------------------------------- |
31 // --------------------------------------------------------------------------- |
33 // |
32 // |
34 CHarvesterClientAO* CHarvesterClientAO::NewL( RHarvesterClient& aHarvesterClient, |
33 CHarvesterClientAO* CHarvesterClientAO::NewL( RHarvesterClient& aHarvesterClient ) |
35 CHarvesterNotificationQueue* aNotificationQueue ) |
|
36 { |
34 { |
37 WRITELOG( "CHarvesterClientAO::NewL()" ); |
35 WRITELOG( "CHarvesterClientAO::NewL()" ); |
38 OstTrace0( TRACE_NORMAL, CHARVESTERCLIENTAO_NEWL, "CHarvesterClientAO::NewL" ); |
36 OstTrace0( TRACE_NORMAL, CHARVESTERCLIENTAO_NEWL, "CHarvesterClientAO::NewL" ); |
39 |
37 |
40 CHarvesterClientAO* self = new (ELeave) CHarvesterClientAO( aHarvesterClient, aNotificationQueue ); |
38 CHarvesterClientAO* self = new (ELeave) CHarvesterClientAO( aHarvesterClient ); |
41 CleanupStack::PushL( self ); |
39 CleanupStack::PushL( self ); |
42 self->ConstructL(); |
40 self->ConstructL(); |
43 CleanupStack::Pop( self ); |
41 CleanupStack::Pop( self ); |
44 return self; |
42 return self; |
45 } |
43 } |
51 CHarvesterClientAO::~CHarvesterClientAO() // destruct |
49 CHarvesterClientAO::~CHarvesterClientAO() // destruct |
52 { |
50 { |
53 OstTrace0( TRACE_NORMAL, CHARVESTERCLIENTAO_CHARVESTERCLIENTAO, "CHarvesterClientAO::~CHarvesterClientAO" ); |
51 OstTrace0( TRACE_NORMAL, CHARVESTERCLIENTAO_CHARVESTERCLIENTAO, "CHarvesterClientAO::~CHarvesterClientAO" ); |
54 |
52 |
55 WRITELOG( "CHarvesterClientAO::~CHarvesterClientAO()" ); |
53 WRITELOG( "CHarvesterClientAO::~CHarvesterClientAO()" ); |
56 Cancel(); |
54 CancelRequest(); |
57 |
|
58 delete iURI; |
|
59 iURI = NULL; |
|
60 } |
55 } |
61 |
56 |
62 // --------------------------------------------------------------------------- |
57 // --------------------------------------------------------------------------- |
63 // CHarvesterClientAO |
58 // CHarvesterClientAO |
64 // First-phase C++ constructor |
59 // First-phase C++ constructor |
65 // --------------------------------------------------------------------------- |
60 // --------------------------------------------------------------------------- |
66 // |
61 // |
67 CHarvesterClientAO::CHarvesterClientAO( RHarvesterClient& aHarvesterClient, |
62 CHarvesterClientAO::CHarvesterClientAO( RHarvesterClient& aHarvesterClient ) |
68 CHarvesterNotificationQueue* aNotificationQueue ) |
63 : CActive( CActive::EPriorityUserInput ), |
69 : CActive( CActive::EPriorityStandard ), |
|
70 iObserver( NULL ), |
64 iObserver( NULL ), |
71 iHarvesterClient( aHarvesterClient ), |
65 iHarvesterClient( aHarvesterClient ), |
72 iNotificationQueue( aNotificationQueue ), |
66 iCancelled( EFalse ) |
73 iURI( NULL ), |
|
74 iRequestComplete( EFalse ) |
|
75 { |
67 { |
76 OstTrace0( TRACE_NORMAL, DUP1_CHARVESTERCLIENTAO_CHARVESTERCLIENTAO, "CHarvesterClientAO::CHarvesterClientAO" ); |
68 OstTrace0( TRACE_NORMAL, DUP1_CHARVESTERCLIENTAO_CHARVESTERCLIENTAO, "CHarvesterClientAO::CHarvesterClientAO" ); |
77 |
69 |
78 WRITELOG( "CHarvesterClientAO::CHarvesterClientAO()" ); |
70 WRITELOG( "CHarvesterClientAO::CHarvesterClientAO()" ); |
79 } |
71 } |
101 |
93 |
102 iObserver = aObserver; |
94 iObserver = aObserver; |
103 } |
95 } |
104 |
96 |
105 // --------------------------------------------------------------------------- |
97 // --------------------------------------------------------------------------- |
|
98 // RemoveObserver |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 void CHarvesterClientAO::RemoveObserver( MHarvestObserver* /*aObserver*/ ) |
|
102 { |
|
103 WRITELOG( "CHarvesterClientAO::RemoveObserver()" ); |
|
104 OstTrace0( TRACE_NORMAL, CHARVESTERCLIENTAO_REMOVEOBSERVER, "CHarvesterClientAO::RemoveObserver" ); |
|
105 if ( iObserver ) |
|
106 { |
|
107 WRITELOG( "CHarvesterClientAO::RemoveObserver() - deleting observer" ); |
|
108 iObserver = NULL; |
|
109 } |
|
110 |
|
111 CancelRequest(); |
|
112 } |
|
113 |
|
114 // --------------------------------------------------------------------------- |
106 // DoCancel |
115 // DoCancel |
107 // --------------------------------------------------------------------------- |
116 // --------------------------------------------------------------------------- |
108 // |
117 // |
109 void CHarvesterClientAO::DoCancel() |
118 void CHarvesterClientAO::DoCancel() |
110 { |
119 { |
111 WRITELOG( "CHarvesterClientAO::DoCancel()" ); |
120 WRITELOG( "CHarvesterClientAO::DoCancel()" ); |
112 OstTrace0( TRACE_NORMAL, CHARVESTERCLIENTAO_DOCANCEL, "CHarvesterClientAO::DoCancel" ); |
121 OstTrace0( TRACE_NORMAL, CHARVESTERCLIENTAO_DOCANCEL, "CHarvesterClientAO::DoCancel" ); |
113 iRequestComplete = ETrue; |
122 iHarvesterClient.UnregisterHarvestComplete(); |
|
123 WRITELOG( "CHarvesterClientAO::DoCancel() - end" ); |
114 } |
124 } |
115 |
125 |
116 // --------------------------------------------------------------------------- |
126 // --------------------------------------------------------------------------- |
117 // Active |
127 // Active |
118 // --------------------------------------------------------------------------- |
128 // --------------------------------------------------------------------------- |
119 // |
129 // |
120 void CHarvesterClientAO::Active( TDesC& aUri ) |
130 void CHarvesterClientAO::Active() |
121 { |
131 { |
122 WRITELOG( "CHarvesterClientAO::Active()"); |
132 WRITELOG( "CHarvesterClientAO::Active" ); |
123 if( iObserver && !IsActive() ) |
133 if ( iObserver && !IsActive()) |
124 { |
134 { |
125 delete iURI; |
135 WRITELOG( "CHarvesterClientAO::Active - calling RegisterHarvestComplete" ); |
126 iURI = NULL; |
136 iHarvesterClient.RegisterHarvestComplete(iURI, iStatus); |
127 iURI = aUri.Alloc(); |
137 iCancelled = EFalse; |
128 if( iURI ) |
138 SetActive(); |
129 { |
139 } |
130 TPtr16 uri( iURI->Des() ); |
|
131 iHarvesterClient.RegisterHarvestComplete( uri, iStatus ); |
|
132 SetActive(); |
|
133 } |
|
134 else if( iObserver ) |
|
135 { |
|
136 iObserver->HarvestingComplete( aUri, KErrCompletion ); |
|
137 iRequestComplete = ETrue; |
|
138 } |
|
139 } |
|
140 } |
140 } |
141 |
141 |
142 // --------------------------------------------------------------------------- |
142 // --------------------------------------------------------------------------- |
143 // RunL |
143 // RunL |
144 // --------------------------------------------------------------------------- |
144 // --------------------------------------------------------------------------- |
146 void CHarvesterClientAO::RunL() |
146 void CHarvesterClientAO::RunL() |
147 { |
147 { |
148 WRITELOG( "CHarvesterClientAO::RunL()" ); |
148 WRITELOG( "CHarvesterClientAO::RunL()" ); |
149 OstTrace0( TRACE_NORMAL, CHARVESTERCLIENTAO_RUNL, "CHarvesterClientAO::RunL" ); |
149 OstTrace0( TRACE_NORMAL, CHARVESTERCLIENTAO_RUNL, "CHarvesterClientAO::RunL" ); |
150 |
150 |
151 iNotificationQueue->Cleanup( EFalse ); |
|
152 |
|
153 const TInt status = iStatus.Int(); |
151 const TInt status = iStatus.Int(); |
154 |
152 |
155 if ( status < KErrNone ) |
153 if ( status < KErrNone ) |
156 { |
154 { |
157 WRITELOG1( "CHarvesterClientAO::RunL() - Error occured while harvesting, error:%d", status ); |
155 WRITELOG1( "CHarvesterClientAO::RunL() - Error occured while harvesting, error:%d", status ); |
158 } |
156 } |
159 |
157 |
160 // Callback to client process |
158 // Callback to client process |
161 if ( iObserver && iURI ) |
159 if ( iObserver ) |
162 { |
160 { |
163 WRITELOG( "CHarvesterClientAO::RunL() - Request complete - calling callback" ); |
161 WRITELOG( "CHarvesterClientAO::RunL() - ECompleteRequest - calling callback" ); |
164 TPtrC16 uri( iURI->Des() ); |
162 iObserver->HarvestingComplete( iURI, status ); |
165 iObserver->HarvestingComplete( uri, status ); |
|
166 } |
163 } |
167 |
164 |
168 delete iURI; |
165 // if the request was not canceled or server is not terminated, Activating AO again |
169 iURI = NULL; |
166 if ( status != KErrCancel && status != KErrServerTerminated && iObserver && !iCancelled ) |
170 iRequestComplete = ETrue; |
167 { |
|
168 WRITELOG( "CHarvesterClientAO::RunL() - not cancelled or terminated, calling Active" ); |
|
169 Active(); |
|
170 } |
|
171 WRITELOG( "CHarvesterClientAO::RunL() - end" ); |
171 } |
172 } |
172 |
173 |
173 // --------------------------------------------------------------------------- |
174 // --------------------------------------------------------------------------- |
174 // RunError |
175 // RunError |
175 // --------------------------------------------------------------------------- |
176 // --------------------------------------------------------------------------- |
180 TInt CHarvesterClientAO::RunError( TInt ) |
181 TInt CHarvesterClientAO::RunError( TInt ) |
181 #endif |
182 #endif |
182 { |
183 { |
183 WRITELOG1( "CHarvesterClientAO::RunError(), errorcode: %d", aError ); |
184 WRITELOG1( "CHarvesterClientAO::RunError(), errorcode: %d", aError ); |
184 |
185 |
185 iNotificationQueue->Cleanup( EFalse ); |
|
186 iRequestComplete = ETrue; |
|
187 |
|
188 return KErrNone; |
186 return KErrNone; |
189 } |
187 } |
190 |
188 |
191 // --------------------------------------------------------------------------- |
189 // --------------------------------------------------------------------------- |
192 // RequestComplete |
190 // Active |
193 // --------------------------------------------------------------------------- |
191 // --------------------------------------------------------------------------- |
194 // |
192 // |
195 TBool CHarvesterClientAO::RequestComplete() |
193 void CHarvesterClientAO::CancelRequest() |
196 { |
194 { |
197 return iRequestComplete; |
195 WRITELOG( "CHarvesterClientAO::CancelRequest" ); |
|
196 if( !iCancelled ) |
|
197 { |
|
198 WRITELOG( "CHarvesterClientAO::CancelRequest - not cancelled, calling Cancel" ); |
|
199 iCancelled = ETrue; |
|
200 Cancel(); |
|
201 } |
|
202 if( !IsActive() ) |
|
203 { |
|
204 WRITELOG( "CHarvesterClientAO::CancelRequest - setting priority to High" ); |
|
205 SetPriority( CActive::EPriorityHigh ); |
|
206 } |
198 } |
207 } |
199 |
208 |