|
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
|
2 <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> |
|
3 <title>TB10.1 Example Applications: examples/Base/ArraysAndLists/linkedlist/deltaque/src/timerentry.cpp Source File</title> |
|
4 <link href="doxygen.css" rel="stylesheet" type="text/css"> |
|
5 <link href="tabs.css" rel="stylesheet" type="text/css"> |
|
6 </head><body> |
|
7 <!-- Generated by Doxygen 1.5.3 --> |
|
8 <h1>examples/Base/ArraysAndLists/linkedlist/deltaque/src/timerentry.cpp</h1><a href="timerentry_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).</span> |
|
9 <a name="l00002"></a>00002 <span class="comment">// All rights reserved.</span> |
|
10 <a name="l00003"></a>00003 <span class="comment">// This component and the accompanying materials are made available</span> |
|
11 <a name="l00004"></a>00004 <span class="comment">// under the terms of "Eclipse Public License v1.0"</span> |
|
12 <a name="l00005"></a>00005 <span class="comment">// which accompanies this distribution, and is available</span> |
|
13 <a name="l00006"></a>00006 <span class="comment">// at the URL "http://www.eclipse.org/legal/epl-v10.html".</span> |
|
14 <a name="l00007"></a>00007 <span class="comment">//</span> |
|
15 <a name="l00008"></a>00008 <span class="comment">// Initial Contributors:</span> |
|
16 <a name="l00009"></a>00009 <span class="comment">// Nokia Corporation - initial contribution.</span> |
|
17 <a name="l00010"></a>00010 <span class="comment">//</span> |
|
18 <a name="l00011"></a>00011 <span class="comment">// Contributors:</span> |
|
19 <a name="l00012"></a>00012 <span class="comment">//</span> |
|
20 <a name="l00013"></a>00013 <span class="comment">// Description:</span> |
|
21 <a name="l00014"></a>00014 <span class="comment">// Contains definition of functions defined in the CTimerEntry class.</span> |
|
22 <a name="l00015"></a>00015 <span class="comment">//</span> |
|
23 <a name="l00016"></a>00016 |
|
24 <a name="l00017"></a>00017 |
|
25 <a name="l00018"></a>00018 |
|
26 <a name="l00023"></a>00023 <span class="preprocessor">#include "<a class="code" href="timerentry_8h.html">timerentry.h</a>"</span> |
|
27 <a name="l00024"></a>00024 |
|
28 <a name="l00029"></a><a class="code" href="class_c_timer_entry.html#e9239b3945aa446c00506024551a8268">00029</a> <a class="code" href="class_c_timer_entry.html">CTimerEntry</a>* <a class="code" href="class_c_timer_entry.html#e9239b3945aa446c00506024551a8268">CTimerEntry::NewL</a>(CConsoleBase* aConsole) |
|
29 <a name="l00030"></a>00030 { |
|
30 <a name="l00031"></a>00031 <a class="code" href="class_c_timer_entry.html">CTimerEntry</a>* <span class="keyword">self</span> = <span class="keyword">new</span> (ELeave) <a class="code" href="class_c_timer_entry.html">CTimerEntry</a>(aConsole); |
|
31 <a name="l00032"></a>00032 CleanupStack::PushL(<span class="keyword">self</span>); |
|
32 <a name="l00033"></a>00033 <span class="keyword">self</span>->ConstructL(); |
|
33 <a name="l00034"></a>00034 CleanupStack::Pop(<span class="keyword">self</span>); |
|
34 <a name="l00035"></a>00035 <span class="keywordflow">return</span> <span class="keyword">self</span>; |
|
35 <a name="l00036"></a>00036 } |
|
36 <a name="l00037"></a>00037 |
|
37 <a name="l00041"></a>00041 <span class="keywordtype">void</span> CTimerEntry::ConstructL() |
|
38 <a name="l00042"></a>00042 { |
|
39 <a name="l00043"></a>00043 <span class="comment">// Construct the timer object.</span> |
|
40 <a name="l00044"></a>00044 CTimer::ConstructL(); |
|
41 <a name="l00045"></a>00045 <span class="comment">// Add the object to the active scheduler.</span> |
|
42 <a name="l00046"></a>00046 CActiveScheduler::Add(<span class="keyword">this</span>); |
|
43 <a name="l00047"></a>00047 } |
|
44 <a name="l00048"></a>00048 |
|
45 <a name="l00053"></a>00053 CTimerEntry::CTimerEntry(CConsoleBase* aConsole): |
|
46 <a name="l00054"></a>00054 <span class="comment">// Constructor of the timer object.</span> |
|
47 <a name="l00055"></a>00055 CTimer(CActive::EPriorityStandard), |
|
48 <a name="l00056"></a>00056 <span class="comment">// Create the iterator object.</span> |
|
49 <a name="l00057"></a>00057 iIterator(iQueue), |
|
50 <a name="l00058"></a>00058 <span class="comment">// Set count to -1.</span> |
|
51 <a name="l00059"></a>00059 iCount(-1), |
|
52 <a name="l00060"></a>00060 <span class="comment">// Set increment operation as</span> |
|
53 <a name="l00061"></a>00061 <span class="comment">// the default operation.</span> |
|
54 <a name="l00062"></a>00062 iOp(EInsert), |
|
55 <a name="l00063"></a>00063 iConsole(aConsole), |
|
56 <a name="l00064"></a>00064 iWaitFlag(ETrue) |
|
57 <a name="l00065"></a>00065 { |
|
58 <a name="l00066"></a>00066 } |
|
59 <a name="l00067"></a>00067 |
|
60 <a name="l00071"></a><a class="code" href="class_c_timer_entry.html#b03ab2f073ce345c257048d5f364cc98">00071</a> <span class="keywordtype">void</span> <a class="code" href="class_c_timer_entry.html#b03ab2f073ce345c257048d5f364cc98">CTimerEntry::RunL</a>() |
|
61 <a name="l00072"></a>00072 { |
|
62 <a name="l00073"></a>00073 <span class="comment">// Call the arbitrator function.</span> |
|
63 <a name="l00074"></a>00074 <a class="code" href="class_c_timer_entry.html#19f74837cbfb53d10b57b922898648d1">ArbitratorL</a>(); |
|
64 <a name="l00075"></a>00075 <span class="comment">// Print the contents of the queue.</span> |
|
65 <a name="l00076"></a>00076 <a class="code" href="class_c_timer_entry.html#50d4cca6ff84c59189d437bb83007a03">PrintQue</a>(); |
|
66 <a name="l00077"></a>00077 <span class="comment">// Maintain an outstanding request.</span> |
|
67 <a name="l00078"></a>00078 <a class="code" href="class_c_timer_entry.html#06ea9b1cc9e02c51ac544ec85cacb477">IssueRequest</a>(); |
|
68 <a name="l00079"></a>00079 } |
|
69 <a name="l00080"></a>00080 |
|
70 <a name="l00081"></a>00081 |
|
71 <a name="l00085"></a><a class="code" href="class_c_timer_entry.html#06ea9b1cc9e02c51ac544ec85cacb477">00085</a> <span class="keywordtype">void</span> <a class="code" href="class_c_timer_entry.html#06ea9b1cc9e02c51ac544ec85cacb477">CTimerEntry::IssueRequest</a>() |
|
72 <a name="l00086"></a>00086 { |
|
73 <a name="l00087"></a>00087 <span class="comment">// Get a random number for number of seconds to wait.</span> |
|
74 <a name="l00088"></a>00088 <span class="comment">// Issue the wait request.</span> |
|
75 <a name="l00089"></a>00089 TUint waitTime = <a class="code" href="timerentry_8h.html#1d76d5d6749e42f230fa13809142da9c">KWaitTime</a>; |
|
76 <a name="l00090"></a>00090 <span class="keywordflow">if</span> (iWaitFlag) |
|
77 <a name="l00091"></a>00091 { |
|
78 <a name="l00092"></a>00092 waitTime = Math::Random() % <a class="code" href="timerentry_8h.html#7cfb6e84793cfd2baafc893a55b0ccb4">KMaxTimeToWait</a>; |
|
79 <a name="l00093"></a>00093 <span class="comment">// Make sure that time to wait is not zero;</span> |
|
80 <a name="l00094"></a>00094 waitTime++; |
|
81 <a name="l00095"></a>00095 } |
|
82 <a name="l00096"></a>00096 CTimer::After((waitTime) * 1000000); |
|
83 <a name="l00097"></a>00097 } |
|
84 <a name="l00098"></a>00098 |
|
85 <a name="l00104"></a><a class="code" href="class_c_timer_entry.html#19f74837cbfb53d10b57b922898648d1">00104</a> <span class="keywordtype">void</span> <a class="code" href="class_c_timer_entry.html#19f74837cbfb53d10b57b922898648d1">CTimerEntry::ArbitratorL</a>() |
|
86 <a name="l00105"></a>00105 { |
|
87 <a name="l00106"></a>00106 <span class="comment">// The increment operation.</span> |
|
88 <a name="l00107"></a>00107 <span class="comment">// Add elements to the list.</span> |
|
89 <a name="l00108"></a>00108 <span class="keywordflow">if</span>(iOp == EInsert) |
|
90 <a name="l00109"></a>00109 { |
|
91 <a name="l00110"></a>00110 <span class="comment">// Get the tick count.</span> |
|
92 <a name="l00111"></a>00111 TInt tc = (TInt)User::TickCount(); |
|
93 <a name="l00112"></a>00112 <span class="comment">// Try to add an element to the list.</span> |
|
94 <a name="l00113"></a>00113 TBool redo = <a class="code" href="class_c_timer_entry.html#0500f775214fb36077a020c8d6ec58d1">AddToQueueL</a>(tc); |
|
95 <a name="l00114"></a>00114 <span class="comment">// The queue is full.</span> |
|
96 <a name="l00115"></a>00115 <span class="keywordflow">if</span>(!redo) |
|
97 <a name="l00116"></a>00116 { |
|
98 <a name="l00117"></a>00117 _LIT(KTextQueFull,<span class="stringliteral">"Queue is full!\n"</span>); |
|
99 <a name="l00118"></a>00118 iConsole->Printf(KTextQueFull); |
|
100 <a name="l00119"></a>00119 <span class="comment">// Stop adding elements to the queue.</span> |
|
101 <a name="l00120"></a>00120 <span class="comment">// Set iWaitFlag to EFalse.</span> |
|
102 <a name="l00121"></a>00121 <span class="comment">// The timer will wait for 1 second before removing an element</span> |
|
103 <a name="l00122"></a>00122 <span class="comment">// from the queue.</span> |
|
104 <a name="l00123"></a>00123 iWaitFlag = EFalse; |
|
105 <a name="l00124"></a>00124 } |
|
106 <a name="l00125"></a>00125 } |
|
107 <a name="l00126"></a>00126 <span class="comment">// The decrement operation.</span> |
|
108 <a name="l00127"></a>00127 <span class="comment">// Remove elements from the list.</span> |
|
109 <a name="l00128"></a>00128 <span class="keywordflow">else</span> |
|
110 <a name="l00129"></a>00129 { |
|
111 <a name="l00130"></a>00130 <span class="comment">// Try to remove an element from the list.</span> |
|
112 <a name="l00131"></a>00131 TBool redo = <a class="code" href="class_c_timer_entry.html#41e0ec777102f5e9317469a83ddd6b82">RemoveFromQueue</a>(); |
|
113 <a name="l00132"></a>00132 <span class="comment">// The queue is empty.</span> |
|
114 <a name="l00133"></a>00133 <span class="keywordflow">if</span>(!redo) |
|
115 <a name="l00134"></a>00134 { |
|
116 <a name="l00135"></a>00135 _LIT(KTextQueEmpty,<span class="stringliteral">"Queue is empty!\n"</span>); |
|
117 <a name="l00136"></a>00136 iConsole->Printf(KTextQueEmpty); |
|
118 <a name="l00137"></a>00137 <span class="comment">// Stop removing elements from the queue.</span> |
|
119 <a name="l00138"></a>00138 <span class="comment">// Set iWaitFlag to ETrue.</span> |
|
120 <a name="l00139"></a>00139 <span class="comment">// The timer will wait for a random interval of time</span> |
|
121 <a name="l00140"></a>00140 <span class="comment">// before adding an element to the queue.</span> |
|
122 <a name="l00141"></a>00141 iWaitFlag = ETrue; |
|
123 <a name="l00142"></a>00142 } |
|
124 <a name="l00143"></a>00143 } |
|
125 <a name="l00144"></a>00144 } |
|
126 <a name="l00145"></a>00145 |
|
127 <a name="l00151"></a><a class="code" href="class_c_timer_entry.html#0500f775214fb36077a020c8d6ec58d1">00151</a> TBool <a class="code" href="class_c_timer_entry.html#0500f775214fb36077a020c8d6ec58d1">CTimerEntry::AddToQueueL</a>(TInt aTicks) |
|
128 <a name="l00152"></a>00152 { |
|
129 <a name="l00153"></a>00153 <span class="comment">// Check if the queue is full.</span> |
|
130 <a name="l00154"></a>00154 <span class="keywordflow">if</span>(iCount >= (<a class="code" href="timerentry_8h.html#417100e77f433b7a4e47986b04938e0c">KMaxEntry</a> - 1)) |
|
131 <a name="l00155"></a>00155 { |
|
132 <a name="l00156"></a>00156 iOp = ERemove; |
|
133 <a name="l00157"></a>00157 <span class="keywordflow">return</span> EFalse; |
|
134 <a name="l00158"></a>00158 } |
|
135 <a name="l00159"></a>00159 |
|
136 <a name="l00160"></a>00160 <span class="comment">// Add the tick count to the delta queue.</span> |
|
137 <a name="l00161"></a>00161 _LIT(KTextAddTick,<span class="stringliteral">"Added %d to the queue\n"</span>); |
|
138 <a name="l00162"></a>00162 iConsole->Printf(KTextAddTick,aTicks); |
|
139 <a name="l00163"></a>00163 iCount++; |
|
140 <a name="l00164"></a>00164 |
|
141 <a name="l00165"></a>00165 <a class="code" href="class_t_timer_entry.html">TTimerEntry</a>* ptr = <span class="keyword">new</span> (ELeave) <a class="code" href="class_t_timer_entry.html">TTimerEntry</a>; |
|
142 <a name="l00166"></a>00166 iQueue.Add(*ptr,aTicks); |
|
143 <a name="l00167"></a>00167 |
|
144 <a name="l00168"></a>00168 <span class="keywordflow">return</span> ETrue; |
|
145 <a name="l00169"></a>00169 } |
|
146 <a name="l00170"></a>00170 |
|
147 <a name="l00174"></a><a class="code" href="class_c_timer_entry.html#50d4cca6ff84c59189d437bb83007a03">00174</a> <span class="keywordtype">void</span> <a class="code" href="class_c_timer_entry.html#50d4cca6ff84c59189d437bb83007a03">CTimerEntry::PrintQue</a>() |
|
148 <a name="l00175"></a>00175 { |
|
149 <a name="l00176"></a>00176 _LIT(KTextCont,<span class="stringliteral">"Contents of the List:\n***\nINDEX\tDELTA\n"</span>); |
|
150 <a name="l00177"></a>00177 iConsole->Printf(KTextCont); |
|
151 <a name="l00178"></a>00178 <span class="comment">// Set the iterator to the first node of the list.</span> |
|
152 <a name="l00179"></a>00179 iIterator.SetToFirst(); |
|
153 <a name="l00180"></a>00180 <span class="comment">// Iterate the list and print all TDigit objects</span> |
|
154 <a name="l00181"></a>00181 <a class="code" href="class_t_timer_entry.html">TTimerEntry</a> *ptr = iIterator++; |
|
155 <a name="l00182"></a>00182 <span class="comment">// List index.</span> |
|
156 <a name="l00183"></a>00183 TInt ix = 0; |
|
157 <a name="l00184"></a>00184 <span class="keywordflow">while</span> (ptr != NULL) |
|
158 <a name="l00185"></a>00185 { |
|
159 <a name="l00186"></a>00186 _LIT(KTextFormat,<span class="stringliteral">"%d\t\t%d\n"</span>); |
|
160 <a name="l00187"></a>00187 iConsole->Printf(KTextFormat,ix,ptr-><a class="code" href="class_t_timer_entry.html#3ab7cbadf08c805fd2ddb864b19eb9d7">iLink</a>.iDelta); |
|
161 <a name="l00188"></a>00188 ptr = iIterator++; |
|
162 <a name="l00189"></a>00189 ix++; |
|
163 <a name="l00190"></a>00190 } |
|
164 <a name="l00191"></a>00191 _LIT(KTextEnd,<span class="stringliteral">"***\n"</span>); |
|
165 <a name="l00192"></a>00192 iConsole->Printf(KTextEnd); |
|
166 <a name="l00193"></a>00193 } |
|
167 <a name="l00194"></a>00194 |
|
168 <a name="l00199"></a><a class="code" href="class_c_timer_entry.html#41e0ec777102f5e9317469a83ddd6b82">00199</a> TBool <a class="code" href="class_c_timer_entry.html#41e0ec777102f5e9317469a83ddd6b82">CTimerEntry::RemoveFromQueue</a>() |
|
169 <a name="l00200"></a>00200 { |
|
170 <a name="l00201"></a>00201 <span class="comment">// Check if the queue is empty.</span> |
|
171 <a name="l00202"></a>00202 <span class="keywordflow">if</span>(iCount < 0) |
|
172 <a name="l00203"></a>00203 { |
|
173 <a name="l00204"></a>00204 iOp = EInsert; |
|
174 <a name="l00205"></a>00205 <span class="keywordflow">return</span> EFalse; |
|
175 <a name="l00206"></a>00206 } |
|
176 <a name="l00207"></a>00207 |
|
177 <a name="l00208"></a>00208 iIterator.SetToFirst(); |
|
178 <a name="l00209"></a>00209 |
|
179 <a name="l00210"></a>00210 <span class="comment">// The index of the node to be removed in the list.</span> |
|
180 <a name="l00211"></a>00211 TInt pos = 0; |
|
181 <a name="l00212"></a>00212 |
|
182 <a name="l00213"></a>00213 <span class="comment">// Get a random value for position.</span> |
|
183 <a name="l00214"></a>00214 <span class="keywordflow">if</span>(iCount > 0) |
|
184 <a name="l00215"></a>00215 { |
|
185 <a name="l00216"></a>00216 pos = Math::Random() % iCount; |
|
186 <a name="l00217"></a>00217 } |
|
187 <a name="l00218"></a>00218 |
|
188 <a name="l00219"></a>00219 <span class="comment">// Iterate the list until the node pointed to by</span> |
|
189 <a name="l00220"></a>00220 <span class="comment">// the pos variable is reached.</span> |
|
190 <a name="l00221"></a>00221 <span class="keywordflow">for</span>(TInt ix = 1; ix <= pos; ix++) |
|
191 <a name="l00222"></a>00222 { |
|
192 <a name="l00223"></a>00223 iIterator++; |
|
193 <a name="l00224"></a>00224 } |
|
194 <a name="l00225"></a>00225 |
|
195 <a name="l00226"></a>00226 <a class="code" href="class_t_timer_entry.html">TTimerEntry</a>* ptr = iIterator; |
|
196 <a name="l00227"></a>00227 |
|
197 <a name="l00228"></a>00228 _LIT(KTextRemove,<span class="stringliteral">"Removed an element from the queue. Index: %d\n"</span>); |
|
198 <a name="l00229"></a>00229 iConsole->Printf(KTextRemove,pos); |
|
199 <a name="l00230"></a>00230 |
|
200 <a name="l00231"></a>00231 <span class="comment">// Remove an element from the delta queue.</span> |
|
201 <a name="l00232"></a>00232 iQueue.Remove(*ptr); |
|
202 <a name="l00233"></a>00233 <span class="keyword">delete</span> ptr; |
|
203 <a name="l00234"></a>00234 |
|
204 <a name="l00235"></a>00235 iCount--; |
|
205 <a name="l00236"></a>00236 |
|
206 <a name="l00237"></a>00237 <span class="keywordflow">return</span> ETrue; |
|
207 <a name="l00238"></a>00238 } |
|
208 <a name="l00239"></a>00239 |
|
209 <a name="l00245"></a><a class="code" href="class_c_timer_entry.html#193d31aafb44a96b5b1e2ea6c0d57f78">00245</a> <a class="code" href="class_c_timer_entry.html#193d31aafb44a96b5b1e2ea6c0d57f78">CTimerEntry::~CTimerEntry</a>() |
|
210 <a name="l00246"></a>00246 { |
|
211 <a name="l00247"></a>00247 <span class="comment">// Cancel any outstanding request.</span> |
|
212 <a name="l00248"></a>00248 Cancel(); |
|
213 <a name="l00249"></a>00249 <span class="comment">// Delete the elements from the list</span> |
|
214 <a name="l00250"></a>00250 <span class="keywordflow">if</span>(iIterator) |
|
215 <a name="l00251"></a>00251 { |
|
216 <a name="l00252"></a>00252 iIterator.SetToFirst(); |
|
217 <a name="l00253"></a>00253 <span class="comment">// Iterate the list and delete all TDigit objects</span> |
|
218 <a name="l00254"></a>00254 <a class="code" href="class_t_timer_entry.html">TTimerEntry</a> *ptr = iIterator++; |
|
219 <a name="l00255"></a>00255 <span class="keywordflow">while</span> (ptr != NULL) |
|
220 <a name="l00256"></a>00256 { |
|
221 <a name="l00257"></a>00257 <span class="keyword">delete</span> ptr; |
|
222 <a name="l00258"></a>00258 ptr = iIterator++; |
|
223 <a name="l00259"></a>00259 } |
|
224 <a name="l00260"></a>00260 } |
|
225 <a name="l00261"></a>00261 } |
|
226 <a name="l00262"></a>00262 |
|
227 <a name="l00266"></a><a class="code" href="class_c_timer_entry.html#21a3db06e926673b3dd3f83b40bd57e2">00266</a> <span class="keywordtype">void</span> <a class="code" href="class_c_timer_entry.html#21a3db06e926673b3dd3f83b40bd57e2">CTimerEntry::DoCancel</a>() |
|
228 <a name="l00267"></a>00267 { |
|
229 <a name="l00268"></a>00268 <span class="comment">// Call DoCancel() on the base class.</span> |
|
230 <a name="l00269"></a>00269 CTimer::DoCancel(); |
|
231 <a name="l00270"></a>00270 } |
|
232 <a name="l00271"></a>00271 |
|
233 </pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Thu Jan 21 10:32:55 2010 for TB10.1 Example Applications by |
|
234 <a href="http://www.doxygen.org/index.html"> |
|
235 <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.3 </small></address> |
|
236 </body> |
|
237 </html> |