[Fedora-directory-commits] esc/src/lib/coolkey SmartCardMonitoringThread.cpp, 1.2, 1.3

Jack Magne (jmagne) fedora-directory-commits at redhat.com
Sat Feb 24 02:22:06 UTC 2007


Author: jmagne

Update of /cvs/dirsec/esc/src/lib/coolkey
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv2391

Modified Files:
	SmartCardMonitoringThread.cpp 
Log Message:
Add time stamps to log messages.



Index: SmartCardMonitoringThread.cpp
===================================================================
RCS file: /cvs/dirsec/esc/src/lib/coolkey/SmartCardMonitoringThread.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SmartCardMonitoringThread.cpp	27 Sep 2006 17:47:46 -0000	1.2
+++ SmartCardMonitoringThread.cpp	24 Feb 2007 02:22:04 -0000	1.3
@@ -28,213 +28,215 @@
 #include "SlotUtils.h"
 
 #include <assert.h>
+#include <time.h>
 
 static PRLogModuleInfo *coolKeyLogSC = PR_NewLogModule("coolKeySmart");
 
 SmartCardMonitoringThread::SmartCardMonitoringThread(SECMODModule *aModule)
   : mModule(aModule), mThread(NULL)
 {
-  PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
-            ("SmartCardMonitoringThread::SmartCardMonitoringThread : \n"));
+    char tBuff[56];
+    PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
+            ("%s SmartCardMonitoringThread::SmartCardMonitoringThread : \n",GetTStamp(tBuff,56)));
 }
 
 SmartCardMonitoringThread::~SmartCardMonitoringThread()
 {
-  PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
-          ("SmartCardMonitoringThread::~SmartCardMonitoringThread : \n"));
-  Stop();
+    char tBuff[56];
+    PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
+          ("%s SmartCardMonitoringThread::~SmartCardMonitoringThread : \n",GetTStamp(tBuff,56)));
+    Stop();
 }
 
 void SmartCardMonitoringThread::Start()
 {
-  PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
-          ("SmartCardMonitoringThread::Start : \n"));
+    char tBuff[56];
+    PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
+          ("%s SmartCardMonitoringThread::Start : \n",GetTStamp(tBuff,56)));
 
-  if (!mThread) {
-    mThread = PR_CreateThread(PR_SYSTEM_THREAD, LaunchExecute, this,
+    if (!mThread) {
+        mThread = PR_CreateThread(PR_SYSTEM_THREAD, LaunchExecute, this,
                               PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
                               PR_JOINABLE_THREAD, 0);
-  }
+    }
 }
 
 void SmartCardMonitoringThread::Stop()
 {
-  PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
-          ("SmartCardMonitoringThread::Stop : \n"));
+    char tBuff[56];
+    PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
+          ("%s SmartCardMonitoringThread::Stop : \n",GetTStamp(tBuff,56)));
 
-  Interrupt();
+    Interrupt();
 }
 
 void SmartCardMonitoringThread::Insert(PK11SlotInfo *aSlot)
 {
+    char tBuff[56];
+    PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
+          ("%s SmartCardMonitoringThread::Insert  Key. \n",GetTStamp(tBuff,56)));
 
-  PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
-          ("SmartCardMonitoringThread::Insert  Key. \n"));
-
-  CoolKeyInfo *info = CKHGetCoolKeyInfo(aSlot);
-  if (info) {
-    if (!InsertCoolKeyInfoIntoCoolKeyList(info)) {
-      AutoCoolKey key(eCKType_CoolKey, info->mCUID);
-      CoolKeyNotify(&key, eCKState_KeyInserted, 0);
-    } else {
-      delete info;
-    }
-  } 
+    CoolKeyInfo *info = CKHGetCoolKeyInfo(aSlot);
+    if (info) {
+        if (!InsertCoolKeyInfoIntoCoolKeyList(info)) {
+            AutoCoolKey key(eCKType_CoolKey, info->mCUID);
+            CoolKeyNotify(&key, eCKState_KeyInserted, 0);
+        } else {
+            delete info;
+        }
+    } 
 }
 
 void SmartCardMonitoringThread::Remove(CoolKeyInfo *info)
 {
-  PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
-          ("SmartCardMonitoringThread::Remove Key: \n"));
+    char tBuff[56];
+    PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
+          ("%s SmartCardMonitoringThread::Remove Key: \n",GetTStamp(tBuff,56)));
 
