|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "saasimadaptation.h" |
|
17 |
|
18 #include "startupadaptationadapter.h" |
|
19 #include "ssmdebug.h" |
|
20 #include "clayerpanic.h" |
|
21 /* |
|
22 * Creates a new object associated with the passed in CStartupAdaptationAdapter |
|
23 * |
|
24 * @internalComponent |
|
25 */ |
|
26 CSaaSimAdaptation* CSaaSimAdaptation::NewL(CStartupAdaptationAdapter* aAdapter) |
|
27 { |
|
28 CSaaSimAdaptation* self = new (ELeave) CSaaSimAdaptation(aAdapter); |
|
29 CleanupStack::PushL(self); |
|
30 self->ConstructL(); |
|
31 CleanupStack::Pop(self); |
|
32 return self; |
|
33 } |
|
34 |
|
35 /* |
|
36 * Destructor for this object |
|
37 * |
|
38 * @internalComponent |
|
39 */ |
|
40 CSaaSimAdaptation::~CSaaSimAdaptation() |
|
41 { |
|
42 iEventQueue.Close(); |
|
43 } |
|
44 |
|
45 /* |
|
46 * Decrements the reference count for this object, deleting it if necessary |
|
47 * |
|
48 * @internalComponent |
|
49 */ |
|
50 void CSaaSimAdaptation::Release() |
|
51 { |
|
52 // This MClass is owned by the singleton CStartupAdaptationAdapter class so |
|
53 // release should do nothing. |
|
54 } |
|
55 |
|
56 /* |
|
57 * |
|
58 * |
|
59 * @internalComponent |
|
60 */ |
|
61 void CSaaSimAdaptation::GetSimOwned(TDes8& aOwnedPckg, TRequestStatus& aStatus) |
|
62 { |
|
63 // If this adaptation is busy then complete with KErrInUse |
|
64 if(Busy()) |
|
65 { |
|
66 TRequestStatus* statusPtr = &aStatus; |
|
67 User::RequestComplete(statusPtr, KErrInUse); |
|
68 return; |
|
69 } |
|
70 // Set this request status |
|
71 SetRequestStatus(&aStatus); |
|
72 aStatus = KRequestPending; |
|
73 // No outstand requests so set up command id |
|
74 SetCommandId(StartupAdaptation::EGetSimOwned); |
|
75 // No parameters to set to pass in |
|
76 |
|
77 // Remember the package to pass data back into |
|
78 iReturnDes = &aOwnedPckg; |
|
79 // Pass this to the adapter |
|
80 TRAPD(err, iAdapter->QueueDispatchL(this)); |
|
81 if(err != KErrNone) |
|
82 { |
|
83 // Failed to queue adaptation, complete with error |
|
84 SetRequestStatus(NULL); |
|
85 TRequestStatus* statusPtr = &aStatus; |
|
86 User::RequestComplete(statusPtr, err); |
|
87 } |
|
88 } |
|
89 |
|
90 /* |
|
91 * |
|
92 * |
|
93 * @internalComponent |
|
94 */ |
|
95 void CSaaSimAdaptation::GetCancel() |
|
96 { |
|
97 CancelRequest(); |
|
98 } |
|
99 |
|
100 /* |
|
101 * |
|
102 * |
|
103 * @internalComponent |
|
104 */ |
|
105 void CSaaSimAdaptation::NotifySimEvent(TDes8& aTypePckg, TRequestStatus& aStatus) |
|
106 { |
|
107 if(iEventStatus != NULL) |
|
108 { |
|
109 DEBUGPRINT1A("SAA - Multiple notify SIM event requests detected, completing with KErrInUse"); |
|
110 TRequestStatus* statusPtr = &aStatus; |
|
111 User::RequestComplete(statusPtr, KErrInUse); |
|
112 return; |
|
113 } |
|
114 if(iEventQueue.Count() != 0) |
|
115 { |
|
116 // Complete immediately with an event from the queue |
|
117 DEBUGPRINT1A("SAA - Completing notify SIM event immediately with queued event"); |
|
118 // Read value from array |
|
119 TPckgBuf<TSsmSimEventType> pckgBuf(iEventQueue[0]); |
|
120 // Remove value from array |
|
121 iEventQueue.Remove(0); |
|
122 // Copy descriptor package across |
|
123 aTypePckg.Copy(pckgBuf); |
|
124 // Complete status |
|
125 TRequestStatus* statusPtr = &aStatus; |
|
126 User::RequestComplete(statusPtr, KErrNone); |
|
127 } |
|
128 else |
|
129 { |
|
130 // No events in queue so wait |
|
131 aStatus = KRequestPending; |
|
132 iEventStatus = &aStatus; |
|
133 iEventOutputBuffer = &aTypePckg; |
|
134 } |
|
135 |
|
136 } |
|
137 |
|
138 /* |
|
139 * |
|
140 * |
|
141 * @internalComponent |
|
142 */ |
|
143 void CSaaSimAdaptation::NotifyCancel() |
|
144 { |
|
145 if(iEventStatus != NULL) |
|
146 { |
|
147 User::RequestComplete(iEventStatus, KErrCancel); |
|
148 iEventStatus = NULL; |
|
149 } |
|
150 // Clear buffer |
|
151 iEventOutputBuffer = NULL; |
|
152 } |
|
153 |
|
154 /* |
|
155 * Constructs a new state adaptation object and associates it with aAdapter |
|
156 * |
|
157 * @internalComponent |
|
158 */ |
|
159 CSaaSimAdaptation::CSaaSimAdaptation(CStartupAdaptationAdapter* aAdapter) |
|
160 : CAdaptationBase(aAdapter) |
|
161 { |
|
162 |
|
163 } |
|
164 |
|
165 /** |
|
166 * Number of events to pre-allocate in the event queue |
|
167 * |
|
168 * @internalComponent |
|
169 */ |
|
170 const TInt KEventQueueReserveValue = 8; |
|
171 |
|
172 /* |
|
173 * Second phase of construction |
|
174 * |
|
175 * @internalComponent |
|
176 */ |
|
177 void CSaaSimAdaptation::ConstructL() |
|
178 { |
|
179 // Preallocate event queue some memory |
|
180 iEventQueue.ReserveL(KEventQueueReserveValue); |
|
181 } |
|
182 |
|
183 /** |
|
184 * See CAdaptationBase for description of method. |
|
185 * |
|
186 * @internalComponent |
|
187 */ |
|
188 void CSaaSimAdaptation::RequestComplete(const StartupAdaptation::TCommand __DEBUG_ONLY(aCommandId), TDesC8& aRetPckg) |
|
189 { |
|
190 DEBUGPRINT3A("SAA - Response received from adaptation with commandId: %d, expecting %d", aCommandId, CommandId()); |
|
191 __ASSERT_DEBUG(aCommandId == CommandId(), CLAYER_PANIC(ECLayerUnexpectedCommandResponse)); |
|
192 // Both Owned and Changed requests have the same return type so no need to switch on CommandId() |
|
193 StartupAdaptation::TBooleanResponsePckg booleanResponsePckg; |
|
194 booleanResponsePckg.Copy(aRetPckg); |
|
195 if(booleanResponsePckg().iErrorCode == KErrNone) |
|
196 { |
|
197 // Copy the boolean value across to the descriptor passed in |
|
198 TPckgBuf<TBool> boolPckg; |
|
199 boolPckg() = booleanResponsePckg().iValue; |
|
200 iReturnDes->Copy(boolPckg); |
|
201 // Null iReturnDes as it has no further use |
|
202 iReturnDes = NULL; |
|
203 } |
|
204 CompleteRequestStatus(booleanResponsePckg().iErrorCode); |
|
205 } |
|
206 |
|
207 /** |
|
208 * See CAdaptationBase for description of method. |
|
209 * |
|
210 * @internalComponent |
|
211 */ |
|
212 TDesC8* CSaaSimAdaptation::ParameterPckg() |
|
213 { |
|
214 // No methods in this adaptation have any parameters so return an empty descriptor |
|
215 return &iNullBuf; |
|
216 } |
|
217 |
|
218 /** |
|
219 * Processes the event passed in and distributes to waiting client or queues event. |
|
220 * |
|
221 * @internalComponent |
|
222 */ |
|
223 void CSaaSimAdaptation::ProcessEventL(TSsmSimEventType aEventType) |
|
224 { |
|
225 DEBUGPRINT2A("SAA - Sim adaptation processing event with type: %d", aEventType); |
|
226 if(iEventStatus == NULL) |
|
227 { |
|
228 // Need to queue event as nothing is waiting to be notified |
|
229 iEventQueue.AppendL(aEventType); |
|
230 } |
|
231 else |
|
232 { |
|
233 // Client waiting for event |
|
234 __ASSERT_DEBUG(iEventOutputBuffer != NULL, CLAYER_PANIC(ECLayerNullSimEventBuffer)); |
|
235 TPckgBuf<TSsmSimEventType> pckgBuf(aEventType); |
|
236 // Copy event across |
|
237 iEventOutputBuffer->Copy(pckgBuf); |
|
238 // Complete status |
|
239 User::RequestComplete(iEventStatus, KErrNone); |
|
240 // Clear event status and buffer |
|
241 iEventOutputBuffer = NULL; |
|
242 iEventStatus = NULL; |
|
243 } |
|
244 |
|
245 } |