00001 #include "epoc-keypress-anim.hpp" 00002 00003 #if __KEYPRESS_ENABLED__ && __HAVE_ANIM__ 00004 00005 #include "ld_logging.h" 00006 #include "sa_sensor_list_log_db.h" 00007 00008 #include "common/assertions.h" 00009 #include "er_errors.h" 00010 #include "common/error_list.h" 00011 #include "common/logging.h" 00012 #include "common/platform_error.h" 00013 #include "common/utilities.h" 00014 00015 #include <errno.h> 00016 00017 #define KPropertyCategory TUid::Uid(__UID__) 00018 #define KPropertyKey 1 00019 00020 CSensor_keypress* CSensor_keypress::NewL(LogDb* aLogDb) 00021 { 00022 CSensor_keypress* self = new (ELeave) CSensor_keypress(aLogDb); 00023 CleanupStack::PushL(self); 00024 self->ConstructL(); 00025 CleanupStack::Pop(self); 00026 return self; 00027 }; 00028 00029 CSensor_keypress::CSensor_keypress(LogDb* aLogDb) : 00030 CActive(CActive::EPriorityLow) 00031 { 00032 iLogDb = aLogDb; 00033 CActiveScheduler::Add(this); 00034 }; 00035 00036 void CSensor_keypress::ConstructL() 00037 { 00038 // The size chosen so that we are not wasteful with space, but 00039 // neither should require too many reallocations. 00040 SET_TRAP_OOM(User::LeaveNoMemory()); 00041 iKeysText = g_string_sized_new(20 + MAX_NUM_CAPTURED_KEYS * 2); 00042 UNSET_TRAP_OOM(); 00043 assert(iKeysText != NULL); 00044 00045 iSession = new (ELeave) RWsSession(); 00046 00047 User::LeaveIfError(iSession->Connect()); 00048 iWinGroup = new (ELeave) RWindowGroup(*iSession); 00049 iWinGroup->Construct((TUint32)iWinGroup, EFalse); 00050 00051 iWinGroup->SetOrdinalPosition(-1, ECoeWinPriorityNeverAtFront); 00052 iWinGroup->EnableReceiptOfFocus(EFalse); 00053 00054 iWinGroupName = CApaWindowGroupName::NewL(*iSession); 00055 iWinGroupName->SetHidden(ETrue); // Hide from tasklist. 00056 iWinGroupName->SetWindowGroupName(*iWinGroup); 00057 00058 TUid cat(KPropertyCategory); 00059 iKeyEventsClient = CKeyEventsClient::NewL(cat, KPropertyKey, 00060 iSession, 00061 iWinGroup); 00062 00063 // It does not look like iKeyEventsClient owns the property, so we 00064 // shall be the ones to close it. 00065 iKeyEventsClient->OpenNotificationPropertyL(&iProperty); 00066 SET_SESSION_OPEN(iProperty); 00067 }; 00068 00069 CSensor_keypress::~CSensor_keypress() 00070 { 00071 Cancel(); 00072 LogAndClear(NULL); 00073 delete iKeyEventsClient; 00074 SESSION_CLOSE_IF_OPEN(iProperty); 00075 delete iWinGroupName; 00076 if(iWinGroup){ 00077 iWinGroup->Close(); 00078 delete iWinGroup; 00079 } 00080 if(iSession){ 00081 iSession->Close(); 00082 delete iSession; 00083 } 00084 if (iKeysText) { 00085 g_string_free(iKeysText, TRUE); 00086 } 00087 }; 00088 00089 gboolean CSensor_keypress::StartL(GError** error) 00090 { 00091 if (!IsActive()) { 00092 MakeRequest(); 00093 //log_db_log_status(iLogDb, NULL, "keypress sensor started"); 00094 } 00095 return TRUE; 00096 } 00097 00098 // Must be callable from the dtor, without ContructL necessarily 00099 // having succeeded. 00100 void CSensor_keypress::Stop() 00101 { 00102 if (IsActive()) { 00103 Cancel(); 00104 //log_db_log_status(iLogDb, NULL, "keypress sensor stopped"); 00105 } 00106 LogAndClear(NULL); // best effort 00107 } 00108 00109 void CSensor_keypress::MakeRequest() 00110 { 00111 iProperty.Subscribe(iStatus); 00112 SetActive(); 00113 } 00114 00115 void CSensor_keypress::DoCancel() 00116 { 00117 assert(IS_SESSION_OPEN(iProperty)); 00118 iProperty.Cancel(); 00119 } 00120 00121 void CSensor_keypress::RunL() 00122 { 00123 TInt errCode = iStatus.Int(); 00124 //logg("keypress (anim) RunL error %d", errCode); 00125 00126 if (errCode) { 00127 // This error really should not occur, but since it has, we will 00128 // simply log the error and inactivate this scanner. 00129 log_db_log_status(iLogDb, NULL, "INACTIVATE: keypress: failure reading sensor: %s (%d)", plat_error_strerror(errCode), errCode); 00130 Stop(); 00131 } else { 00132 TInt eventCount; 00133 errCode = iProperty.Get(KPropertyCategory, KPropertyKey, eventCount); 00134 if (errCode) { 00135 log_db_log_status(iLogDb, NULL, "INACTIVATE: keypress: RProperty access error: %s (%d)", plat_error_strerror(errCode), errCode); 00136 Stop(); 00137 } else { 00138 //logg("keypress: eventCount is %d", eventCount); 00139 { // record event time 00140 time_t now = time(NULL); 00141 if (now == -1) { 00142 px_dblog_fatal_errno(iLogDb); 00143 return; 00144 } else { 00145 iCapturedKeys[iNumCapturedKeys] = now; 00146 iNumCapturedKeys++; 00147 if (iNumCapturedKeys == MAX_NUM_CAPTURED_KEYS) { 00148 GError* localError = NULL; 00149 if (!LogAndClear(&localError)) { 00150 gx_dblog_fatal_error_clear(iLogDb, &localError); 00151 return; 00152 } 00153 } 00154 } 00155 } 00156 MakeRequest(); 00157 } 00158 } 00159 } 00160 00161 // Must be callable from the dtor, without ContructL necessarily 00162 // having succeeded. 00163 gboolean CSensor_keypress::LogAndClear(GError** error) 00164 { 00165 if (iNumCapturedKeys > 0) { 00166 assert(iKeysText); 00167 time_t base = iCapturedKeys[0]; 00168 SET_TRAP_OOM(goto nomemory); 00169 g_string_set_size(iKeysText, 0); 00170 g_string_append_printf(iKeysText, "{base: %d, times: [", base); 00171 int i = 0; 00172 while (i < iNumCapturedKeys) { 00173 if (i != 0) 00174 g_string_append(iKeysText, ", "); 00175 g_string_append_printf(iKeysText, "%d", iCapturedKeys[i] - base); 00176 i++; 00177 } 00178 g_string_append(iKeysText, "]}"); 00179 UNSET_TRAP_OOM(); 00180 iNumCapturedKeys = 0; 00181 00182 if (!log_db_log_keypress(iLogDb, iKeysText->str, error)) { 00183 return FALSE; 00184 } 00185 } 00186 return TRUE; 00187 00188 nomemory: 00189 if (error) *error = gx_error_no_memory; 00190 return FALSE; 00191 } 00192 00193 #endif // __KEYPRESS_ENABLED__ && __HAVE_ANIM__ 00194 00195 /** 00196 00197 epoc-keypress-anim.cpp 00198 00199 Copyright 2009 Helsinki Institute for Information Technology (HIIT) 00200 and the authors. All rights reserved. 00201 00202 Authors: Tero Hasu <tero.hasu@hut.fi> 00203 00204 Permission is hereby granted, free of charge, to any person 00205 obtaining a copy of this software and associated documentation files 00206 (the "Software"), to deal in the Software without restriction, 00207 including without limitation the rights to use, copy, modify, merge, 00208 publish, distribute, sublicense, and/or sell copies of the Software, 00209 and to permit persons to whom the Software is furnished to do so, 00210 subject to the following conditions: 00211 00212 The above copyright notice and this permission notice shall be 00213 included in all copies or substantial portions of the Software. 00214 00215 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00216 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00217 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00218 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 00219 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 00220 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 00221 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 00222 SOFTWARE. 00223 00224 **/
ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:52 2011 by Doxygen 1.6.1