|
1 /* |
|
2 * Copyright (c) 2008 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: CCFAsyncCmdQueue implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // SYSTEM INCLUDES |
|
20 |
|
21 // USER INCLUDES |
|
22 #include "cfasynccmdqueue.h" |
|
23 #include "cfcmd.h" |
|
24 #include "cftrace.h" |
|
25 |
|
26 // ======== MEMBER FUNCTIONS ======== |
|
27 |
|
28 // --------------------------------------------------------------------------- |
|
29 // C++ constructor. |
|
30 // --------------------------------------------------------------------------- |
|
31 // |
|
32 CCFAsyncCmdQueue::CCFAsyncCmdQueue() |
|
33 : CActive( EPriorityHigh ), |
|
34 iQueue( CCFCmd::SglQueLinkOffset() ), |
|
35 iQueueIter( iQueue ) |
|
36 { |
|
37 FUNC_LOG; |
|
38 |
|
39 CActiveScheduler::Add( this ); |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // Symbian two phased constructor. |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 CCFAsyncCmdQueue* CCFAsyncCmdQueue::NewL( ) |
|
47 { |
|
48 FUNC_LOG; |
|
49 |
|
50 CCFAsyncCmdQueue* self = CCFAsyncCmdQueue::NewLC(); |
|
51 CleanupStack::Pop( self ); |
|
52 return self; |
|
53 } |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // Symbian two phased constructor. |
|
57 // Leaves pointer in the cleanup stack. |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 CCFAsyncCmdQueue* CCFAsyncCmdQueue::NewLC() |
|
61 { |
|
62 FUNC_LOG; |
|
63 |
|
64 CCFAsyncCmdQueue* self = new( ELeave ) CCFAsyncCmdQueue(); |
|
65 CleanupStack::PushL( self ); |
|
66 return self; |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // C++ destructor. |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 CCFAsyncCmdQueue::~CCFAsyncCmdQueue() |
|
74 { |
|
75 FUNC_LOG; |
|
76 |
|
77 Cancel(); |
|
78 if ( !iQueue.IsEmpty() ) |
|
79 { |
|
80 CCFCmd* cmd = NULL; |
|
81 iQueueIter.SetToFirst(); |
|
82 while ( ( cmd = iQueueIter++ ) != NULL ) |
|
83 { |
|
84 iQueue.Remove( *cmd ); |
|
85 delete cmd; |
|
86 } |
|
87 } |
|
88 delete iCurrentCmd; |
|
89 } |
|
90 |
|
91 |
|
92 // --------------------------------------------------------------------------- |
|
93 // CCFAsyncCmdQueue::Add |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 void CCFAsyncCmdQueue::Add( CCFCmd* aCmd ) |
|
97 { |
|
98 FUNC_LOG; |
|
99 |
|
100 iQueue.AddLast( *aCmd ); |
|
101 Activate(); |
|
102 } |
|
103 |
|
104 // --------------------------------------------------------------------------- |
|
105 // CCFAsyncCmdQueue::AddFirst |
|
106 // --------------------------------------------------------------------------- |
|
107 // |
|
108 void CCFAsyncCmdQueue::AddFirst( CCFCmd* aCmd ) |
|
109 { |
|
110 FUNC_LOG; |
|
111 |
|
112 iQueue.AddFirst( *aCmd ); |
|
113 Activate(); |
|
114 } |
|
115 |
|
116 |
|
117 // --------------------------------------------------------------------------- |
|
118 // CCFAsyncCmdQueue::DoCancel |
|
119 // --------------------------------------------------------------------------- |
|
120 // |
|
121 void CCFAsyncCmdQueue::DoCancel() |
|
122 { |
|
123 FUNC_LOG; |
|
124 // Nothing to do. |
|
125 } |
|
126 |
|
127 // --------------------------------------------------------------------------- |
|
128 // CCFAsyncCmdQueue::RunL |
|
129 // --------------------------------------------------------------------------- |
|
130 // |
|
131 void CCFAsyncCmdQueue::RunL() |
|
132 { |
|
133 FUNC_LOG; |
|
134 |
|
135 if ( !iQueue.IsEmpty() ) |
|
136 { |
|
137 iCurrentCmd = iQueue.First(); |
|
138 iQueue.Remove( *iCurrentCmd ); |
|
139 iCurrentCmd->ExecuteL(); |
|
140 delete iCurrentCmd; |
|
141 iCurrentCmd = NULL; |
|
142 } |
|
143 |
|
144 Activate(); |
|
145 } |
|
146 |
|
147 // --------------------------------------------------------------------------- |
|
148 // CCFAsyncCmdQueue::RunError |
|
149 // --------------------------------------------------------------------------- |
|
150 // |
|
151 TInt CCFAsyncCmdQueue::RunError( TInt aError ) |
|
152 { |
|
153 FUNC_LOG; |
|
154 |
|
155 if ( iCurrentCmd ) |
|
156 { |
|
157 iCurrentCmd->LogError( aError ); |
|
158 delete iCurrentCmd; |
|
159 iCurrentCmd = NULL; |
|
160 } |
|
161 |
|
162 ERROR( aError, "CCFAsyncCmdQueue::RunError - Ignoring the error" ); |
|
163 |
|
164 Activate(); |
|
165 |
|
166 return KErrNone; // Ignore errors. |
|
167 } |
|
168 |
|
169 // ----------------------------------------------------------------------------- |
|
170 // CCFAsyncCmdQueue::Activate |
|
171 // ----------------------------------------------------------------------------- |
|
172 // |
|
173 void CCFAsyncCmdQueue::Activate() |
|
174 { |
|
175 FUNC_LOG; |
|
176 |
|
177 if ( !IsActive() && !iQueue.IsEmpty() ) |
|
178 { |
|
179 iStatus = KRequestPending; |
|
180 SetActive(); |
|
181 TRequestStatus* status = &iStatus; |
|
182 User::RequestComplete( status, KErrNone ); |
|
183 } |
|
184 } |
|
185 |
|
186 // End of file |