sa_sensor_util_epoc.cpp

Go to the documentation of this file.
00001 #include "sa_sensor_util_epoc.hpp"
00002 
00003 #include "er_errors.h"
00004 
00005 #include "common/epoc-time.h"
00006 
00007 #include <stdlib.h> // rand
00008 
00009 // --------------------------------------------------
00010 // CActiveRetry
00011 // --------------------------------------------------
00012 
00013 void CActiveRetry::TimerConstructL()
00014 {
00015   LEAVE_IF_ERROR_OR_SET_SESSION_OPEN(iRetryTimer, iRetryTimer.CreateLocal()); 
00016 }
00017 
00018 CActiveRetry::~CActiveRetry()
00019 {
00020   SESSION_CLOSE_IF_OPEN(iRetryTimer);
00021 }
00022 
00023 TTimeIntervalMicroSeconds32 CActiveRetry::WaitInterval()
00024 {
00025   int secs = BaseInterval() * (1 + iNumScanFailures) + (rand() % 10);
00026   TTimeIntervalMicroSeconds32 interval = SecsToUsecs(secs);
00027   return interval;
00028 }
00029 
00030 void CActiveRetry::Retry()
00031 {
00032   TTimeIntervalMicroSeconds32 interval = WaitInterval();
00033   iRetryTimer.After(iStatus, interval);
00034   SetActive();
00035   iRetryState = ERetryWaiting;
00036 }
00037 
00038 void CActiveRetry::RunL()
00039 {
00040   TRetryState oldState = iRetryState;
00041   iRetryState = EInactive;
00042 
00043   switch (oldState)
00044     {
00045     case EDoingActual:
00046       {
00047   RunActualL();
00048   break;
00049       }
00050     case ERetryWaiting:
00051       {
00052   int errCode = iStatus.Int();
00053   if (errCode) {
00054     ex_txtlog_fatal_error(errCode);
00055     return;
00056   }
00057   MakeRequest();
00058         break;
00059       }
00060     default:
00061       {
00062         assert(0 && "unexpected state");
00063         break;
00064       }
00065     }
00066 }
00067   
00068 void CActiveRetry::DoCancel()
00069 {
00070   switch (iRetryState)
00071     {
00072     case EDoingActual:
00073       {
00074   DoCancelActual();
00075         break;
00076       }
00077     case ERetryWaiting:
00078       {
00079   iRetryTimer.Cancel();
00080         break;
00081       }
00082     default:
00083       {
00084         assert(0 && "unexpected state");
00085         break;
00086       }
00087     }
00088 
00089   // Note that the state must never become anything else without
00090   // invoking SetActive at the same time.
00091   iRetryState = EInactive;
00092 }
00093 
00094 // --------------------------------------------------
00095 // CActiveSensorG
00096 // --------------------------------------------------
00097 
00098 gboolean CActiveSensorG::StartL(GError** error)
00099 {
00100   iNumScanFailures = 0;
00101   if (!IsActive()) {
00102     MakeRequest();
00103   }
00104   return TRUE;
00105 }
00106 
00107 void CActiveSensorG::Stop()
00108 {
00109   if ((IsActive())) {
00110     Cancel();
00111   }
00112 }
00113 
00114 /**
00115 
00116 sa_sensor_util_epoc.cpp
00117 
00118 Copyright 2009 Helsinki Institute for Information Technology (HIIT)
00119 and the authors. All rights reserved.
00120 
00121 Authors: Tero Hasu <tero.hasu@hut.fi>
00122 
00123 Permission is hereby granted, free of charge, to any person
00124 obtaining a copy of this software and associated documentation files
00125 (the "Software"), to deal in the Software without restriction,
00126 including without limitation the rights to use, copy, modify, merge,
00127 publish, distribute, sublicense, and/or sell copies of the Software,
00128 and to permit persons to whom the Software is furnished to do so,
00129 subject to the following conditions:
00130 
00131 The above copyright notice and this permission notice shall be
00132 included in all copies or substantial portions of the Software.
00133 
00134 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00135 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00136 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00137 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
00138 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
00139 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00140 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00141 SOFTWARE.
00142 
00143  **/

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