1 /* |
|
2 * Copyright (c) 2007 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ahplugin.h" |
|
20 #include "cpluginvalidator.h" |
|
21 #include "actionhandlerinterface.h" |
|
22 #include "ahplugindefs.h" |
|
23 #include "serviceerrno.h" |
|
24 |
|
25 using namespace LIW; |
|
26 |
|
27 // --------------------------------------------------------------------------- |
|
28 // |
|
29 // --------------------------------------------------------------------------- |
|
30 // |
|
31 CActionHandlerInterface::CActionHandlerInterface() |
|
32 { |
|
33 |
|
34 } |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 void CActionHandlerInterface::ConstructL() |
|
41 { |
|
42 iPluginManager = CPluginValidator::NewL( |
|
43 TUid::Uid( KAHPluginInterfaceUid ) ); |
|
44 } |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 CActionHandlerInterface* CActionHandlerInterface::NewL() |
|
51 { |
|
52 CActionHandlerInterface* self = CActionHandlerInterface::NewLC( ); |
|
53 CleanupStack::Pop( self ); |
|
54 return self; |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 CActionHandlerInterface* CActionHandlerInterface::NewLC() |
|
62 { |
|
63 CActionHandlerInterface* self = new( ELeave ) CActionHandlerInterface; |
|
64 CleanupStack::PushL( self ); |
|
65 self->ConstructL( ); |
|
66 return self; |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 CActionHandlerInterface::~CActionHandlerInterface() |
|
74 { |
|
75 delete iPluginManager; |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // Executes the SAPI as per params |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 void CActionHandlerInterface::ExecuteCmdL( const TDesC8& aCmdName, |
|
83 const CLiwGenericParamList& aInParamList, |
|
84 CLiwGenericParamList& aOutParamList, TUint aCmdOptions, |
|
85 MLiwNotifyCallback* aCallback ) |
|
86 { |
|
87 TInt errCode(KErrNotSupported); |
|
88 aOutParamList.AppendL( TLiwGenericParam( EGenericParamError, |
|
89 TLiwVariant( ErrCodeConversion( KErrNone ) ) ) ); |
|
90 // Check the command name;Cmd name should be Execute |
|
91 if ( !aCmdName.Compare( KExecute ) && !aCallback && !aCmdOptions ) |
|
92 { |
|
93 TUid pluginUid= TUid::Null( ); |
|
94 CLiwDefaultMap* map = CLiwDefaultMap::NewLC( ); |
|
95 //extract command params |
|
96 if ( !ExtractUid( aInParamList, pluginUid ) &&!ExtractMap( |
|
97 aInParamList, map ) ) |
|
98 { |
|
99 TRAP(errCode, ExecuteActionL( pluginUid, map )); |
|
100 } |
|
101 else |
|
102 { |
|
103 errCode = KErrNotSupported; |
|
104 } |
|
105 CleanupStack::PopAndDestroy( map ); |
|
106 } |
|
107 if ( errCode != KErrNone ) |
|
108 { |
|
109 aOutParamList.Reset( ); |
|
110 aOutParamList.AppendL( TLiwGenericParam( EGenericParamError, |
|
111 TLiwVariant( ErrCodeConversion( errCode ) ) ) ); |
|
112 } |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // Closes the interface |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 void CActionHandlerInterface::Close() |
|
120 { |
|
121 delete this; |
|
122 } |
|
123 |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 // --------------------------------------------------------------------------- |
|
127 // |
|
128 TInt CActionHandlerInterface::ExtractUid( |
|
129 const CLiwGenericParamList& aInParamList, TUid& aUid ) |
|
130 |
|
131 { |
|
132 TInt errCode(KErrArgument); |
|
133 const TLiwGenericParam* param= NULL; |
|
134 TInt pos( 0); |
|
135 param = aInParamList.FindFirst( pos, KPluginUid ); |
|
136 if ( param && pos !=KErrNotFound ) |
|
137 { |
|
138 //get plugin uid |
|
139 if ( param->Value().Get( aUid ) ) |
|
140 { |
|
141 errCode = KErrNone; |
|
142 } |
|
143 else |
|
144 { |
|
145 TUint plugin( 0 ); |
|
146 if ( param->Value().Get( plugin ) ) |
|
147 { |
|
148 aUid = TUid::Uid( plugin ); |
|
149 errCode = KErrNone; |
|
150 } |
|
151 } |
|
152 } |
|
153 return errCode; |
|
154 } |
|
155 |
|
156 // --------------------------------------------------------------------------- |
|
157 // Extract Map |
|
158 // --------------------------------------------------------------------------- |
|
159 // |
|
160 TInt CActionHandlerInterface::ExtractMap( |
|
161 const CLiwGenericParamList& aInParamList, CLiwMap* aMap ) |
|
162 { |
|
163 TInt errCode(KErrArgument); |
|
164 const TLiwGenericParam* param= NULL; |
|
165 TInt pos( 0); |
|
166 param = aInParamList.FindFirst( pos, KMap ); |
|
167 if ( param && pos !=KErrNotFound ) |
|
168 { |
|
169 //get action type |
|
170 if ( param->Value().Get( *aMap ) ) |
|
171 { |
|
172 errCode = KErrNone; |
|
173 } |
|
174 } |
|
175 return errCode; |
|
176 } |
|
177 |
|
178 // --------------------------------------------------------------------------- |
|
179 // ErrCode Conversion |
|
180 // --------------------------------------------------------------------------- |
|
181 // |
|
182 TInt32 CActionHandlerInterface::ErrCodeConversion( TInt code ) |
|
183 { |
|
184 TInt32 err; |
|
185 switch ( code ) |
|
186 { |
|
187 case KErrNone: |
|
188 err= SErrNone; |
|
189 break; |
|
190 |
|
191 case KErrNotFound: |
|
192 err= SErrNotFound; |
|
193 break; |
|
194 |
|
195 case KErrNoMemory: |
|
196 err = SErrNoMemory; |
|
197 break; |
|
198 |
|
199 case KErrInUse: |
|
200 err = SErrServiceInUse; |
|
201 break; |
|
202 |
|
203 case KErrNotSupported: |
|
204 err = SErrServiceNotSupported; |
|
205 break; |
|
206 |
|
207 case KErrBadName: |
|
208 err = SErrBadArgumentType; |
|
209 break; |
|
210 |
|
211 case KErrArgument: |
|
212 err = SErrInvalidServiceArgument; |
|
213 break; |
|
214 |
|
215 default: |
|
216 err = SErrGeneralError; |
|
217 break; |
|
218 } |
|
219 |
|
220 return err; |
|
221 |
|
222 } |
|
223 |
|
224 // --------------------------------------------------------------------------- |
|
225 // CActionHandlerInterface::ExecuteActionL |
|
226 // Gets required plugin and triggers action execution |
|
227 // --------------------------------------------------------------------------- |
|
228 // |
|
229 void CActionHandlerInterface::ExecuteActionL( const TUid aUid, |
|
230 const CLiwMap* aMap ) |
|
231 { |
|
232 __ASSERT_DEBUG( aMap , User::Panic( _L("actionhandlerinterface"), 0 ) ); |
|
233 CAHPlugin* pluginInstance = |
|
234 static_cast<CAHPlugin*>( iPluginManager->GetImplementation( aUid ) ); |
|
235 |
|
236 if ( pluginInstance ) |
|
237 { |
|
238 User::LeaveIfError( pluginInstance->ExecuteActionL( aMap ) ); |
|
239 } |
|
240 else |
|
241 { |
|
242 User::Leave( KErrNotFound ); |
|
243 } |
|
244 } |
|
245 |
|