|
1 /* |
|
2 * Copyright (c) 2007-2009 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: Harvester client active object |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "harvesterclientao.h" |
|
20 #include "harvestercommon.h" |
|
21 #include "harvesterlog.h" |
|
22 #include "mdsutils.h" |
|
23 |
|
24 |
|
25 // --------------------------------------------------------------------------- |
|
26 // NewL |
|
27 // --------------------------------------------------------------------------- |
|
28 // |
|
29 CHarvesterClientAO* CHarvesterClientAO::NewL( RHarvesterClient& aHarvesterClient ) |
|
30 { |
|
31 WRITELOG( "CHarvesterClientAO::NewL()" ); |
|
32 CHarvesterClientAO* self = new (ELeave) CHarvesterClientAO( aHarvesterClient ); |
|
33 CleanupStack::PushL( self ); |
|
34 self->ConstructL(); |
|
35 CleanupStack::Pop( self ); |
|
36 return self; |
|
37 } |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // ~CHarvesterClientAO |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 CHarvesterClientAO::~CHarvesterClientAO() // destruct |
|
44 { |
|
45 WRITELOG( "CHarvesterClientAO::~CHarvesterClientAO()" ); |
|
46 Cancel(); |
|
47 } |
|
48 |
|
49 // --------------------------------------------------------------------------- |
|
50 // CHarvesterClientAO |
|
51 // First-phase C++ constructor |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 CHarvesterClientAO::CHarvesterClientAO( RHarvesterClient& aHarvesterClient ) |
|
55 : CActive( CActive::EPriorityStandard ), |
|
56 iObserver( NULL ), |
|
57 iHarvesterClient( aHarvesterClient ) |
|
58 { |
|
59 WRITELOG( "CHarvesterClientAO::CHarvesterClientAO()" ); |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // ConstructL |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 void CHarvesterClientAO::ConstructL() // second-phase constructor |
|
67 { |
|
68 WRITELOG( "CHarvesterClientAO::ConstructL()" ); |
|
69 CActiveScheduler::Add( this ); |
|
70 } |
|
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 // SetObserver |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 void CHarvesterClientAO::SetObserver( MHarvestObserver* aObserver ) |
|
77 { |
|
78 WRITELOG( "CHarvesterClientAO::SetObserver()" ); |
|
79 iObserver = aObserver; |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // RemoveObserver |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 void CHarvesterClientAO::RemoveObserver( MHarvestObserver* aObserver ) |
|
87 { |
|
88 WRITELOG( "CHarvesterClientAO::RemoveObserver()" ); |
|
89 if ( aObserver == iObserver ) |
|
90 { |
|
91 if ( iObserver ) |
|
92 { |
|
93 WRITELOG( "CHarvesterClientAO::RemoveObserver() - deleting observer" ); |
|
94 iObserver = NULL; |
|
95 } |
|
96 } |
|
97 } |
|
98 |
|
99 // --------------------------------------------------------------------------- |
|
100 // DoCancel |
|
101 // --------------------------------------------------------------------------- |
|
102 // |
|
103 void CHarvesterClientAO::DoCancel() |
|
104 { |
|
105 WRITELOG( "CHarvesterClientAO::DoCancel()" ); |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------------------------- |
|
109 // Active |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 void CHarvesterClientAO::Active() |
|
113 { |
|
114 if (!IsActive()) |
|
115 { |
|
116 iHarvesterClient.RegisterHarvestComplete(iURI, iStatus); |
|
117 SetActive(); |
|
118 } |
|
119 } |
|
120 |
|
121 // --------------------------------------------------------------------------- |
|
122 // RunL |
|
123 // --------------------------------------------------------------------------- |
|
124 // |
|
125 void CHarvesterClientAO::RunL() |
|
126 { |
|
127 WRITELOG( "CHarvesterClientAO::RunL()" ); |
|
128 |
|
129 const TInt status = iStatus.Int(); |
|
130 |
|
131 if ( status < KErrNone ) |
|
132 { |
|
133 WRITELOG1( "CHarvesterClientAO::RunL() - Error occured while harvesting, error:%d", status ); |
|
134 } |
|
135 |
|
136 // Callback to client process |
|
137 if ( iObserver ) |
|
138 { |
|
139 WRITELOG( "CHarvesterClientAO::RunL() - ECompleteRequest - calling callback" ); |
|
140 iObserver->HarvestingComplete( iURI, status ); |
|
141 } |
|
142 |
|
143 // if the request was not canceled or server is not terminated, Activating AO again |
|
144 if ( status != KErrCancel && status != KErrServerTerminated ) |
|
145 { |
|
146 Active(); |
|
147 } |
|
148 } |
|
149 |
|
150 // --------------------------------------------------------------------------- |
|
151 // RunError |
|
152 // --------------------------------------------------------------------------- |
|
153 // |
|
154 #ifdef _DEBUG |
|
155 TInt CHarvesterClientAO::RunError( TInt aError ) |
|
156 #else |
|
157 TInt CHarvesterClientAO::RunError( TInt ) |
|
158 #endif |
|
159 { |
|
160 WRITELOG1( "CHarvesterClientAO::RunError(), errorcode: %d", aError ); |
|
161 |
|
162 return KErrNone; |
|
163 } |