ut_retry_epoc.cpp

Go to the documentation of this file.
00001 /*
00002  !concept {:name => "Timer-based retries on Symbian"}
00003 */
00004 
00005 #include "ut_retry_epoc.hpp"
00006 
00007 #include "er_errors.h"
00008 
00009 #include "common/epoc-time.h"
00010 
00011 #include <stdlib.h> // rand
00012 
00013 // --------------------------------------------------
00014 // CRetryAo
00015 // --------------------------------------------------
00016 
00017 CRetryAo* CRetryAo::NewL(MRetryAoObserver& aObserver,
00018        TInt aMaxNumRetries,
00019        TInt aBaseInterval /* secs */)
00020 {
00021   CRetryAo* obj = new (ELeave) CRetryAo(aObserver, aMaxNumRetries,
00022           aBaseInterval);
00023   CleanupStack::PushL(obj);
00024   obj->ConstructL();
00025   CleanupStack::Pop();
00026   return obj;
00027 }
00028 
00029 CRetryAo::CRetryAo(MRetryAoObserver& aObserver,
00030        TInt aMaxNumRetries,
00031        TInt aBaseInterval /* secs */) :
00032   CActive(EPriorityLow), 
00033   iObserver(aObserver),
00034   iMaxNumRetries(aMaxNumRetries),
00035   iBaseInterval(aBaseInterval)
00036   
00037 {
00038   CActiveScheduler::Add(this);
00039 }
00040 
00041 void CRetryAo::ConstructL()
00042 {
00043   LEAVE_IF_ERROR_OR_SET_SESSION_OPEN(iTimer, iTimer.CreateLocal()); 
00044 }
00045 
00046 CRetryAo::~CRetryAo()
00047 {
00048   Cancel();
00049   SESSION_CLOSE_IF_OPEN(iTimer);
00050 }
00051 
00052 TBool CRetryAo::Retry()
00053 {
00054   Cancel();
00055   iNumScanFailures++;
00056   if (iNumScanFailures > iMaxNumRetries) {
00057     return EFalse;
00058   } else {
00059     TTimeIntervalMicroSeconds32 interval = WaitInterval();
00060     iTimer.After(iStatus, interval);
00061     SetActive();
00062     return ETrue;
00063   }
00064 }
00065 
00066 void CRetryAo::RunL()
00067 {
00068   iObserver.RetryTimerExpired(this, iStatus.Int());
00069 }
00070 
00071 void CRetryAo::DoCancel()
00072 {
00073   iTimer.Cancel();
00074 }
00075 
00076 TTimeIntervalMicroSeconds32 CRetryAo::WaitInterval()
00077 {
00078   int secs = (iBaseInterval * iNumScanFailures) + (rand() % 10);
00079   TTimeIntervalMicroSeconds32 interval = SecsToUsecs(secs);
00080   return interval;
00081 }
00082 
00083 void CRetryAo::ResetFailures()
00084 { 
00085   iNumScanFailures = 0; 
00086 }
00087 
00088 /**
00089 
00090 ut_retry_epoc.cpp
00091 
00092 Copyright 2009 Helsinki Institute for Information Technology (HIIT)
00093 and the authors. All rights reserved.
00094 
00095 Authors: Tero Hasu <tero.hasu@hut.fi>
00096 
00097 Permission is hereby granted, free of charge, to any person
00098 obtaining a copy of this software and associated documentation files
00099 (the "Software"), to deal in the Software without restriction,
00100 including without limitation the rights to use, copy, modify, merge,
00101 publish, distribute, sublicense, and/or sell copies of the Software,
00102 and to permit persons to whom the Software is furnished to do so,
00103 subject to the following conditions:
00104 
00105 The above copyright notice and this permission notice shall be
00106 included in all copies or substantial portions of the Software.
00107 
00108 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00109 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00110 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00111 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
00112 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
00113 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00114 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00115 SOFTWARE.
00116 
00117  **/

ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:57 2011 by Doxygen 1.6.1