|
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: AlwaysOnline server command operation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "HandleServerCommandOperation.h" |
|
22 #include "AlwaysOnlineManagerLogging.h" |
|
23 |
|
24 // CONSTANTS |
|
25 _LIT8( KAOCmdStart, "AOCmdStart:" ); |
|
26 _LIT8( KAOCmdEnd, ":AOCmdEnd" ); |
|
27 _LIT8( KColon, ":" ); |
|
28 // FORWARD DECLARATIONS |
|
29 |
|
30 // ============================ MEMBER FUNCTIONS =============================== |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // CAOServerCommandHandler::CAOServerCommandHandler |
|
34 // C++ default constructor can NOT contain any code, that |
|
35 // might leave. |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 CAOServerCommandHandler::CAOServerCommandHandler( |
|
39 CMsvSession& aMsvSession, |
|
40 TInt aPriority, |
|
41 TRequestStatus& aObserverRequestStatus, |
|
42 CAlwaysOnlineEComInterface& aPlugin, |
|
43 TManagerServerCommands aCommand ) |
|
44 : |
|
45 CMsvOperation(aMsvSession, aPriority, aObserverRequestStatus), |
|
46 iPlugin( aPlugin ), |
|
47 iCommand( aCommand ) |
|
48 { |
|
49 } |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CAOServerCommandHandler::ConstructL |
|
53 // Symbian 2nd phase constructor can leave. |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 void CAOServerCommandHandler::ConstructL( const TDes8& aParameter) |
|
57 { |
|
58 CActiveScheduler::Add(this); |
|
59 |
|
60 // Copy the contents from the passed parameter into member variable, |
|
61 // so that the contents of the parameter remains in safe memory area. |
|
62 iParameterBuf = aParameter.AllocL(); |
|
63 |
|
64 StartOperationL(); |
|
65 KAOMANAGER_LOGGER_WRITE("CAOServerCommandHandler::ConstructL() Operation Started"); |
|
66 } |
|
67 |
|
68 // ---------------------------------------------------- |
|
69 // CAOServerCommandHandler::StartOperationL |
|
70 // ---------------------------------------------------- |
|
71 // |
|
72 void CAOServerCommandHandler::StartOperationL() |
|
73 { |
|
74 KAOMANAGER_LOGGER_WRITE_FORMAT("CAOServerCommandHandler::StartOperationL() Creating async call for HandleServerCommand(). TManagerServerCommand: %d", iCommand); |
|
75 |
|
76 SetActive(); |
|
77 TRequestStatus* status = &iStatus; |
|
78 User::RequestComplete(status, KErrNone); |
|
79 } |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // CAOServerCommandHandler::NewL |
|
83 // Two-phased constructor. |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 CAOServerCommandHandler* CAOServerCommandHandler::NewL( |
|
87 CMsvSession& aMsvSession, |
|
88 TRequestStatus& aObserverRequestStatus, |
|
89 TManagerServerCommands aCommand, |
|
90 TDes8& aParameter, |
|
91 CAlwaysOnlineEComInterface& aPlugin) |
|
92 { |
|
93 CAOServerCommandHandler* self = new( ELeave ) CAOServerCommandHandler( |
|
94 aMsvSession, |
|
95 CActive::EPriorityIdle, |
|
96 aObserverRequestStatus, |
|
97 aPlugin, |
|
98 aCommand ); |
|
99 |
|
100 KAOMANAGER_LOGGER_WRITE_FORMAT("CAOServerCommandHandler created to address 0x%x", self); |
|
101 |
|
102 CleanupStack::PushL( self ); |
|
103 self->ConstructL( aParameter ); |
|
104 CleanupStack::Pop( self ); |
|
105 |
|
106 return self; |
|
107 } |
|
108 |
|
109 |
|
110 // ---------------------------------------------------- |
|
111 // ~CAOServerCommandHandler |
|
112 // ---------------------------------------------------- |
|
113 // |
|
114 CAOServerCommandHandler::~CAOServerCommandHandler() |
|
115 { |
|
116 Cancel(); |
|
117 delete iParameterBuf; |
|
118 } |
|
119 |
|
120 // ---------------------------------------------------- |
|
121 // CAOServerCommandHandler::ProgressL |
|
122 // ---------------------------------------------------- |
|
123 // |
|
124 const TDesC8& CAOServerCommandHandler::ProgressL() |
|
125 { |
|
126 return iProgress; |
|
127 } |
|
128 |
|
129 // ---------------------------------------------------- |
|
130 // CAOServerCommandHandler::FinalProgress |
|
131 // ---------------------------------------------------- |
|
132 // |
|
133 const TDesC8& CAOServerCommandHandler::FinalProgress() |
|
134 { |
|
135 return iFinalProgress; |
|
136 } |
|
137 |
|
138 // ---------------------------------------------------- |
|
139 // CAOServerCommandHandler::DoCancel |
|
140 // ---------------------------------------------------- |
|
141 void CAOServerCommandHandler::DoCancel() |
|
142 { |
|
143 KAOMANAGER_LOGGER_WRITE("CAOServerCommandHandler::DoCancel() Operation Cancelled"); |
|
144 TRequestStatus* status = &iObserverRequestStatus; |
|
145 User::RequestComplete( status, KErrCancel ); |
|
146 } |
|
147 |
|
148 |
|
149 // ---------------------------------------------------- |
|
150 // CAOServerCommandHandler::RunL |
|
151 // ---------------------------------------------------- |
|
152 void CAOServerCommandHandler::RunL() |
|
153 { |
|
154 KAOMANAGER_LOGGER_WRITE("CAOServerCommandHandler::RunL() Command Issued!"); |
|
155 TAny* response = iPlugin.HandleServerCommandL( iCommand, iParameterBuf ); |
|
156 TRequestStatus* status = &iObserverRequestStatus; |
|
157 User::RequestComplete( status, KErrNone ); |
|
158 SetFinalProgressFromResult( response ); |
|
159 } |
|
160 |
|
161 // ---------------------------------------------------------------------------- |
|
162 // CAOServerCommandHandler::RunError() |
|
163 // ---------------------------------------------------------------------------- |
|
164 // |
|
165 TInt CAOServerCommandHandler::RunError( TInt aError ) |
|
166 { |
|
167 // A leave occurred in plugin command handler. Complete watcher |
|
168 // with error. |
|
169 TRequestStatus* status = &iObserverRequestStatus; |
|
170 User::RequestComplete( status, aError ); |
|
171 return KErrNone; |
|
172 } |
|
173 |
|
174 // ---------------------------------------------------------------------------- |
|
175 // CAOServerCommandHandler::SetFinalProgressFromResult() |
|
176 // ---------------------------------------------------------------------------- |
|
177 // |
|
178 void CAOServerCommandHandler::SetFinalProgressFromResult( TAny* aResponse ) |
|
179 { |
|
180 iFinalProgress.Zero(); |
|
181 |
|
182 iFinalProgress.Append( KAOCmdStart ); |
|
183 iFinalProgress.AppendNum( iPlugin.InstanceUid().iUid ); |
|
184 iFinalProgress.Append( KColon ); |
|
185 iFinalProgress.AppendNum( iCommand ); |
|
186 iFinalProgress.Append( KColon ); |
|
187 |
|
188 // aResponse should be handled based on command. |
|
189 HandleResponse( aResponse ); |
|
190 |
|
191 iFinalProgress.Append( KAOCmdEnd ); |
|
192 } |
|
193 |
|
194 // ---------------------------------------------------------------------------- |
|
195 // CAOServerCommandHandler::HandleResponse() |
|
196 // ---------------------------------------------------------------------------- |
|
197 // |
|
198 void CAOServerCommandHandler::HandleResponse( TAny* aResponse ) |
|
199 { |
|
200 switch ( iCommand ) |
|
201 { |
|
202 case EAOManagerSuicideQuery: |
|
203 // aResponse should contain either 0 or 1. |
|
204 iFinalProgress.AppendNum( reinterpret_cast<TBool>( aResponse ) ); |
|
205 KAOMANAGER_LOGGER_WRITE_FORMAT("CAOServerCommandHandler::HandleResponse() EAOManagerSuicideQuery, aResponse %d", aResponse); |
|
206 break; |
|
207 default: |
|
208 // Other commands doesn't respond anything useful. |
|
209 iFinalProgress.AppendNum( reinterpret_cast<TInt>( aResponse ) ); |
|
210 KAOMANAGER_LOGGER_WRITE_FORMAT("CAOServerCommandHandler::HandleResponse() default, aResponse %d", aResponse); |
|
211 break; |
|
212 } |
|
213 } |
|
214 // End of File |