00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "CommonFramework.h"
00024 #include <e32math.h>
00025
00026
00027
00028
00029
00030 _LIT(KMsgQuickCancelled,"Quick service request canceled\n");
00031
00032
00033
00034
00035
00036 LOCAL_D TInt64 smallRandSeed;
00037
00038 LOCAL_C TInt smallRand()
00039 {
00040
00041 TInt bigResult=Math::Rand(smallRandSeed);
00042 return bigResult % 10;
00043 }
00044
00045 LOCAL_C void sleep(TInt aTenths)
00046 {
00047
00048 User::After(aTenths*100000);
00049 }
00050
00051
00052
00053 LOCAL_C void doExampleL()
00054 {
00055
00056 RTimer heartbeat;
00057 TRequestStatus heartbeatStatus;
00058 heartbeat.CreateLocal();
00059
00060
00061 RTimer quickService;
00062 TRequestStatus quickServiceStatus;
00063 TBool quickServiceRequestIssued=EFalse;
00064 quickService.CreateLocal();
00065
00066
00067 heartbeat.After(heartbeatStatus,1000000);
00068
00069 TInt heartbeatTick=0;
00070
00071
00072 for (;;)
00073 {
00074
00075 User::WaitForAnyRequest();
00076
00077 if (heartbeatStatus!=KRequestPending)
00078 {
00079
00080 _LIT(KMsgServicing,"Servicing heartbeat tick %d ...\n");
00081 console->Printf(KMsgServicing,heartbeatTick);
00082
00083 sleep(smallRand());
00084
00085 if (smallRand() < 5)
00086 {
00087
00088
00089 if (quickServiceRequestIssued)
00090 {
00091 quickService.Cancel();
00092 User::WaitForRequest(quickServiceStatus);
00093 quickServiceRequestIssued=EFalse;
00094 console->Printf(KMsgQuickCancelled);
00095 }
00096
00097 quickService.After(quickServiceStatus,(smallRand()*2)*100000);
00098
00099 quickServiceRequestIssued=ETrue;
00100 _LIT(KMsgQuickIssued,"Quick service request issued\n");
00101 console->Printf(KMsgQuickIssued);
00102 }
00103
00104 _LIT(KMsgServiced,"... heartbeat tick %d serviced\n");
00105 console->Printf(KMsgServiced, heartbeatTick);
00106
00107 if (heartbeatTick >= 10)
00108 {
00109
00110 _LIT(KMsgFinishing,"Finishing\n");
00111 console->Printf(KMsgFinishing);
00112
00113
00114 if (quickServiceRequestIssued)
00115 {
00116
00117 quickService.Cancel();
00118 User::WaitForRequest(quickServiceStatus);
00119 quickServiceRequestIssued=EFalse;
00120
00121 console->Printf(KMsgQuickCancelled);
00122 }
00123
00124 break;
00125 }
00126
00127 heartbeatTick++;
00128 heartbeat.After(heartbeatStatus,1000000);
00129 }
00130
00131 else if (quickServiceRequestIssued && quickServiceStatus!=KRequestPending)
00132 {
00133 _LIT(KMsgQuickCompleted,"Quick request completed\n");
00134 console->Printf(KMsgQuickCompleted);
00135 quickServiceRequestIssued=EFalse;
00136 }
00137
00138 else
00139 {
00140 _LIT(KMsgStraySignal,"Stray signal\n");
00141 User::Panic(KMsgStraySignal, 1);
00142 }
00143 }
00144
00145
00146 quickService.Close();
00147
00148
00149 heartbeat.Close();
00150 }