|
1 /* |
|
2 * Copyright (c) 2009 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 /** |
|
20 @file |
|
21 @internalComponent |
|
22 */ |
|
23 #include "buffercopier.h" |
|
24 #include "comxilvideoscheduler.h" |
|
25 #include "buffercopierstatemonitor.h" |
|
26 #include "log.h" |
|
27 |
|
28 CBufferCopierStateMonitor* CBufferCopierStateMonitor::NewL(MBufferCopierIf& aCallback, COmxILVideoScheduler& aComponent) |
|
29 { |
|
30 CBufferCopierStateMonitor* self = new (ELeave) CBufferCopierStateMonitor(aCallback, aComponent); |
|
31 CleanupStack::PushL(self); |
|
32 self->ConstructL(); |
|
33 CleanupStack::Pop(self); |
|
34 return self; |
|
35 } |
|
36 |
|
37 CBufferCopierStateMonitor::CBufferCopierStateMonitor(MBufferCopierIf& aCallback, COmxILVideoScheduler& aComponent) : |
|
38 CActive(EPriorityNormal), |
|
39 iCallback(aCallback), |
|
40 iComponent(aComponent), |
|
41 iState(ENull) |
|
42 { |
|
43 CActiveScheduler::Add(this); |
|
44 } |
|
45 |
|
46 CBufferCopierStateMonitor::~CBufferCopierStateMonitor() |
|
47 { |
|
48 Cancel(); |
|
49 delete iBufferCopier; |
|
50 } |
|
51 |
|
52 void CBufferCopierStateMonitor::ConstructL() |
|
53 { |
|
54 RThread me; |
|
55 iConstructionThreadId = me.Id(); |
|
56 |
|
57 iStatus = KRequestPending; |
|
58 SetActive(); |
|
59 } |
|
60 |
|
61 void CBufferCopierStateMonitor::RunL() |
|
62 { |
|
63 iStatus = KRequestPending; |
|
64 SetActive(); |
|
65 |
|
66 TInt err = DoSetState(); |
|
67 |
|
68 TRequestStatus *status = iCallingStatus; |
|
69 RThread callingThread; |
|
70 callingThread.Open(iCallingThreadId); |
|
71 callingThread.RequestComplete(status, err); |
|
72 callingThread.Close(); |
|
73 } |
|
74 |
|
75 void CBufferCopierStateMonitor::DoCancel() |
|
76 { |
|
77 TRequestStatus* pStat = &iStatus; |
|
78 User::RequestComplete(pStat, KErrCancel); |
|
79 } |
|
80 |
|
81 TInt CBufferCopierStateMonitor::RunError(TInt aError) |
|
82 { |
|
83 DEBUG_PRINTF2(_L8("CBufferCopierStateMonitor::RunError %d"), aError); |
|
84 aError=KErrNone; //Do not want to panic the server! |
|
85 return aError; |
|
86 } |
|
87 |
|
88 TInt CBufferCopierStateMonitor::SetState(TPFState aState) |
|
89 { |
|
90 DEBUG_PRINTF(_L8("CBufferCopierStateMonitor::SetState")); |
|
91 |
|
92 TInt err = KErrNone; |
|
93 iState = aState; |
|
94 |
|
95 RThread me; |
|
96 if(me.Id() != iConstructionThreadId) |
|
97 { |
|
98 // in different thread to that which 'this' was constructed |
|
99 err = DoRequest(); |
|
100 } |
|
101 else |
|
102 { |
|
103 // in same thread to that which 'this' was constructed therefore |
|
104 // active scheduler must exist and following call is safe |
|
105 err = DoSetState(); |
|
106 } |
|
107 |
|
108 return err; |
|
109 } |
|
110 |
|
111 TInt CBufferCopierStateMonitor::DoSetState() |
|
112 { |
|
113 DEBUG_PRINTF(_L8("CBufferCopierStateMonitor::DoSetState")); |
|
114 |
|
115 TInt err = KErrNone; |
|
116 |
|
117 switch(iState) |
|
118 { |
|
119 case ESubLoadedToIdle: |
|
120 iMaxBuffers = iComponent.BufferCount(); |
|
121 delete iBufferCopier; |
|
122 iBufferCopier = NULL; |
|
123 TRAP(err, iBufferCopier = CBufferCopier::NewL(iCallback, iMaxBuffers)); |
|
124 break; |
|
125 case ESubIdleToLoaded: |
|
126 delete iBufferCopier; |
|
127 iBufferCopier = NULL; |
|
128 break; |
|
129 default: |
|
130 break; |
|
131 }; |
|
132 |
|
133 return err; |
|
134 } |
|
135 |
|
136 TInt CBufferCopierStateMonitor::DoRequest() |
|
137 { |
|
138 DEBUG_PRINTF(_L8("CBufferCopierStateMonitor::DoRequest")); |
|
139 |
|
140 RThread me; |
|
141 iCallingThreadId = me.Id(); |
|
142 TRequestStatus requestStatus = KRequestPending; |
|
143 iCallingStatus = &requestStatus; |
|
144 |
|
145 // send request to active scheduler thread |
|
146 RThread schedulerThread; |
|
147 TInt error = schedulerThread.Open(iConstructionThreadId); |
|
148 if(error != KErrNone) |
|
149 { |
|
150 return error; |
|
151 } |
|
152 |
|
153 TRequestStatus* schedulerRequest = &iStatus; |
|
154 schedulerThread.RequestComplete(schedulerRequest, KErrNone); |
|
155 schedulerThread.Close(); |
|
156 |
|
157 // block until request completes |
|
158 User::WaitForRequest(requestStatus); |
|
159 |
|
160 return requestStatus.Int(); |
|
161 } |