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: Emualtor support for CCamCameraController part of cameraapp* |
|
15 */ |
|
16 |
|
17 |
|
18 |
|
19 #include "CamCameraCallback.h" |
|
20 #include "CameraappTestBitmapManager.h" |
|
21 #include <ecam.h> |
|
22 #include <AknIconUtils.h> |
|
23 #include <fbs.h> |
|
24 |
|
25 _LIT(KImageFile, "c:\\private\\101F857A\\capture.jpg"); |
|
26 |
|
27 |
|
28 /* |
|
29 * CCamCameraCallBack* CCamCameraCallBack::NewL |
|
30 */ |
|
31 CCamCameraCallBack* CCamCameraCallBack::NewL( |
|
32 MCameraObserver& aController ) |
|
33 { |
|
34 CCamCameraCallBack* self = new( ELeave ) CCamCameraCallBack( aController ); |
|
35 CleanupStack::PushL( self ); |
|
36 self->ConstructL(); |
|
37 CleanupStack::Pop( self ); |
|
38 |
|
39 return self; |
|
40 } |
|
41 |
|
42 /* |
|
43 * CCamCameraCallBack::CCamCameraCallBack |
|
44 */ |
|
45 CCamCameraCallBack::CCamCameraCallBack( |
|
46 MCameraObserver& aController ) |
|
47 : CActive( EPriorityLow ), |
|
48 iController( aController ) |
|
49 { |
|
50 } |
|
51 |
|
52 /* |
|
53 * CCamCameraCallBack::ConstructL() |
|
54 */ |
|
55 void CCamCameraCallBack::ConstructL() |
|
56 { |
|
57 CActiveScheduler::Add( this ); |
|
58 iBitmapManager = CCameraappTestBitmapManager::NewL(); |
|
59 } |
|
60 |
|
61 /* |
|
62 * CCamCameraCallBack::DoCancel |
|
63 */ |
|
64 void CCamCameraCallBack::DoCancel() |
|
65 { |
|
66 // Status update flags |
|
67 iViewFinderFrame = EFalse; |
|
68 iStillPrepareComplete = EFalse; |
|
69 iReserveComplete = EFalse; |
|
70 iPowerOnComplete = EFalse; |
|
71 iCaptureImage = EFalse; |
|
72 |
|
73 // Error status associated with each request |
|
74 iReserveError = KErrNone; |
|
75 iPowerOnError = KErrNone; |
|
76 } |
|
77 |
|
78 /* |
|
79 * CCamCameraCallBack::~CCamCameraCallBack |
|
80 */ |
|
81 CCamCameraCallBack::~CCamCameraCallBack() |
|
82 { |
|
83 delete iBitmapManager; |
|
84 Cancel(); |
|
85 } |
|
86 |
|
87 /* |
|
88 * CCamCameraCallBack::Cancel |
|
89 */ |
|
90 /* |
|
91 void CCamCameraCallBack::Cancel() |
|
92 { |
|
93 CActive::Cancel(); |
|
94 DoCancel(); |
|
95 } |
|
96 */ |
|
97 |
|
98 /* |
|
99 * CCamCameraCallBack::RunL |
|
100 */ |
|
101 void CCamCameraCallBack::RunL() |
|
102 { |
|
103 if ( iStillPrepareComplete ) |
|
104 { |
|
105 DoStillPrepareComplete(); |
|
106 } |
|
107 else if ( iReserveComplete ) |
|
108 { |
|
109 DoReserveComplete(); |
|
110 } |
|
111 else if ( iPowerOnComplete ) |
|
112 { |
|
113 DoPowerOnComplete(); |
|
114 } |
|
115 else if ( iCaptureImage ) |
|
116 { |
|
117 DoCaptureImageL(); |
|
118 } |
|
119 else |
|
120 { |
|
121 } |
|
122 if ( iViewFinderFrame ) |
|
123 { |
|
124 DoViewFinderFrame(); |
|
125 } |
|
126 } |
|
127 |
|
128 /* |
|
129 * CCamCameraCallBack::SetActiveAndCompleteRequest |
|
130 */ |
|
131 void CCamCameraCallBack::SetActiveAndCompleteRequest() |
|
132 { |
|
133 SetActive(); |
|
134 TRequestStatus* statusPtr = &iStatus; |
|
135 User::RequestComplete( statusPtr, KErrNone ); |
|
136 } |
|
137 |
|
138 |
|
139 /* |
|
140 * CCamCameraCallBack::ReserveCompleteRequest |
|
141 */ |
|
142 void |
|
143 CCamCameraCallBack::ReserveCompleteRequest( const TInt aError ) |
|
144 { |
|
145 iReserveError = aError; |
|
146 iReserveComplete = ETrue; |
|
147 if ( !IsActive() ) |
|
148 { |
|
149 SetActiveAndCompleteRequest(); |
|
150 } |
|
151 } |
|
152 |
|
153 /* |
|
154 * CCamCameraCallBack::PowerOnCompleteRequest |
|
155 */ |
|
156 void |
|
157 CCamCameraCallBack::PowerOnCompleteRequest( const TInt aError ) |
|
158 { |
|
159 iPowerOnError = aError; |
|
160 iPowerOnComplete = ETrue; |
|
161 if ( !IsActive() ) |
|
162 { |
|
163 SetActiveAndCompleteRequest(); |
|
164 } |
|
165 } |
|
166 |
|
167 |
|
168 /* |
|
169 * CCamCameraCallBack::StillPrepareComplete |
|
170 */ |
|
171 void CCamCameraCallBack::StillPrepareComplete() |
|
172 { |
|
173 iStillPrepareComplete = ETrue; |
|
174 if ( !IsActive() ) |
|
175 { |
|
176 SetActiveAndCompleteRequest(); |
|
177 } |
|
178 } |
|
179 |
|
180 /* |
|
181 * CCamCameraCallBack::SendViewFinderFrames |
|
182 */ |
|
183 void CCamCameraCallBack::SendViewFinderFrames() |
|
184 { |
|
185 iViewFinderFrame = ETrue; |
|
186 if ( !IsActive() ) |
|
187 { |
|
188 SetActiveAndCompleteRequest(); |
|
189 } |
|
190 } |
|
191 |
|
192 /* |
|
193 * CCamCameraCallBack::StopViewFinderFrames |
|
194 */ |
|
195 void CCamCameraCallBack::StopViewFinderFrames() |
|
196 { |
|
197 iViewFinderFrame = EFalse; |
|
198 } |
|
199 |
|
200 /* |
|
201 * CCamCameraCallBack::RequestCaptureImage |
|
202 */ |
|
203 void CCamCameraCallBack::RequestCaptureImage() |
|
204 { |
|
205 iCaptureImage = ETrue; |
|
206 if ( !IsActive() ) |
|
207 { |
|
208 SetActiveAndCompleteRequest(); |
|
209 } |
|
210 } |
|
211 |
|
212 /* |
|
213 * CCamCameraCallBack::DoReserveComplete |
|
214 */ |
|
215 void CCamCameraCallBack::DoReserveComplete() |
|
216 { |
|
217 iController.ReserveComplete( iReserveError ); |
|
218 iReserveComplete = EFalse; |
|
219 } |
|
220 |
|
221 /* |
|
222 * CCamCameraCallBack::DoPowerOnComplete |
|
223 */ |
|
224 void CCamCameraCallBack::DoPowerOnComplete() |
|
225 { |
|
226 iController.PowerOnComplete( iPowerOnError ); |
|
227 iPowerOnComplete = EFalse; |
|
228 } |
|
229 |
|
230 |
|
231 /* |
|
232 * CCamCameraCallBack::DoStillPrepareComplete |
|
233 */ |
|
234 void CCamCameraCallBack::DoStillPrepareComplete() |
|
235 { |
|
236 iStillPrepareComplete = EFalse; |
|
237 } |
|
238 |
|
239 |
|
240 /* |
|
241 * CCamCameraCallBack::DoViewFinderFrame |
|
242 */ |
|
243 void CCamCameraCallBack::DoViewFinderFrame() |
|
244 { |
|
245 iController.ViewFinderFrameReady( iBitmapManager->NextBitmap() ); |
|
246 |
|
247 if ( iViewFinderFrame ) |
|
248 { |
|
249 if ( !IsActive() ) |
|
250 { |
|
251 SetActiveAndCompleteRequest(); |
|
252 } |
|
253 } |
|
254 |
|
255 } |
|
256 |
|
257 /* |
|
258 * CCamCameraCallBack::DoCaptureImageL |
|
259 */ |
|
260 void CCamCameraCallBack::DoCaptureImageL() |
|
261 { |
|
262 iCaptureImage = EFalse; |
|
263 TInt imageIndex = 0; |
|
264 |
|
265 // Connect to fs |
|
266 RFs fs; |
|
267 User::LeaveIfError( fs.Connect() ); |
|
268 CleanupClosePushL( fs ); |
|
269 |
|
270 // Open file and get size |
|
271 RFile file; |
|
272 TInt size = 0; |
|
273 User::LeaveIfError( file.Open( fs, KImageFile, EFileRead ) ); |
|
274 CleanupClosePushL( file ); |
|
275 User::LeaveIfError( file.Size( size ) ); |
|
276 |
|
277 // Allocate memory |
|
278 HBufC8* data = HBufC8::NewL( size ); |
|
279 TPtr8 dataDes = data->Des(); |
|
280 |
|
281 |
|
282 // Read file content |
|
283 TInt read = file.Read( dataDes, size ); |
|
284 |
|
285 // Clean up |
|
286 CleanupStack::PopAndDestroy( &file ); |
|
287 CleanupStack::PopAndDestroy( &fs ); |
|
288 |
|
289 // Give data to controller |
|
290 iController.ImageReady( NULL, data, KErrNone ); |
|
291 } |
|
292 |
|
293 |
|
294 // End of File |
|