|
1 // Copyright (c) 2003-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 "TestAsyncCodec.h" |
|
17 |
|
18 |
|
19 // CTestAsyncReadCodec |
|
20 CTestAsyncReadCodec::CTestAsyncReadCodec(CTestAsyncDecoder& aDecoder): |
|
21 iDecoder(aDecoder) |
|
22 { |
|
23 } |
|
24 |
|
25 void CTestAsyncReadCodec::ConstructL () |
|
26 { |
|
27 CImageReadCodec::ConstructL(); |
|
28 |
|
29 TTimeIntervalMicroSeconds32 KQuarterSecond = 250000; |
|
30 iTimer = CUtilityTimer::NewL(KQuarterSecond, *this); |
|
31 } |
|
32 |
|
33 CTestAsyncReadCodec* CTestAsyncReadCodec::NewL(CTestAsyncDecoder &aDecoder) |
|
34 { |
|
35 CTestAsyncReadCodec* self = new (ELeave) CTestAsyncReadCodec(aDecoder); |
|
36 CleanupStack::PushL(self); |
|
37 self->ConstructL(); |
|
38 CleanupStack::Pop(self); |
|
39 return self; |
|
40 } |
|
41 |
|
42 CTestAsyncReadCodec::~CTestAsyncReadCodec() |
|
43 { |
|
44 delete iTimer; |
|
45 } |
|
46 |
|
47 TFrameState CTestAsyncReadCodec::ProcessFrameL(TBufPtr8& /*aSrc*/) |
|
48 { |
|
49 // pause for a quarter of a second to look like we're doing somthing |
|
50 iTimer->InitializeTimer(); |
|
51 |
|
52 return EFrameComplete; |
|
53 } |
|
54 |
|
55 TFrameState CTestAsyncReadCodec::ProcessFrameHeaderL(TBufPtr8& /*aData*/) |
|
56 { |
|
57 return EFrameComplete; |
|
58 } |
|
59 |
|
60 void CTestAsyncReadCodec::Complete() |
|
61 { |
|
62 iTimer->Cancel(); |
|
63 } |
|
64 |
|
65 void CTestAsyncReadCodec::InitFrameL(TFrameInfo& /*aFrameInfo*/, CFrameImageData& /*aFrameImageData*/, TBool /*aDisableErrorDiffusion*/, CFbsBitmap& /*aDestination*/, CFbsBitmap* /*aDestinationMask*/) |
|
66 { |
|
67 } |
|
68 |
|
69 void CTestAsyncReadCodec::TimerExpired() |
|
70 { |
|
71 iDecoder.ProcessFrameComplete(KErrNone); |
|
72 } |
|
73 |
|
74 |
|
75 // CTestAsyncWriteCodec |
|
76 CTestAsyncWriteCodec::CTestAsyncWriteCodec(CTestAsyncEncoder& aEncoder): |
|
77 iEncoder(aEncoder) |
|
78 { |
|
79 } |
|
80 |
|
81 void CTestAsyncWriteCodec::ConstructL () |
|
82 { |
|
83 CImageWriteCodec::ConstructL(); |
|
84 |
|
85 TTimeIntervalMicroSeconds32 KQuarterSecond = 250000; |
|
86 iTimer = CUtilityTimer::NewL(KQuarterSecond, *this); |
|
87 } |
|
88 |
|
89 CTestAsyncWriteCodec* CTestAsyncWriteCodec::NewL(CTestAsyncEncoder &aEncoder) |
|
90 { |
|
91 CTestAsyncWriteCodec* self = new (ELeave) CTestAsyncWriteCodec(aEncoder); |
|
92 CleanupStack::PushL(self); |
|
93 self->ConstructL(); |
|
94 CleanupStack::Pop(self); |
|
95 return self; |
|
96 } |
|
97 |
|
98 CTestAsyncWriteCodec::~CTestAsyncWriteCodec() |
|
99 { |
|
100 delete iTimer; |
|
101 } |
|
102 |
|
103 void CTestAsyncWriteCodec::InitFrameL(TBufPtr8& aDst, const CFbsBitmap& /*aSource*/) |
|
104 { |
|
105 iDst = &aDst; |
|
106 } |
|
107 |
|
108 TFrameState CTestAsyncWriteCodec::ProcessFrameL(TBufPtr8& /*aDst*/) |
|
109 { |
|
110 // pause for a quarter of a second to look like we're doing somthing |
|
111 iTimer->InitializeTimer(); |
|
112 |
|
113 return EFrameComplete; |
|
114 } |
|
115 |
|
116 |
|
117 |
|
118 void CTestAsyncWriteCodec::Complete() |
|
119 { |
|
120 iTimer->Cancel(); |
|
121 } |
|
122 |
|
123 |
|
124 void CTestAsyncWriteCodec::TimerExpired() |
|
125 { |
|
126 iEncoder.ProcessFrameComplete(KErrNone); |
|
127 } |
|
128 |
|
129 |
|
130 // CUtilityTimer |
|
131 CUtilityTimer* CUtilityTimer::NewL(TTimeIntervalMicroSeconds32& aDelay, MTimerObserver& aObserver) |
|
132 { |
|
133 CUtilityTimer* self = new (ELeave) CUtilityTimer(aObserver); |
|
134 CleanupStack::PushL(self); |
|
135 self->ConstructL(aDelay); |
|
136 CleanupStack::Pop(self); |
|
137 return self; |
|
138 } |
|
139 |
|
140 void CUtilityTimer::ConstructL(TTimeIntervalMicroSeconds32& aDelay) |
|
141 { |
|
142 CTimer::ConstructL(); |
|
143 |
|
144 iDelay = aDelay; |
|
145 CActiveScheduler::Add(this); |
|
146 } |
|
147 |
|
148 CUtilityTimer::~CUtilityTimer() |
|
149 { |
|
150 Cancel(); |
|
151 } |
|
152 |
|
153 void CUtilityTimer::InitializeTimer() |
|
154 { |
|
155 // Request another wait - assume not active |
|
156 CTimer::After(iDelay); |
|
157 } |
|
158 |
|
159 void CUtilityTimer::RunL() |
|
160 { |
|
161 if (iStatus.Int() == KErrNone) |
|
162 iObserver.TimerExpired(); |
|
163 } |
|
164 |
|
165 void CUtilityTimer::DoCancel() |
|
166 { |
|
167 } |
|
168 |
|
169 |
|
170 CUtilityTimer::CUtilityTimer(MTimerObserver& aObserver) : |
|
171 CTimer(CActive::EPriorityUserInput), |
|
172 iObserver(aObserver) |
|
173 { |
|
174 } |
|
175 |