-  info->mInfoFlags = 0;
-  AutoCoolKey key(eCKType_CoolKey, info->mCUID);
-  CoolKeyNotify(&key, eCKState_KeyRemoved, 0);
-  RemoveCoolKeyInfoFromCoolKeyList(info);
+    info->mInfoFlags = 0;
+    AutoCoolKey key(eCKType_CoolKey, info->mCUID);
+    CoolKeyNotify(&key, eCKState_KeyRemoved, 0);
+    RemoveCoolKeyInfoFromCoolKeyList(info);
 }
 
 void SmartCardMonitoringThread::Execute()
 {
-  PK11SlotInfo *slot;
+    char tBuff[56];
+    PK11SlotInfo *slot;
 
-  PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
-         ("SmartCardMonitoringThread::Execute.\n"));
+    PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
+         ("%s SmartCardMonitoringThread::Execute.\n",GetTStamp(tBuff,56)));
   //
   // populate token names for already inserted tokens.
   //
-  PK11SlotList *sl =
+    PK11SlotList *sl =
 	PK11_FindSlotsByNames(mModule->dllName, NULL, NULL, PR_TRUE);
-  PK11SlotListElement *sle;
+    PK11SlotListElement *sle;
  
-  if (sl) {
+    if (sl) {
 
-    for (sle=PK11_GetFirstSafe(sl); sle; 
+        for (sle=PK11_GetFirstSafe(sl); sle; 
 				      sle=PK11_GetNextSafe(sl,sle,PR_FALSE)) {
-
-      Insert(sle->slot);
-
-      PK11_FreeSlot(sle->slot);
+            Insert(sle->slot);
+            PK11_FreeSlot(sle->slot);
+        }
+        PK11_FreeSlotList(sl);
     }
-    PK11_FreeSlotList(sl);
-  }
 
   // loop starts..
-  do {
-
-     PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
-            ("SmartCardMonitoringThread::Execute.Waiting for TokenEvent\n"));
-    slot = SECMOD_WaitForAnyTokenEvent(mModule, 0, PR_SecondsToInterval(1)  );
-
-
-    PR_LOG( coolKeyLogSC, PR_LOG_ALWAYS, 
-           ("SmartCard thread event detected. \n"));
-
-    if (slot == NULL) {
+    do {
 
-       PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
-              ("SmartCardMonitoringThread::Execute. slot is NULL\n"));
-      break;
-    }
+        PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
+            ("%s SmartCardMonitoringThread::Execute.Waiting for TokenEvent\n",GetTStamp(tBuff,56)));
+        slot = SECMOD_WaitForAnyTokenEvent(mModule, 0, PR_SecondsToInterval(1)  );
+        PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
+           ("%s SmartCard thread event detected. \n",GetTStamp(tBuff,56)));
+
+        if (slot == NULL) {
+
+            PR_LOG( coolKeyLogSC, PR_LOG_ERROR, 
+              ("%s SmartCard thread event detected, but the slot is NULL.\n",GetTStamp(tBuff,56)));
+            break;
+        }
 
     // now we have a potential insertion or removal event see if the slot
     // is present to determine which it is...
-    CoolKeyInfo *info = GetCoolKeyInfoBySlot(slot);
-
-    PR_LOG( coolKeyLogSC, PR_LOG_DEBUG,
-             ("SmartCardMonitoringThread::info %p : \n",info));
+        CoolKeyInfo *info = GetCoolKeyInfoBySlot(slot);
 
-    PRBool isPresent = PK11_IsPresent(slot);
+        PR_LOG( coolKeyLogSC, PR_LOG_DEBUG,
+             ("%s SmartCardMonitoringThread::info %p : \n",GetTStamp(tBuff,56),info));
 
+        PRBool isPresent = PK11_IsPresent(slot);
 
-    PR_LOG( coolKeyLogSC, PR_LOG_DEBUG,
-             ("SmartCardMonitoringThread::isPresent %d : \n",isPresent));
-
+        PR_LOG( coolKeyLogSC, PR_LOG_DEBUG,
+             ("%s SmartCardMonitoringThread::isPresent %d : \n",GetTStamp(tBuff,56),isPresent));
 
     /* if we think we have a token, but it's not the right one, or it's 
      * not there, then send a removal event */
-    if (info && (!isPresent || (info->mSeries != PK11_GetSlotSeries(slot))) ) {
+        if (info && (!isPresent || (info->mSeries != PK11_GetSlotSeries(slot))) ) {
 
-      PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
-             ("SmartCardMonitoringThread::Execute Token Removed : \n"));
+            PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
+             ("%s SmartCardMonitoringThread::Execute Token Removed : \n",GetTStamp(tBuff,56)));
 
-      Remove(info);
-      delete info;
-      info = NULL;
-    }
+            Remove(info);
+            delete info;
+            info = NULL;
+        }
     /* if the there is a token and we don't have info for it, send an 
      * insertion event */
