|
1 // Copyright (c) 2008-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 "imageprocessorcallback.h" |
|
17 #include <imageprocessor/imageprocessor.h> |
|
18 #include <imageprocessor/imageprocessorobserver.h> |
|
19 |
|
20 using namespace ImageProcessor; |
|
21 |
|
22 //Free slots allocated to ensure there is enough memory for future callbacks |
|
23 const TInt KCallbackReserveSlots = 20; |
|
24 |
|
25 CImageProcessorCallback* CImageProcessorCallback::NewL(CImgProcessor& aImageProcessor,MImgProcessorObserver& aObserver) |
|
26 { |
|
27 CImageProcessorCallback* self = new (ELeave) CImageProcessorCallback(aImageProcessor,aObserver); |
|
28 CleanupStack::PushL(self); |
|
29 self->ConstructL(); |
|
30 CleanupStack::Pop(self); |
|
31 return self; |
|
32 } |
|
33 |
|
34 CImageProcessorCallback::CImageProcessorCallback(CImgProcessor& aImageProcessor,MImgProcessorObserver& aObserver): |
|
35 CActive(EPriorityNormal),iProcessor(aImageProcessor),iObserver(aObserver) |
|
36 { |
|
37 CActiveScheduler::Add(this); |
|
38 } |
|
39 |
|
40 void CImageProcessorCallback::ConstructL() |
|
41 { |
|
42 iCallbackInfo.ReserveL(KCallbackReserveSlots); |
|
43 } |
|
44 |
|
45 CImageProcessorCallback::~CImageProcessorCallback() |
|
46 { |
|
47 __ASSERT_ALWAYS(!IsActive(),Cancel()); |
|
48 iCallbackInfo.Close(); |
|
49 } |
|
50 |
|
51 void CImageProcessorCallback::AddCallback(TInt aEventId, TUid aUid, TInt aId, TInt aError) |
|
52 { |
|
53 TInt err = iCallbackInfo.Append(TCallbackInfo(aEventId, aUid, aId, aError)); |
|
54 if (err == KErrNoMemory) |
|
55 { |
|
56 iCallbackInfo.Reset(); |
|
57 // try to reserve few slots |
|
58 iCallbackInfo.Reserve(KCallbackReserveSlots); |
|
59 iCallbackInfo.Append(TCallbackInfo(aEventId, aUid, aId, KErrNoMemory)); |
|
60 iProcessor.Cancel(); |
|
61 } |
|
62 SelfComplete(); |
|
63 } |
|
64 |
|
65 void CImageProcessorCallback::SelfComplete() |
|
66 { |
|
67 //Only activate if a request is not already outstanding, |
|
68 //else it will be activated from RunL() |
|
69 if(!IsActive()) |
|
70 { |
|
71 TRequestStatus* request = &iStatus; |
|
72 User::RequestComplete(request,KErrNone); |
|
73 SetActive(); |
|
74 } |
|
75 } |
|
76 |
|
77 void CImageProcessorCallback::RunL() |
|
78 { |
|
79 if(iCallbackInfo.Count()) |
|
80 { |
|
81 //Any properies that need to be modified has to be done before the |
|
82 //callbacks. The client may delete the Image Processor in the callback |
|
83 const TCallbackInfo info(iCallbackInfo[0]); |
|
84 iCallbackInfo.Remove(0); |
|
85 EnsureSpace(); |
|
86 |
|
87 //More requests in the queue |
|
88 __ASSERT_ALWAYS(!iCallbackInfo.Count(),SelfComplete()); |
|
89 |
|
90 switch(info.iEventId) |
|
91 { |
|
92 case CImgProcessor::EEventInitializingComplete: |
|
93 iObserver.ImageProcessorInitializingComplete(iProcessor, info.iError); |
|
94 break; |
|
95 |
|
96 case CImgProcessor::EEventPreviewInitializingComplete: |
|
97 iObserver.ImageProcessorPreviewInitializingComplete(iProcessor, info.iId, info.iError); |
|
98 break; |
|
99 |
|
100 case CImgProcessor::EEventProcessingComplete: |
|
101 iObserver.ImageProcessingComplete(iProcessor, info.iError); |
|
102 break; |
|
103 |
|
104 case CImgProcessor::EEventPreviewRenderingComplete: |
|
105 iObserver.ImageProcessorPreviewRenderingComplete(iProcessor, info.iId, info.iError); |
|
106 break; |
|
107 |
|
108 default: |
|
109 iObserver.ImageProcessorEvent(iProcessor, info.iEventId, info.iUid, info.iId); |
|
110 } |
|
111 } |
|
112 } |
|
113 |
|
114 void CImageProcessorCallback::DoCancel() |
|
115 { |
|
116 } |
|
117 |
|
118 void CImageProcessorCallback::EnsureSpace() |
|
119 { |
|
120 const TInt cnt(iCallbackInfo.Count()); |
|
121 //Ignore error. Just a best effort attempt to ensure enough memory in future |
|
122 //Still have some space from granularity |
|
123 iCallbackInfo.Reserve(cnt+KCallbackReserveSlots); |
|
124 } |
|
125 |
|
126 CImageProcessorCallback::TCallbackInfo::TCallbackInfo(TInt aEventId, TUid aUid, TInt aId, TInt aError): |
|
127 iEventId(aEventId), |
|
128 iUid(aUid), |
|
129 iId(aId), |
|
130 iError(aError) |
|
131 { |
|
132 } |
|
133 //EOF |