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 // http://www.newlc.com/article-275.html -- RTimer::Inactivity 00047 00048 #include "epoc-inactivity.hpp" 00049 00050 #if __INACTIVITY_ENABLED__ 00051 00052 #include "er_errors.h" 00053 #include "sa_sensor_list_log_db.h" 00054 00055 #define TIMEOUT_SECS TTimeIntervalSeconds(60) 00056 00057 CTOR_IMPL_CSensor_inactivity; 00058 00059 void CSensor_inactivity::ConstructL() 00060 { 00061 LEAVE_IF_ERROR_OR_SET_SESSION_OPEN(iTimer, iTimer.CreateLocal()); 00062 } 00063 00064 CSensor_inactivity::~CSensor_inactivity() 00065 { 00066 if (IS_SESSION_OPEN(iTimer)) { 00067 Cancel(); 00068 iTimer.Close(); 00069 } 00070 } 00071 00072 #define iLogDb ac_LogDb(iC) 00073 00074 gboolean CSensor_inactivity::StartL(GError** error) 00075 { 00076 if (!IsActive()) { 00077 GetState(); 00078 MakeRequest(); 00079 //log_db_log_status(iLogDb, NULL, "inactivity sensor started"); 00080 } 00081 return TRUE; 00082 } 00083 00084 void CSensor_inactivity::Stop() 00085 { 00086 if ((IsActive())) { 00087 Cancel(); 00088 //log_db_log_status(iLogDb, NULL, "inactivity sensor stopped"); 00089 } 00090 } 00091 00092 void CSensor_inactivity::RunL() 00093 { 00094 TInt errCode = iStatus.Int(); 00095 00096 if (errCode) { 00097 log_db_log_status(iLogDb, NULL, "INACTIVATE: inactivity: RTimer inactivity request error %d", errCode); 00098 return; 00099 } 00100 00101 if (iCurrentState == EIdle) { 00102 iCurrentState = EActive; 00103 } else { 00104 iCurrentState = EIdle; 00105 } 00106 00107 LogDb* logDb = ac_LogDb(iC); 00108 GError* localError = NULL; 00109 if (!log_db_log_inactivity(logDb, (iCurrentState == EActive), &localError)) { 00110 gx_txtlog_fatal_error_free(localError); 00111 return; 00112 } 00113 00114 guilogf("inactivity: %s", (iCurrentState == EActive) ? "active" : "inactive"); 00115 00116 MakeRequest(); 00117 } 00118 00119 void CSensor_inactivity::DoCancel() 00120 { 00121 iTimer.Cancel(); 00122 } 00123 00124 void CSensor_inactivity::MakeRequest() 00125 { 00126 // This should not be dangerous even if there is some nasty process 00127 // that keeps resetting the timer. In that case we will end up in 00128 // the EActive state, and we will stay there since the timer resets 00129 // happen, and will not get timer events. 00130 if (iCurrentState == EIdle) { 00131 // Wait until there is some activity. 00132 iTimer.Inactivity(iStatus, 0); 00133 } else { 00134 // Wait until there is no activity and has not been for TIMEOUT_SECS. 00135 iTimer.Inactivity(iStatus, TIMEOUT_SECS); 00136 } 00137 00138 SetActive(); 00139 } 00140 00141 void CSensor_inactivity::GetState() 00142 { 00143 if (User::InactivityTime() > TIMEOUT_SECS) { 00144 iCurrentState = EIdle; 00145 } else { 00146 iCurrentState = EActive; 00147 } 00148 } 00149 00150 #endif // __INACTIVITY_ENABLED__
ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:52 2011 by Doxygen 1.6.1