-    if (isPresent && !info) {
+        if (isPresent && !info) {
 
-      PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
-             ("SmartCardMonitoringThread::Execute Token Inserted : \n"));
+            PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
+             ("%s SmartCardMonitoringThread::Execute Token Inserted : \n",GetTStamp(tBuff,56)));
 
-      Insert(slot);
-    }
-    PK11_FreeSlot(slot);
+           Insert(slot);
+        }
+        PK11_FreeSlot(slot);
 
-  } while (1);
+    } while (1);
 
 }
 
 void SmartCardMonitoringThread::Interrupt()
 {
-  PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
-         ("SmartCardMonitoringThread::Interrupt: mThread %p mModule %p\n",mThread,mModule));
+    char tBuff[56];
+    PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
+         ("%s SmartCardMonitoringThread::Interrupt: mThread %p mModule %p\n",GetTStamp(tBuff,56),mThread,mModule));
 
-  if(mThread)
-  {
-    SECStatus rv;
-    rv = SECMOD_CancelWait(mModule);
-    if (rv !=SECSuccess) {
-      PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
-              ("SmartCardMonitoringThread::Interrupt:"
+    if(mThread)
+    {
+        SECStatus rv;
+        rv = SECMOD_CancelWait(mModule);
+        if (rv !=SECSuccess) {
+            PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
+              ("%s SmartCardMonitoringThread::Interrupt:"
                " Can't join thread. result of CancelWait"
-               " %d error %d \n",rv,PORT_GetError()));
+               " %d error %d \n",GetTStamp(tBuff,56),rv,PORT_GetError()));
 
-      return; // don't hang if we couldn't wake up thread!!
-    }
-    PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
-           ("SmartCardMonitoringThread::Interrupt: "
-            "About to join smart card thread. \n"));
+           return; // don't hang if we couldn't wake up thread!!
+        }
+        PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
+           ("%s SmartCardMonitoringThread::Interrupt: "
+            "About to join smart card thread. \n",GetTStamp(tBuff,56)));
 
-    PRStatus rs = PR_JoinThread(mThread);
+        PRStatus rs = PR_JoinThread(mThread);
 
-    PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
-           ("SmartCardMonitoringThread::Interrupt: result"
-            " of PR_JoinThread %d error %d \n",rs,PORT_GetError()));
+        PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
+           ("%s SmartCardMonitoringThread::Interrupt: result"
+            " of PR_JoinThread %d error %d \n",GetTStamp(tBuff,56),rs,PORT_GetError()));
 
-    mThread = 0; 
-  }
+        mThread = 0; 
+    }
 
-  if(mModule)
-  {
-       PR_LOG( coolKeyLogSC, PR_LOG_DEBUG,
-           ("SmartCardMonitoringThread::Interrupt: about to unload  module"
+    if(mModule)
+    {
+         PR_LOG( coolKeyLogSC, PR_LOG_DEBUG,
+           ("%s SmartCardMonitoringThread::Interrupt: about to unload  module \n",GetTStamp(tBuff,56)
             ));
 
-       mModule = 0;
-  }
+         mModule = 0;
+    }
 }
 
 void SmartCardMonitoringThread::Release() {
+    char tBuff[56];
+    PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
+         ("%s SmartCardMonitoringThread::Release : \n",GetTStamp(tBuff,56)));
 
-  PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
-         ("SmartCardMonitoringThread::Release : \n"));
-
-  if (mCurrentActivation)
-    free(mCurrentActivation); 
+    if (mCurrentActivation)
+         free(mCurrentActivation); 
   
-  mCurrentActivation= NULL;
+    mCurrentActivation= NULL;
 }
 
 void SmartCardMonitoringThread::OnComplete() 
 {
+    char tBuff[56];
+    PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
+         ("%s SmartCardMonitoringThread::OnComplete : \n",GetTStamp(tBuff,56)));
 
-  PR_LOG( coolKeyLogSC, PR_LOG_DEBUG, 
-         ("SmartCardMonitoringThread::OnComplete : \n"));
-
-  AutoCoolKey key(eCKType_CoolKey, mCurrentActivation);
-  CoolKeyNotify(&key, eCKState_KeyInserted, 0);
+    AutoCoolKey key(eCKType_CoolKey, mCurrentActivation);
+    CoolKeyNotify(&key, eCKState_KeyInserted, 0);
 }
 
 void SmartCardMonitoringThread::OnDisconnect() {}
@@ -242,6 +244,5 @@
 
 void SmartCardMonitoringThread::LaunchExecute(void *arg)
 {
-  ((SmartCardMonitoringThread*)arg)->Execute();
+    ((SmartCardMonitoringThread*)arg)->Execute();
 }
-




More information about the Fedora-directory-commits mailing list