[PATCH 3/4] SlotList::waitForSlotEvent: use \\?PnP?\Notification

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 src/coolkey/slot.cpp |   23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/src/coolkey/slot.cpp b/src/coolkey/slot.cpp
index a5f550b..d0fa41d 100644
--- a/src/coolkey/slot.cpp
+++ b/src/coolkey/slot.cpp
@@ -1228,22 +1228,23 @@ SlotList::waitForSlotEvent(CK_FLAGS flag, CK_SLOT_ID_PTR slotp, CK_VOID_PTR res)
 	    throw;
 	}
 
-	if (myNumReaders != numReaders) {
+	if (myNumReaders != numReaders + 1) {
 	    if (myReaderStates) {
 		delete [] myReaderStates;
 	    } 
-	    myReaderStates = new SCARD_READERSTATE [numReaders];
+	    myReaderStates = new SCARD_READERSTATE [numReaders + 1];
+            myNumReaders = numReaders + 1;
 	}
-	memcpy(myReaderStates, readerStates, 
-				sizeof(SCARD_READERSTATE)*numReaders);
-	myNumReaders = numReaders;
+	memcpy(myReaderStates, readerStates,
+				sizeof(SCARD_READERSTATE) * numReaders);
+        myReaderStates[numReaders].szReader = "\\\\?PnP?\\Notification";
+        myReaderStates[numReaders].dwCurrentState = SCARD_STATE_UNAWARE;
 	readerListLock.releaseLock();
 	status = CKYCardContext_WaitForStatusChange(context,
 				 myReaderStates, myNumReaders, timeout);
 	if (status == CKYSUCCESS) {
-	    for (i=0; i < myNumReaders; i++) {
-		SCARD_READERSTATE *rsp = &myReaderStates[i];
-	        unsigned long eventState = CKYReader_GetEventState(rsp);
+	    for (i=0; i < myNumReaders - 1; i++) {
+                unsigned long eventState = CKYReader_GetEventState(&myReaderStates[i]);
 		if (eventState & SCARD_STATE_CHANGED) {
 		    readerListLock.getLock();
 		    CKYReader_SetKnownState(&readerStates[i], eventState & ~SCARD_STATE_CHANGED);
@@ -1253,6 +1254,12 @@ SlotList::waitForSlotEvent(CK_FLAGS flag, CK_SLOT_ID_PTR slotp, CK_VOID_PTR res)
 		    break;
 		}
 	    }
+            /* No real need to check for an additional card, we already update the
+             * list when we iterate. */
+            if (CKYReader_GetEventState(&myReaderStates[myNumReaders - 1])
+                    & SCARD_STATE_CHANGED) {
+                log->log("Reader insertion/removal detected\n");
+            }
 	}
 
         if (found || (flag == CKF_DONT_BLOCK) || shuttingDown) {
-- 
1.7.9.3

_______________________________________________
Coolkey-devel mailing list
Coolkey-devel@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/coolkey-devel


[Index of Archives]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Women]

  Powered by Linux