00001 // 00002 // Copyright (c) 2009-2009 HIIT and Tero Hasu 00003 // Copyright (c) 2007-2009 Google Inc. 00004 // Copyright (c) 2006-2007 Jaiku Ltd. 00005 // Copyright (c) 2002-2006 Mika Raento and Renaud Petit 00006 // 00007 // This software is licensed at your choice under either 1 or 2 below. 00008 // 00009 // 1. MIT License 00010 // 00011 // Permission is hereby granted, free of charge, to any person obtaining a copy 00012 // of this software and associated documentation files (the "Software"), to deal 00013 // in the Software without restriction, including without limitation the rights 00014 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00015 // copies of the Software, and to permit persons to whom the Software is 00016 // furnished to do so, subject to the following conditions: 00017 // 00018 // The above copyright notice and this permission notice shall be included in 00019 // all copies or substantial portions of the Software. 00020 // 00021 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00022 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00023 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00024 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00025 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00026 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00027 // THE SOFTWARE. 00028 // 00029 // 2. Gnu General Public license 2.0 00030 // 00031 // This program is free software; you can redistribute it and/or 00032 // modify it under the terms of the GNU General Public License 00033 // as published by the Free Software Foundation; either version 2 00034 // of the License, or (at your option) any later version. 00035 // 00036 // This program is distributed in the hope that it will be useful, 00037 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00038 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00039 // GNU General Public License for more details. 00040 // 00041 // You should have received a copy of the GNU General Public License 00042 // along with this program; if not, write to the Free Software 00043 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00044 // 00045 00046 #include "ut_timeout_epoc.hpp" 00047 00048 #include "symbian_auto_ptr.hpp" 00049 00050 NONSHARABLE_CLASS(CTimeOutImpl) : public CTimeOut 00051 { 00052 public: 00053 ~CTimeOutImpl(); 00054 private: 00055 virtual void Wait(int seconds); 00056 virtual void WaitMax(int seconds); 00057 virtual void Reset(); 00058 virtual void WaitShort(int milliseconds); 00059 virtual const TTime& WaitingUntil() const; 00060 00061 CTimeOutImpl(MTimeOut& i_cb, CActive::TPriority aPriority); 00062 void ConstructL(); 00063 void RunL(); 00064 00065 MTimeOut& cb; 00066 TTime iWaitUntil; 00067 00068 friend class CTimeOut; 00069 }; 00070 00071 CTimeOut::CTimeOut(CActive::TPriority aPriority) : CTimer(aPriority) 00072 { 00073 } 00074 00075 CTimeOut::~CTimeOut() 00076 { 00077 } 00078 00079 CTimeOutImpl::CTimeOutImpl(MTimeOut& i_cb, CActive::TPriority aPriority) : 00080 CTimeOut(aPriority), cb(i_cb) 00081 { 00082 } 00083 00084 void CTimeOutImpl::ConstructL() 00085 { 00086 CTimer::ConstructL(); 00087 CActiveScheduler::Add(this); 00088 } 00089 00090 CTimeOut* CTimeOut::NewL(MTimeOut& i_cb, CActive::TPriority aPriority) 00091 { 00092 e_auto_ptr<CTimeOutImpl> ret (new (ELeave) CTimeOutImpl(i_cb, aPriority)); 00093 ret->ConstructL(); 00094 return ret.release(); 00095 } 00096 00097 void CTimeOutImpl::RunL() 00098 { 00099 // there's no guarantee that we aren't deleted 00100 // from the expired() callback, so we have to cache 00101 // any required member variables in stack variables 00102 00103 TTime now; now.HomeTime(); 00104 00105 now+=TTimeIntervalMicroSeconds(100*1000); 00106 if (now < iWaitUntil) { 00107 At(iWaitUntil); 00108 } else { 00109 iWaitUntil=TTime(0); 00110 cb.expired(this); 00111 } 00112 } 00113 00114 const TTime& CTimeOutImpl::WaitingUntil() const 00115 { 00116 return iWaitUntil; 00117 } 00118 00119 void CTimeOutImpl::WaitShort(int milliseconds) 00120 { 00121 Reset(); 00122 TTime at; 00123 at.HomeTime(); 00124 00125 if (milliseconds<0) milliseconds=0; 00126 at+=TTimeIntervalMicroSeconds(milliseconds*1000); 00127 iWaitUntil=at; 00128 At(at); 00129 } 00130 00131 void CTimeOutImpl::Wait(int seconds) 00132 { 00133 Reset(); 00134 TTime at; 00135 at.HomeTime(); 00136 00137 if (seconds<0) seconds=0; 00138 at+=TTimeIntervalSeconds(seconds); 00139 iWaitUntil=at; 00140 At(at); 00141 } 00142 00143 void CTimeOutImpl::WaitMax(int seconds) 00144 { 00145 TTime t; t.HomeTime(); 00146 if (seconds<0) seconds=0; 00147 t+=TTimeIntervalSeconds(seconds); 00148 if (IsActive() && t >= iWaitUntil) return; 00149 Reset(); 00150 iWaitUntil=t; 00151 At(t); 00152 } 00153 00154 void CTimeOutImpl::Reset() 00155 { 00156 iWaitUntil=TTime(0); 00157 Cancel(); 00158 } 00159 00160 CTimeOutImpl::~CTimeOutImpl() 00161 { 00162 Cancel(); 00163 }
ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:57 2011 by Doxygen 1.6.1