Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/taskscheduler_8cpp-source.html
changeset 1 25a17d01db0c
equal deleted inserted replaced
0:89d6a7a84779 1:25a17d01db0c
       
     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/SysLibs/TaskSchedulerExample/taskscheduler.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/SysLibs/TaskSchedulerExample/taskscheduler.cpp</h1><a href="taskscheduler_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) 2007-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">// This is simple example code that demonstrates the use of task scheduler. </span>
       
    22 <a name="l00015"></a>00015 <span class="comment">// The code demonstrates how to,</span>
       
    23 <a name="l00016"></a>00016 <span class="comment">// 1) Connect and register with the task scheduler</span>
       
    24 <a name="l00017"></a>00017 <span class="comment">// 2) Create a persistent schedule</span>
       
    25 <a name="l00018"></a>00018 <span class="comment">// 3) Add tasks to it</span>
       
    26 <a name="l00019"></a>00019 <span class="comment">// 4) Execute the schedule</span>
       
    27 <a name="l00020"></a>00020 <span class="comment">// 5) Delete the schedules and the tasks associated with them after</span>
       
    28 <a name="l00021"></a>00021 <span class="comment">// verifying that they are the schedules created by us.</span>
       
    29 <a name="l00022"></a>00022 <span class="comment">// 6) Create a transient schedule</span>
       
    30 <a name="l00023"></a>00023 <span class="comment">// 7) Add task to the transient schedule, edit the schedule and execute it</span>
       
    31 <a name="l00024"></a>00024 <span class="comment">//</span>
       
    32 <a name="l00025"></a>00025 
       
    33 <a name="l00026"></a>00026 
       
    34 <a name="l00027"></a>00027 
       
    35 <a name="l00031"></a>00031 <span class="preprocessor">#include "<a class="code" href="taskscheduler_8h.html">taskscheduler.h</a>"</span>
       
    36 <a name="l00032"></a>00032 <span class="preprocessor">#include &lt;e32std.h&gt;</span>
       
    37 <a name="l00033"></a>00033 <span class="preprocessor">#include &lt;schinfo.h&gt;</span>
       
    38 <a name="l00034"></a>00034 <span class="preprocessor">#include &lt;e32base.h&gt;</span>
       
    39 <a name="l00035"></a>00035 
       
    40 <a name="l00036"></a>00036 _LIT(KTaskName,<span class="stringliteral">"MyTaskName\n"</span>);
       
    41 <a name="l00037"></a>00037 
       
    42 <a name="l00038"></a>00038 _LIT(KTitle, <span class="stringliteral">"Task Scheduler example"</span>);
       
    43 <a name="l00039"></a>00039 _LIT(KTextPressAKey, <span class="stringliteral">"\nPress any key to step through the example\n"</span>);
       
    44 <a name="l00040"></a>00040 _LIT(KExit,<span class="stringliteral">"\nPress any key to exit the application"</span>);
       
    45 <a name="l00041"></a>00041 _LIT(KPressAKey,<span class="stringliteral">"\nPress any key to continue\n"</span>);
       
    46 <a name="l00042"></a>00042 
       
    47 <a name="l00043"></a>00043 _LIT(KConnect, <span class="stringliteral">"\nConnecting the client to the task scheduler server"</span>);
       
    48 <a name="l00044"></a>00044 _LIT(KRegisterClient,<span class="stringliteral">"\nRegistering the client\n"</span>);
       
    49 <a name="l00045"></a>00045 _LIT(KCreateSchedule,<span class="stringliteral">"Creating a persistent schedule\n"</span>);
       
    50 <a name="l00046"></a>00046 _LIT(KCreateTask,<span class="stringliteral">"Creating task for the schedule\n"</span>);
       
    51 <a name="l00047"></a>00047 
       
    52 <a name="l00048"></a>00048 _LIT(KPersistentWait,<span class="stringliteral">"Waiting for the persistent task to complete. This will take 20 seconds\n"</span>);
       
    53 <a name="l00049"></a>00049 _LIT(KDone,<span class="stringliteral">"Task complete \n"</span>);
       
    54 <a name="l00050"></a>00050 _LIT(KTransientSchedule,<span class="stringliteral">"A transient schedule"</span>);
       
    55 <a name="l00051"></a>00051 _LIT(KTransientWait,<span class="stringliteral">"Waiting for the transient task to complete. This will take 20 seconds\n"</span>);
       
    56 <a name="l00052"></a>00052 
       
    57 <a name="l00053"></a>00053 _LIT(KCreateTransient,<span class="stringliteral">"\nCreating a transient schedule with non-repeating task\n"</span>);
       
    58 <a name="l00054"></a>00054 _LIT(KDeleteAllTasks,<span class="stringliteral">"\nDeleting all the persistent tasks scheduled by this exe"</span>);
       
    59 <a name="l00055"></a>00055 _LIT(KDeleteAllSchedules,<span class="stringliteral">"\nDeleting all schedules created by this exe\n"</span>);
       
    60 <a name="l00056"></a>00056 _LIT(KTask, <span class="stringliteral">"Number of task(s) scheduled by us is(are) %d\n"</span>);
       
    61 <a name="l00057"></a>00057 _LIT(KExists, <span class="stringliteral">"The tasks scheduled exist\n"</span>);
       
    62 <a name="l00058"></a>00058 _LIT(KOtherTask,<span class="stringliteral">"Error! Unexpected schedules not scheduled by this exe exist\n"</span>);
       
    63 <a name="l00059"></a>00059 
       
    64 <a name="l00064"></a><a class="code" href="class_c_task_schedule.html#d152b61017146041468ce89a4312ddf9">00064</a> <a class="code" href="class_c_task_schedule.html">CTaskSchedule</a>* <a class="code" href="class_c_task_schedule.html#d152b61017146041468ce89a4312ddf9">CTaskSchedule::NewLC</a>()
       
    65 <a name="l00065"></a>00065         {
       
    66 <a name="l00066"></a>00066         <a class="code" href="class_c_task_schedule.html">CTaskSchedule</a>* schedule = <span class="keyword">new</span>(ELeave) <a class="code" href="class_c_task_schedule.html">CTaskSchedule</a>();
       
    67 <a name="l00067"></a>00067         CleanupStack::PushL(schedule);
       
    68 <a name="l00068"></a>00068         schedule-&gt;<a class="code" href="class_c_task_schedule.html#05ad797c4ac25b60b42ae93b1c932830">ConstructL</a>();
       
    69 <a name="l00069"></a>00069         <span class="keywordflow">return</span> schedule;
       
    70 <a name="l00070"></a>00070         }
       
    71 <a name="l00071"></a>00071         
       
    72 <a name="l00075"></a>00075 CTaskSchedule::CTaskSchedule()
       
    73 <a name="l00076"></a>00076         {
       
    74 <a name="l00077"></a>00077         }       
       
    75 <a name="l00078"></a>00078 
       
    76 <a name="l00079"></a>00079 <span class="keywordtype">void</span> CTaskSchedule::ConstructL()
       
    77 <a name="l00080"></a>00080         {       
       
    78 <a name="l00081"></a>00081         iConsole = Console::NewL(KTitle,TSize(KConsFullScreen,KConsFullScreen));
       
    79 <a name="l00082"></a>00082         iConsole-&gt;Printf (KTextPressAKey);
       
    80 <a name="l00083"></a>00083         iConsole-&gt;Getch ();
       
    81 <a name="l00084"></a>00084         }
       
    82 <a name="l00085"></a>00085 
       
    83 <a name="l00089"></a><a class="code" href="class_c_task_schedule.html#739ccbea3ef8f1dc76440e829f206fb6">00089</a> <a class="code" href="class_c_task_schedule.html#739ccbea3ef8f1dc76440e829f206fb6">CTaskSchedule::~CTaskSchedule</a>()
       
    84 <a name="l00090"></a>00090         {
       
    85 <a name="l00091"></a>00091         iScheduler.Close();
       
    86 <a name="l00092"></a>00092         iConsole-&gt;Printf(KExit);
       
    87 <a name="l00093"></a>00093         iConsole-&gt;Getch();
       
    88 <a name="l00094"></a>00094         
       
    89 <a name="l00095"></a>00095         <span class="keyword">delete</span> iConsole;
       
    90 <a name="l00096"></a>00096         }
       
    91 <a name="l00097"></a>00097 
       
    92 <a name="l00104"></a><a class="code" href="class_c_task_schedule.html#c957da1838fe31cb3f7fe9f6a533f6c5">00104</a> <span class="keywordtype">void</span> <a class="code" href="class_c_task_schedule.html#c957da1838fe31cb3f7fe9f6a533f6c5">CTaskSchedule::ConnectAndRegisterL</a>()
       
    93 <a name="l00105"></a>00105         {
       
    94 <a name="l00106"></a>00106         
       
    95 <a name="l00107"></a>00107         <span class="comment">// Connect to the scheduler server</span>
       
    96 <a name="l00108"></a>00108         iConsole-&gt;Printf(KConnect);
       
    97 <a name="l00109"></a>00109         User::LeaveIfError(iScheduler.Connect());
       
    98 <a name="l00110"></a>00110         
       
    99 <a name="l00111"></a>00111         _LIT(KTaskExec,<span class="stringliteral">"Taskexecutor"</span>);
       
   100 <a name="l00112"></a>00112         TFileName filename;
       
   101 <a name="l00113"></a>00113         filename.Append(KTaskExec);
       
   102 <a name="l00114"></a>00114         
       
   103 <a name="l00115"></a>00115         <span class="comment">// Register with the scheduler</span>
       
   104 <a name="l00116"></a>00116         iConsole-&gt;Printf(KRegisterClient);
       
   105 <a name="l00117"></a>00117         
       
   106 <a name="l00118"></a>00118         <span class="comment">// A priority value</span>
       
   107 <a name="l00119"></a>00119         <span class="keyword">const</span> TInt priority = 3;
       
   108 <a name="l00120"></a>00120         User::LeaveIfError(iScheduler.Register(filename, priority));
       
   109 <a name="l00121"></a>00121         
       
   110 <a name="l00122"></a>00122         }
       
   111 <a name="l00123"></a>00123 
       
   112 <a name="l00130"></a><a class="code" href="class_c_task_schedule.html#5b7869136d2a8f1c625531ab1c12ef98">00130</a> <span class="keywordtype">void</span> <a class="code" href="class_c_task_schedule.html#5b7869136d2a8f1c625531ab1c12ef98">CTaskSchedule::PersistentScheduleL</a>()
       
   113 <a name="l00131"></a>00131         {
       
   114 <a name="l00132"></a>00132         
       
   115 <a name="l00133"></a>00133         iConsole-&gt;Printf(KCreateSchedule);              
       
   116 <a name="l00134"></a>00134         TSchedulerItemRef scheduleHandle;
       
   117 <a name="l00135"></a>00135         TTime time;
       
   118 <a name="l00136"></a>00136         time.UniversalTime();
       
   119 <a name="l00137"></a>00137         
       
   120 <a name="l00138"></a>00138         <span class="comment">// Assign an offset of 20 seconds. TTimeIntervalMinutes, </span>
       
   121 <a name="l00139"></a>00139         <span class="comment">// TTimeIntervalHours etc can be used for longer offsets.</span>
       
   122 <a name="l00140"></a>00140         time += TTimeIntervalSeconds(20);<span class="comment">// 20 secs in future</span>
       
   123 <a name="l00141"></a>00141 
       
   124 <a name="l00142"></a>00142         TTsTime time2 (time, ETrue);
       
   125 <a name="l00143"></a>00143 
       
   126 <a name="l00144"></a>00144         iConsole-&gt;Printf(KCreateTask);
       
   127 <a name="l00145"></a>00145         <a class="code" href="class_c_task_schedule.html#c2ed627ab19ecc8d397b63ceacd6aaa4">CreatePersistentScheduleL</a>(scheduleHandle,time2);
       
   128 <a name="l00146"></a>00146 
       
   129 <a name="l00147"></a>00147         <span class="comment">// Create the task to be scheduled</span>
       
   130 <a name="l00148"></a>00148         TTaskInfo taskInfo;
       
   131 <a name="l00149"></a>00149         
       
   132 <a name="l00150"></a>00150         <span class="keyword">const</span> TInt priority = 2; 
       
   133 <a name="l00151"></a>00151         <span class="keyword">const</span> TInt numberOfRepeats = 2;
       
   134 <a name="l00152"></a>00152         <span class="comment">// Name of the task</span>
       
   135 <a name="l00153"></a>00153         taskInfo.iName = KTaskName;
       
   136 <a name="l00154"></a>00154         
       
   137 <a name="l00155"></a>00155         <span class="comment">// Task priority set by the client. </span>
       
   138 <a name="l00156"></a>00156         <span class="comment">// If the client has two tasks with different priorities, </span>
       
   139 <a name="l00157"></a>00157         <span class="comment">// the task with the higher priority will be executed first.</span>
       
   140 <a name="l00158"></a>00158         taskInfo.iPriority = priority;
       
   141 <a name="l00159"></a>00159         
       
   142 <a name="l00160"></a>00160         <span class="comment">// Task repeats twice</span>
       
   143 <a name="l00161"></a>00161         taskInfo.iRepeat = numberOfRepeats;
       
   144 <a name="l00162"></a>00162         
       
   145 <a name="l00163"></a>00163         _LIT(KScheduleType,<span class="stringliteral">" persistent schedule"</span>);
       
   146 <a name="l00164"></a>00164         <span class="keyword">const</span> TDesC* persistent = &amp;KScheduleType;
       
   147 <a name="l00165"></a>00165         HBufC* data = persistent-&gt;AllocLC();
       
   148 <a name="l00166"></a>00166         
       
   149 <a name="l00167"></a>00167         <span class="comment">// Add the task</span>
       
   150 <a name="l00168"></a>00168         User::LeaveIfError(iScheduler.ScheduleTask(taskInfo, *data, scheduleHandle.iHandle));
       
   151 <a name="l00169"></a>00169                                 
       
   152 <a name="l00170"></a>00170         <span class="comment">// Wait for the entry to fire</span>
       
   153 <a name="l00171"></a>00171         iConsole-&gt;Printf(KPersistentWait);
       
   154 <a name="l00172"></a>00172         <span class="keyword">const</span> TInt twentySecs = 20000000;
       
   155 <a name="l00173"></a>00173         User::After(twentySecs); <span class="comment">// pause for 20 seconds</span>
       
   156 <a name="l00174"></a>00174         
       
   157 <a name="l00175"></a>00175         <span class="comment">// Delete all the persistent schedules created</span>
       
   158 <a name="l00176"></a>00176         <a class="code" href="class_c_task_schedule.html#0c3db205409436a0b47b3e11c9d3190f">DeleteSchedulesL</a>(scheduleHandle, EAllSchedules);
       
   159 <a name="l00177"></a>00177 
       
   160 <a name="l00178"></a>00178         CleanupStack::PopAndDestroy(1); <span class="comment">// data</span>
       
   161 <a name="l00179"></a>00179         
       
   162 <a name="l00180"></a>00180         }
       
   163 <a name="l00181"></a>00181 
       
   164 <a name="l00182"></a>00182         
       
   165 <a name="l00197"></a><a class="code" href="class_c_task_schedule.html#c2ed627ab19ecc8d397b63ceacd6aaa4">00197</a> <span class="keywordtype">void</span> <a class="code" href="class_c_task_schedule.html#c2ed627ab19ecc8d397b63ceacd6aaa4">CTaskSchedule::CreatePersistentScheduleL</a>(TSchedulerItemRef&amp; aRef, <span class="keyword">const</span> TTsTime&amp; aStartTime)
       
   166 <a name="l00198"></a>00198         {
       
   167 <a name="l00199"></a>00199         CArrayFixFlat&lt;TScheduleEntryInfo2&gt;* cSchEntryInfoArray; 
       
   168 <a name="l00200"></a>00200         cSchEntryInfoArray = <span class="keyword">new</span> CArrayFixFlat&lt;TScheduleEntryInfo2&gt;(1);
       
   169 <a name="l00201"></a>00201         CleanupStack::PushL(cSchEntryInfoArray);
       
   170 <a name="l00202"></a>00202 
       
   171 <a name="l00203"></a>00203         <span class="comment">// Create an hourly schedule with StartTime of aStartTime</span>
       
   172 <a name="l00204"></a>00204         TScheduleEntryInfo2 entry1;
       
   173 <a name="l00205"></a>00205         
       
   174 <a name="l00206"></a>00206         <span class="comment">// Set the first instance when the entry will </span>
       
   175 <a name="l00207"></a>00207         <span class="comment">// cause the execution of tasks. </span>
       
   176 <a name="l00208"></a>00208         entry1.SetStartTime(aStartTime);
       
   177 <a name="l00209"></a>00209         
       
   178 <a name="l00210"></a>00210         <span class="comment">// Set the type of interval used between due times </span>
       
   179 <a name="l00211"></a>00211         <span class="comment">// for the scheduled entry</span>
       
   180 <a name="l00212"></a>00212         entry1.SetIntervalType(TIntervalType(EHourly));
       
   181 <a name="l00213"></a>00213         
       
   182 <a name="l00214"></a>00214         <span class="comment">// Set the period for which the entry is valid. After 8 hours the </span>
       
   183 <a name="l00215"></a>00215         <span class="comment">// tasks associated with the entry will not be eligible for execution.</span>
       
   184 <a name="l00216"></a>00216         <span class="keyword">const</span> TInt eightHours = 480; <span class="comment">// in minutes </span>
       
   185 <a name="l00217"></a>00217         entry1.SetValidityPeriod(TTimeIntervalMinutes (eightHours));
       
   186 <a name="l00218"></a>00218         
       
   187 <a name="l00219"></a>00219         <span class="comment">// Set the interval between execution of tasks</span>
       
   188 <a name="l00220"></a>00220         <span class="comment">// Here the interval is 1 hour because the interval type is hourly.</span>
       
   189 <a name="l00221"></a>00221         <span class="keyword">const</span> TInt interval = 1;
       
   190 <a name="l00222"></a>00222         entry1.SetInterval(interval);
       
   191 <a name="l00223"></a>00223 
       
   192 <a name="l00224"></a>00224         cSchEntryInfoArray-&gt;AppendL(entry1);
       
   193 <a name="l00225"></a>00225         
       
   194 <a name="l00226"></a>00226         User::LeaveIfError(iScheduler.CreatePersistentSchedule(aRef, *cSchEntryInfoArray));
       
   195 <a name="l00227"></a>00227         CleanupStack::PopAndDestroy(cSchEntryInfoArray);
       
   196 <a name="l00228"></a>00228         
       
   197 <a name="l00229"></a>00229         }
       
   198 <a name="l00230"></a>00230         
       
   199 <a name="l00231"></a>00231 
       
   200 <a name="l00240"></a><a class="code" href="class_c_task_schedule.html#abfef5ace0331f83eb8cd4de511d3d7f">00240</a> <span class="keywordtype">void</span> <a class="code" href="class_c_task_schedule.html#abfef5ace0331f83eb8cd4de511d3d7f">CTaskSchedule::CreateTransientScheduleL</a>()
       
   201 <a name="l00241"></a>00241         {
       
   202 <a name="l00242"></a>00242         iConsole-&gt;ClearScreen();
       
   203 <a name="l00243"></a>00243 
       
   204 <a name="l00244"></a>00244         TSchedulerItemRef ref;
       
   205 <a name="l00245"></a>00245         CArrayFixFlat&lt;TScheduleEntryInfo2&gt;* cSchEntryInfoArray;
       
   206 <a name="l00246"></a>00246         cSchEntryInfoArray = <span class="keyword">new</span> CArrayFixFlat&lt;TScheduleEntryInfo2&gt;(1);
       
   207 <a name="l00247"></a>00247         
       
   208 <a name="l00248"></a>00248         CleanupStack::PushL(cSchEntryInfoArray);
       
   209 <a name="l00249"></a>00249         ref.iName = KTransientSchedule;
       
   210 <a name="l00250"></a>00250         iConsole-&gt;Printf(KCreateTransient);
       
   211 <a name="l00251"></a>00251         
       
   212 <a name="l00252"></a>00252         <span class="comment">// Create a schedule entry</span>
       
   213 <a name="l00253"></a>00253         TScheduleEntryInfo2 entry;      
       
   214 <a name="l00254"></a>00254         TTime now;
       
   215 <a name="l00255"></a>00255         
       
   216 <a name="l00256"></a>00256         <span class="comment">//      Set the date and time of this TTime to the universal time. </span>
       
   217 <a name="l00257"></a>00257         now.UniversalTime();
       
   218 <a name="l00258"></a>00258         
       
   219 <a name="l00259"></a>00259         <span class="comment">// Assign an offset of 15 seconds. TTimeIntervalMinutes, </span>
       
   220 <a name="l00260"></a>00260         <span class="comment">// TTimeIntervalHours etc can be used for longer offsets.</span>
       
   221 <a name="l00261"></a>00261         TInt offset = 15;
       
   222 <a name="l00262"></a>00262         now += TTimeIntervalSeconds(offset);
       
   223 <a name="l00263"></a>00263         
       
   224 <a name="l00264"></a>00264         <span class="comment">// Constructs a TTsTime with a TTime object. </span>
       
   225 <a name="l00265"></a>00265         <span class="comment">// ETrue indicates that TTsTime is UTC based time</span>
       
   226 <a name="l00266"></a>00266         TTsTime time (now, ETrue);
       
   227 <a name="l00267"></a>00267         
       
   228 <a name="l00268"></a>00268         <span class="comment">// Set the above time as the first time at which </span>
       
   229 <a name="l00269"></a>00269         <span class="comment">// the entry will cause execution of tasks. </span>
       
   230 <a name="l00270"></a>00270         entry.SetStartTime(time);
       
   231 <a name="l00271"></a>00271         
       
   232 <a name="l00272"></a>00272         <span class="comment">// Set the type of interval used between due times for scheduled entry</span>
       
   233 <a name="l00273"></a>00273         entry.SetIntervalType(TIntervalType(EHourly));
       
   234 <a name="l00274"></a>00274         
       
   235 <a name="l00275"></a>00275         <span class="comment">// Set the period for which the entry is valid. </span>
       
   236 <a name="l00276"></a>00276         <span class="comment">// After 2 hours the tasks associated with the entry will not be eligible for execution </span>
       
   237 <a name="l00277"></a>00277         TInt validity = 120;
       
   238 <a name="l00278"></a>00278         entry.SetValidityPeriod(TTimeIntervalMinutes (validity));
       
   239 <a name="l00279"></a>00279         
       
   240 <a name="l00280"></a>00280         <span class="comment">// Set the interval between execution of tasks</span>
       
   241 <a name="l00281"></a>00281         <span class="comment">// Here the interval is 1 hour because the interval type is hourly.</span>
       
   242 <a name="l00282"></a>00282         entry.SetInterval(1);
       
   243 <a name="l00283"></a>00283         cSchEntryInfoArray-&gt;AppendL(entry);
       
   244 <a name="l00284"></a>00284         
       
   245 <a name="l00285"></a>00285         <span class="comment">// Create a transient task to be scheduled</span>
       
   246 <a name="l00286"></a>00286         TTaskInfo taskInfo;
       
   247 <a name="l00287"></a>00287         <span class="comment">// Name of the task</span>
       
   248 <a name="l00288"></a>00288         taskInfo.iName = KTransientSchedule;
       
   249 <a name="l00289"></a>00289         <span class="comment">// Task id</span>
       
   250 <a name="l00290"></a>00290         <span class="keyword">const</span> TInt tId = 0;
       
   251 <a name="l00291"></a>00291         taskInfo.iTaskId = tId;
       
   252 <a name="l00292"></a>00292         
       
   253 <a name="l00293"></a>00293         <span class="comment">// The task repeats just once</span>
       
   254 <a name="l00294"></a>00294         <span class="keyword">const</span> TInt numberOfRepeats = 1;
       
   255 <a name="l00295"></a>00295         taskInfo.iRepeat = numberOfRepeats;
       
   256 <a name="l00296"></a>00296         
       
   257 <a name="l00297"></a>00297         <span class="comment">// Task priority set by the client. </span>
       
   258 <a name="l00298"></a>00298         <span class="comment">// Where a client has two tasks with different priorities, </span>
       
   259 <a name="l00299"></a>00299         <span class="comment">// the task with the higher priority will be executed first.</span>
       
   260 <a name="l00300"></a>00300         <span class="keyword">const</span> TInt priority = 2; 
       
   261 <a name="l00301"></a>00301         taskInfo.iPriority = priority;
       
   262 <a name="l00302"></a>00302         
       
   263 <a name="l00303"></a>00303         _LIT(KScheduleType,<span class="stringliteral">" transient schedule"</span>);
       
   264 <a name="l00304"></a>00304         <span class="keyword">const</span> TDesC* <span class="keyword">transient</span> = &amp;KScheduleType;
       
   265 <a name="l00305"></a>00305         HBufC* data = <span class="keyword">transient</span>-&gt;AllocLC();
       
   266 <a name="l00306"></a>00306                 
       
   267 <a name="l00307"></a>00307         <span class="comment">// Schedule the item</span>
       
   268 <a name="l00308"></a>00308         User::LeaveIfError(iScheduler.ScheduleTask(taskInfo, *data, ref, *cSchEntryInfoArray));
       
   269 <a name="l00309"></a>00309         
       
   270 <a name="l00310"></a>00310         <span class="comment">// Change the start time and validity duration for the schedule</span>
       
   271 <a name="l00311"></a>00311         offset = 19; <span class="comment">// 19 seconds in future</span>
       
   272 <a name="l00312"></a>00312         now += TTimeIntervalSeconds(offset);
       
   273 <a name="l00313"></a>00313         TTsTime newTime (now, ETrue);
       
   274 <a name="l00314"></a>00314         entry.SetStartTime(newTime);
       
   275 <a name="l00315"></a>00315         validity = 300;
       
   276 <a name="l00316"></a>00316         entry.SetValidityPeriod(TTimeIntervalMinutes (validity));
       
   277 <a name="l00317"></a>00317         cSchEntryInfoArray-&gt;AppendL(entry);
       
   278 <a name="l00318"></a>00318         
       
   279 <a name="l00319"></a>00319         <span class="comment">// Change the transient time based schedule</span>
       
   280 <a name="l00320"></a>00320     User::LeaveIfError(iScheduler.EditSchedule(ref.iHandle, *cSchEntryInfoArray));
       
   281 <a name="l00321"></a>00321         
       
   282 <a name="l00322"></a>00322         CleanupStack::PopAndDestroy(2); <span class="comment">// data, CSchEntryInfoArray</span>
       
   283 <a name="l00323"></a>00323 
       
   284 <a name="l00324"></a>00324         <span class="comment">// Check if the tasks scheduled exist</span>
       
   285 <a name="l00325"></a>00325         TBool exists;
       
   286 <a name="l00326"></a>00326         <a class="code" href="class_c_task_schedule.html#3b047bd6e178cbc4964d69adb56e1945">DoesScheduledItemExistL</a>(ref, exists);
       
   287 <a name="l00327"></a>00327         <span class="keywordflow">if</span>(!exists)
       
   288 <a name="l00328"></a>00328                 {
       
   289 <a name="l00329"></a>00329                 User::Leave(KErrNotFound);
       
   290 <a name="l00330"></a>00330                 }
       
   291 <a name="l00331"></a>00331         <span class="comment">// Wait for the task to fire and complete</span>
       
   292 <a name="l00332"></a>00332         iConsole-&gt;Printf(KTransientWait);
       
   293 <a name="l00333"></a>00333         <span class="keyword">const</span> TInt twentySecs = 20000000;
       
   294 <a name="l00334"></a>00334         User::After(twentySecs); <span class="comment">// pause for 20 seconds</span>
       
   295 <a name="l00335"></a>00335         
       
   296 <a name="l00336"></a>00336         iConsole-&gt;Printf(KDone);        
       
   297 <a name="l00337"></a>00337 
       
   298 <a name="l00338"></a>00338         <span class="comment">// Transient schedules are deleted automatically once they are executed</span>
       
   299 <a name="l00339"></a>00339         <span class="comment">// i.e check for count to be zero in the function being called</span>
       
   300 <a name="l00340"></a>00340         <a class="code" href="class_c_task_schedule.html#3b047bd6e178cbc4964d69adb56e1945">DoesScheduledItemExistL</a>(ref, exists);
       
   301 <a name="l00341"></a>00341         <span class="keywordflow">if</span>(exists)
       
   302 <a name="l00342"></a>00342                 {
       
   303 <a name="l00343"></a>00343                 User::Leave(KErrGeneral);
       
   304 <a name="l00344"></a>00344                 }
       
   305 <a name="l00345"></a>00345         }
       
   306 <a name="l00346"></a>00346 
       
   307 <a name="l00353"></a><a class="code" href="class_c_task_schedule.html#3b047bd6e178cbc4964d69adb56e1945">00353</a>  <span class="keywordtype">void</span> <a class="code" href="class_c_task_schedule.html#3b047bd6e178cbc4964d69adb56e1945">CTaskSchedule::DoesScheduledItemExistL</a>(TSchedulerItemRef &amp;aRef, TBool&amp; aExists)
       
   308 <a name="l00354"></a>00354         <span class="comment">// Extract schedule references from the schedule server based on a filter.</span>
       
   309 <a name="l00355"></a>00355         {
       
   310 <a name="l00356"></a>00356         aExists = EFalse;
       
   311 <a name="l00357"></a>00357         CArrayFixFlat&lt;TSchedulerItemRef&gt;* CSchItemRefArray;
       
   312 <a name="l00358"></a>00358         
       
   313 <a name="l00359"></a>00359         CSchItemRefArray = <span class="keyword">new</span> CArrayFixFlat&lt;TSchedulerItemRef&gt;(3);
       
   314 <a name="l00360"></a>00360         CleanupStack::PushL(CSchItemRefArray);
       
   315 <a name="l00361"></a>00361         
       
   316 <a name="l00362"></a>00362         User::LeaveIfError(iScheduler.GetScheduleRefsL(*CSchItemRefArray, EAllSchedules));
       
   317 <a name="l00363"></a>00363         
       
   318 <a name="l00364"></a>00364         TInt count = CSchItemRefArray-&gt;Count();
       
   319 <a name="l00365"></a>00365         <span class="keywordflow">for</span>(TInt i = 0; i &lt; count; i++)
       
   320 <a name="l00366"></a>00366                 {
       
   321 <a name="l00367"></a>00367                 <span class="comment">// Get a list of schedules created by this executable</span>
       
   322 <a name="l00368"></a>00368                 <span class="keywordflow">if</span>(aRef.iHandle == (*CSchItemRefArray)[i].iHandle)
       
   323 <a name="l00369"></a>00369                         {
       
   324 <a name="l00370"></a>00370                         aExists = ETrue;
       
   325 <a name="l00371"></a>00371                         iConsole-&gt;Printf(KExists);
       
   326 <a name="l00372"></a>00372                         iConsole-&gt;Printf(KTask, count);
       
   327 <a name="l00373"></a>00373                         }
       
   328 <a name="l00374"></a>00374                 <span class="keywordflow">else</span>
       
   329 <a name="l00375"></a>00375                         {
       
   330 <a name="l00376"></a>00376                         iConsole-&gt;Printf(KOtherTask);
       
   331 <a name="l00377"></a>00377                         }
       
   332 <a name="l00378"></a>00378                 }
       
   333 <a name="l00379"></a>00379 
       
   334 <a name="l00380"></a>00380         CleanupStack::PopAndDestroy(); <span class="comment">// CSchItemRefArray</span>
       
   335 <a name="l00381"></a>00381 
       
   336 <a name="l00382"></a>00382         }
       
   337 <a name="l00383"></a>00383 
       
   338 <a name="l00395"></a><a class="code" href="class_c_task_schedule.html#0c3db205409436a0b47b3e11c9d3190f">00395</a> <span class="keywordtype">void</span> <a class="code" href="class_c_task_schedule.html#0c3db205409436a0b47b3e11c9d3190f">CTaskSchedule::DeleteSchedulesL</a>(TSchedulerItemRef &amp;aRef, TScheduleFilter aFilter)
       
   339 <a name="l00396"></a>00396         {
       
   340 <a name="l00397"></a>00397         CArrayFixFlat&lt;TSchedulerItemRef&gt;* CSchItemRefArray;
       
   341 <a name="l00398"></a>00398         
       
   342 <a name="l00399"></a>00399         CSchItemRefArray = <span class="keyword">new</span> CArrayFixFlat&lt;TSchedulerItemRef&gt;(3);
       
   343 <a name="l00400"></a>00400         CleanupStack::PushL(CSchItemRefArray);
       
   344 <a name="l00401"></a>00401         
       
   345 <a name="l00402"></a>00402         User::LeaveIfError(iScheduler.GetScheduleRefsL(*CSchItemRefArray, aFilter));
       
   346 <a name="l00403"></a>00403         
       
   347 <a name="l00404"></a>00404         TInt count = CSchItemRefArray-&gt;Count();
       
   348 <a name="l00405"></a>00405         iConsole-&gt;Printf(KTask, count);
       
   349 <a name="l00406"></a>00406         
       
   350 <a name="l00407"></a>00407         <span class="keywordflow">for</span>(TInt i = 0; i &lt; count; i++)
       
   351 <a name="l00408"></a>00408                 {
       
   352 <a name="l00409"></a>00409                 <span class="comment">// Check if the schedules are created by this exe or</span>
       
   353 <a name="l00410"></a>00410                 <span class="comment">// some other exe</span>
       
   354 <a name="l00411"></a>00411                 <span class="keywordflow">if</span>(aRef.iHandle == (*CSchItemRefArray)[i].iHandle)
       
   355 <a name="l00412"></a>00412                         {       
       
   356 <a name="l00413"></a>00413                         <span class="comment">// Delete the tasks scheduled by us (this exe)</span>
       
   357 <a name="l00414"></a>00414                         iConsole-&gt;Printf(KDeleteAllTasks);
       
   358 <a name="l00415"></a>00415                         User::LeaveIfError(iScheduler.DeleteTask(aRef.iHandle));
       
   359 <a name="l00416"></a>00416                         <span class="comment">// Delete the schedules created by us (this exe)</span>
       
   360 <a name="l00417"></a>00417                         iConsole-&gt;Printf(KDeleteAllSchedules);
       
   361 <a name="l00418"></a>00418                         User::LeaveIfError(iScheduler.DeleteSchedule(aRef.iHandle));
       
   362 <a name="l00419"></a>00419                         
       
   363 <a name="l00420"></a>00420                         iConsole-&gt;Printf(KPressAKey);
       
   364 <a name="l00421"></a>00421                         iConsole-&gt;Getch();
       
   365 <a name="l00422"></a>00422                                         
       
   366 <a name="l00423"></a>00423                         }
       
   367 <a name="l00424"></a>00424                 <span class="keywordflow">else</span>
       
   368 <a name="l00425"></a>00425                         {
       
   369 <a name="l00426"></a>00426                         <span class="comment">// Not deleting the tasks or schedules as,</span>
       
   370 <a name="l00427"></a>00427                         <span class="comment">// they are not created by this exe</span>
       
   371 <a name="l00428"></a>00428                         iConsole-&gt;Printf(KOtherTask);
       
   372 <a name="l00429"></a>00429                         }
       
   373 <a name="l00430"></a>00430                 }
       
   374 <a name="l00431"></a>00431         CleanupStack::PopAndDestroy(); <span class="comment">// CSchItemRefArray</span>
       
   375 <a name="l00432"></a>00432         
       
   376 <a name="l00433"></a>00433         }
       
   377 <a name="l00434"></a>00434         
       
   378 <a name="l00435"></a><a class="code" href="taskscheduler_8cpp.html#5fb473d4ee18739183215b04dcad6e12">00435</a> <span class="keywordtype">void</span> <a class="code" href="circularbuffer_8cpp.html#5fb473d4ee18739183215b04dcad6e12">MainL</a>()
       
   379 <a name="l00436"></a>00436         {
       
   380 <a name="l00437"></a>00437         <span class="comment">// Create an Active Scheduler to handle asychronous calls</span>
       
   381 <a name="l00438"></a>00438         CActiveScheduler* scheduler = <span class="keyword">new</span> (ELeave) CActiveScheduler;
       
   382 <a name="l00439"></a>00439         CleanupStack::PushL(scheduler);
       
   383 <a name="l00440"></a>00440 
       
   384 <a name="l00441"></a>00441         <span class="comment">// Install the active scheduler</span>
       
   385 <a name="l00442"></a>00442         CActiveScheduler::Install( scheduler );
       
   386 <a name="l00443"></a>00443         <a class="code" href="class_c_task_schedule.html">CTaskSchedule</a>* app = <a class="code" href="class_c_task_schedule.html#d152b61017146041468ce89a4312ddf9">CTaskSchedule::NewLC</a>();
       
   387 <a name="l00444"></a>00444         
       
   388 <a name="l00445"></a>00445         <span class="comment">// Connect and register with the task scheduler</span>
       
   389 <a name="l00446"></a>00446         app-&gt;<a class="code" href="class_c_task_schedule.html#c957da1838fe31cb3f7fe9f6a533f6c5">ConnectAndRegisterL</a>();
       
   390 <a name="l00447"></a>00447         
       
   391 <a name="l00448"></a>00448         <span class="comment">// Create a persistent schedule and add tasks to it</span>
       
   392 <a name="l00449"></a>00449         app-&gt;<a class="code" href="class_c_task_schedule.html#5b7869136d2a8f1c625531ab1c12ef98">PersistentScheduleL</a>();
       
   393 <a name="l00450"></a>00450                 
       
   394 <a name="l00451"></a>00451         <span class="comment">// Create a transient schedule and add tasks to it</span>
       
   395 <a name="l00452"></a>00452         app-&gt;<a class="code" href="class_c_task_schedule.html#abfef5ace0331f83eb8cd4de511d3d7f">CreateTransientScheduleL</a>();
       
   396 <a name="l00453"></a>00453         
       
   397 <a name="l00454"></a>00454         CleanupStack::PopAndDestroy(2); <span class="comment">// app, scheduler</span>
       
   398 <a name="l00455"></a>00455 
       
   399 <a name="l00456"></a>00456         }
       
   400 <a name="l00457"></a>00457 
       
   401 <a name="l00458"></a><a class="code" href="taskscheduler_8cpp.html#8b0fea7c5e4de0484888431020cf3ec9">00458</a> TInt <a class="code" href="dbllist_8cpp.html#0f358e9c4355138f629b8c4f37310295">E32Main</a>()
       
   402 <a name="l00459"></a>00459         {
       
   403 <a name="l00460"></a>00460     __UHEAP_MARK;
       
   404 <a name="l00461"></a>00461     CTrapCleanup* cleanup = CTrapCleanup::New();
       
   405 <a name="l00462"></a>00462     <span class="keywordflow">if</span>(cleanup == NULL)
       
   406 <a name="l00463"></a>00463         {
       
   407 <a name="l00464"></a>00464         <span class="keywordflow">return</span> KErrNoMemory;
       
   408 <a name="l00465"></a>00465         }
       
   409 <a name="l00466"></a>00466         
       
   410 <a name="l00467"></a>00467     TRAPD(err, <a class="code" href="circularbuffer_8cpp.html#5fb473d4ee18739183215b04dcad6e12">MainL</a>());
       
   411 <a name="l00468"></a>00468         <span class="keywordflow">if</span>(err != KErrNone)
       
   412 <a name="l00469"></a>00469                 {
       
   413 <a name="l00470"></a>00470                 User::Panic(_L(<span class="stringliteral">"Failed to complete"</span>),err);
       
   414 <a name="l00471"></a>00471                 }
       
   415 <a name="l00472"></a>00472     <span class="keyword">delete</span> cleanup;
       
   416 <a name="l00473"></a>00473   
       
   417 <a name="l00474"></a>00474     __UHEAP_MARKEND;
       
   418 <a name="l00475"></a>00475     <span class="keywordflow">return</span> KErrNone;
       
   419 <a name="l00476"></a>00476         }
       
   420 </pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Thu Jan 21 10:33:01 2010 for TB10.1 Example Applications by&nbsp;
       
   421 <a href="http://www.doxygen.org/index.html">
       
   422 <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.3 </small></address>
       
   423 </body>
       
   424 </html>