|
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: Batch ext plugin implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "alfbatchextplugin.h" |
|
20 #include "alfbatchextpluginconstants.h" |
|
21 #include <implementationproxy.h> |
|
22 #include <alf/alfconstants.h> |
|
23 #include <alf/alflayouthandlers.h> |
|
24 |
|
25 class CAlfBatchExtPluginExtension : public CBase, public MAlfExtension |
|
26 { |
|
27 public: |
|
28 ~CAlfBatchExtPluginExtension(); |
|
29 virtual void Release(); |
|
30 virtual TAny* GetInterface( const THuiInterfaceSupport& aInterface ); |
|
31 virtual void HandleCmdL( TInt aCommandId, const TDesC8& aInputBuffer, TDes8& aResponse ); |
|
32 private: |
|
33 RArray<TInt> iReceived; |
|
34 }; |
|
35 |
|
36 MAlfExtension* TAlfBatchExtPlugin::CreateExtensionL( |
|
37 const TInt aObjectId, |
|
38 const TDesC8& /*aInitialParams*/, |
|
39 MAlfInterfaceProvider& /*aResolver*/ ) |
|
40 { |
|
41 MAlfExtension* result = 0; |
|
42 switch( aObjectId ) |
|
43 { |
|
44 case EAlfBatchExtPluginCreateExtension: |
|
45 { |
|
46 result = new (ELeave) CAlfBatchExtPluginExtension; |
|
47 break; |
|
48 } |
|
49 |
|
50 default: |
|
51 User::Leave( KErrNotSupported ); |
|
52 } |
|
53 return result; |
|
54 } |
|
55 |
|
56 void TAlfBatchExtPlugin::Release() |
|
57 { |
|
58 delete this; |
|
59 } |
|
60 |
|
61 CAlfBatchExtPluginExtension::~CAlfBatchExtPluginExtension() |
|
62 { |
|
63 iReceived.Close(); |
|
64 } |
|
65 |
|
66 void CAlfBatchExtPluginExtension::Release() |
|
67 { |
|
68 delete this; |
|
69 } |
|
70 |
|
71 TAny* CAlfBatchExtPluginExtension::GetInterface( const THuiInterfaceSupport& /*aInterface*/ ) |
|
72 { |
|
73 return NULL; |
|
74 } |
|
75 |
|
76 void CAlfBatchExtPluginExtension::HandleCmdL( TInt aCommandId, const TDesC8& aInputBuffer, TDes8& aResponse ) |
|
77 { |
|
78 switch ( aCommandId ) |
|
79 { |
|
80 case EAlfBatchExtensionCmdReset: |
|
81 iReceived.Close(); |
|
82 break; |
|
83 |
|
84 case EAlfBatchExtensionCmdGetCount: |
|
85 { |
|
86 TPckgBuf<TInt> countPckg( iReceived.Count() ); |
|
87 aResponse.Copy( countPckg ); |
|
88 } |
|
89 break; |
|
90 |
|
91 case EAlfBatchExtensionCmdGetIndex: |
|
92 { |
|
93 TInt* param = (TInt*)aInputBuffer.Ptr(); |
|
94 |
|
95 if ( *param >= 0 && *param < iReceived.Count() ) |
|
96 { |
|
97 TPckgBuf<TInt> result( iReceived[ *param ] ); |
|
98 aResponse.Copy( result ); |
|
99 } |
|
100 else |
|
101 { |
|
102 User::Leave( KErrArgument ); |
|
103 } |
|
104 } |
|
105 break; |
|
106 |
|
107 case EAlfBatchExtensionCmdInteger: |
|
108 { |
|
109 TInt* param = (TInt*)aInputBuffer.Ptr(); |
|
110 iReceived.AppendL( *param ); |
|
111 } |
|
112 break; |
|
113 |
|
114 case EAlfBatchExtensionCmdReal: |
|
115 { |
|
116 TReal32* param = (TReal32*)aInputBuffer.Ptr(); |
|
117 TInt asInteger = *param; |
|
118 iReceived.AppendL( asInteger ); |
|
119 } |
|
120 break; |
|
121 |
|
122 case EAlfBatchExtensionCmdNotSupported: |
|
123 User::Leave( KErrNotSupported ); |
|
124 break; |
|
125 |
|
126 default: |
|
127 { |
|
128 if ( aCommandId >= EAlfBatchExtensionCmdBufferMin && |
|
129 aCommandId <= EAlfBatchExtensionCmdBufferMax ) |
|
130 { |
|
131 const TInt length = aCommandId - EAlfBatchExtensionCmdBufferMin; |
|
132 |
|
133 if ( aInputBuffer.Length() == length ) |
|
134 { |
|
135 for ( TInt ii = 0; ii < length; ii++ ) |
|
136 { |
|
137 TUint8 val = (TUint8)ii; |
|
138 if ( aInputBuffer[ ii ] != val ) |
|
139 { |
|
140 User::Leave( KErrArgument ); |
|
141 } |
|
142 } |
|
143 iReceived.AppendL( aCommandId ); |
|
144 } |
|
145 else |
|
146 { |
|
147 User::Leave( KErrArgument ); |
|
148 } |
|
149 } |
|
150 else |
|
151 { |
|
152 User::Leave( KErrNotSupported ); |
|
153 } |
|
154 } |
|
155 break; |
|
156 } |
|
157 } |
|
158 |
|
159 // Global functions: |
|
160 |
|
161 MAlfExtensionFactory* Instance() |
|
162 { |
|
163 TAlfBatchExtPlugin* me = NULL; |
|
164 me = new TAlfBatchExtPlugin; |
|
165 return me; |
|
166 } |
|
167 |
|
168 const TImplementationProxy ImplementationTable[] = |
|
169 { |
|
170 #ifdef __EABI__ |
|
171 {{KAlfBatchExtPluginImplementationId}, (TFuncPtr)Instance} |
|
172 #else |
|
173 {{KAlfBatchExtPluginImplementationId}, Instance} |
|
174 #endif |
|
175 }; |
|
176 |
|
177 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount) |
|
178 { |
|
179 aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy) ; |
|
180 return ImplementationTable; |
|
181 } |