|
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: Audio stream test component |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "MediaEvent.h" |
|
20 |
|
21 CMediaEvent* CMediaEvent::NewL(CStifLogger *aLogger, |
|
22 TTimeIntervalMicroSeconds32 aDelay , TTimeIntervalMicroSeconds32 aInterval, |
|
23 MEventTarget *aTarget , CParameters *aParameters , TInt aPriority) |
|
24 { |
|
25 CMediaEvent *__self = CMediaEvent::NewLC(aLogger , |
|
26 aDelay , aInterval , aTarget, |
|
27 aParameters, aPriority); |
|
28 CleanupStack::Pop(__self); |
|
29 return __self; |
|
30 } |
|
31 |
|
32 CMediaEvent* CMediaEvent::NewLC(CStifLogger *aLogger, |
|
33 TTimeIntervalMicroSeconds32 aDelay , TTimeIntervalMicroSeconds32 aInterval, |
|
34 MEventTarget *aTarget, CParameters *aParameters , TInt aPriority) |
|
35 { |
|
36 CMediaEvent *__self = new(ELeave) CMediaEvent(aLogger , aDelay , aInterval , aTarget , aParameters); |
|
37 CleanupStack::PushL(__self); |
|
38 __self->ConstructL(aPriority); |
|
39 return __self; |
|
40 } |
|
41 |
|
42 CMediaEvent::CMediaEvent (CStifLogger *aLogger, |
|
43 TTimeIntervalMicroSeconds32 aDelay, TTimeIntervalMicroSeconds32 aInterval, |
|
44 MEventTarget *aTarget , CParameters *aParameters) |
|
45 : iLogger(aLogger) , |
|
46 iDelay(aDelay) , iInterval(aInterval) , iEventTarget(aTarget), |
|
47 iParameters(aParameters) , iCount(0) |
|
48 {} |
|
49 |
|
50 void CMediaEvent::ConstructL(TInt aPriority=CActive::EPriorityStandard) |
|
51 { |
|
52 iLogger->Log(_L("Creating event with priority (%d)") , aPriority); |
|
53 iPeriodic=CPeriodic::NewL(aPriority); |
|
54 iPeriodic->Start(iDelay , iInterval , TCallBack(Tick, this)); |
|
55 } |
|
56 |
|
57 CMediaEvent::~CMediaEvent () |
|
58 { |
|
59 iPeriodic->Cancel(); |
|
60 delete iPeriodic; |
|
61 delete iParameters; |
|
62 iParameters=NULL; |
|
63 } |
|
64 |
|
65 TInt CMediaEvent::Tick(TAny *aObject) |
|
66 { |
|
67 return (static_cast<CMediaEvent*>(aObject) )->DoTick(); // cast, and call non-static function |
|
68 } |
|
69 |
|
70 TInt CMediaEvent::DoTick() |
|
71 { |
|
72 iCount++; |
|
73 if (! iEventTarget->ExecuteL(iParameters)) { |
|
74 iPeriodic->Cancel(); |
|
75 } |
|
76 return 0; |
|
77 } |
|
78 |
|
79 TInt CMediaEvent::GetCount() const |
|
80 { |
|
81 return iCount; |
|
82 } |
|
83 |
|
84 |
|
85 //////////////////////////// |
|
86 CImmediateMediaEvent* CImmediateMediaEvent::NewL(CStifLogger *aLogger , |
|
87 MEventTarget *aTarget , CParameters *aParameters , TInt aPriority) |
|
88 { |
|
89 CImmediateMediaEvent *__self = CImmediateMediaEvent::NewLC(aLogger, aTarget, aParameters, aPriority); |
|
90 |
|
91 CleanupStack::Pop(__self); |
|
92 return __self; |
|
93 } |
|
94 |
|
95 CImmediateMediaEvent* CImmediateMediaEvent::NewLC(CStifLogger *aLogger , |
|
96 MEventTarget *aTarget, CParameters *aParameters , TInt aPriority) |
|
97 { |
|
98 CImmediateMediaEvent *__self = new(ELeave) CImmediateMediaEvent(aLogger , aTarget , aParameters, aPriority); |
|
99 CleanupStack::PushL(__self); |
|
100 __self->ConstructL(); |
|
101 return __self; |
|
102 } |
|
103 |
|
104 CImmediateMediaEvent::CImmediateMediaEvent (CStifLogger *aLogger , |
|
105 MEventTarget *aTarget , CParameters *aParameters, TInt aPriority) |
|
106 : CActive(aPriority) , iLogger(aLogger) , |
|
107 iEventTarget(aTarget) , iParameters(aParameters) , iEnabled(ETrue) |
|
108 {} |
|
109 |
|
110 void CImmediateMediaEvent::ConstructL(/*TInt aPriority=CActive::EPriorityStandard*/) |
|
111 { |
|
112 iLogger->Log(_L("Creating event with priority (%d)") , Priority() ); |
|
113 //iPeriodic=CPeriodic::NewL(aPriority); |
|
114 //iPeriodic->Start(iDelay , iInterval , TCallBack(Tick, this)); |
|
115 CActiveScheduler::Add(this); |
|
116 } |
|
117 |
|
118 CImmediateMediaEvent::~CImmediateMediaEvent () |
|
119 { |
|
120 delete iParameters; |
|
121 iParameters=NULL; |
|
122 Cancel(); |
|
123 } |
|
124 |
|
125 void CImmediateMediaEvent::RunL() |
|
126 { |
|
127 if (iEnabled) |
|
128 { |
|
129 iEventTarget->ExecuteL(iParameters); |
|
130 } |
|
131 } |
|
132 |
|
133 void CImmediateMediaEvent::DoCancel() |
|
134 { |
|
135 iEnabled = EFalse; |
|
136 } |
|
137 |
|
138 TBool CImmediateMediaEvent::FireExecute() |
|
139 { |
|
140 //__ASSERT_ALWAYS(!IsActive(), User::Panic(_L("Error with the "), KErrGeneral)); |
|
141 if ( IsActive() ) return EFalse; |
|
142 iEnabled = ETrue; |
|
143 TRequestStatus *status = &iStatus; |
|
144 SetActive(); |
|
145 User::RequestComplete( status , KErrNone); |
|
146 return ETrue; |
|
147 } |