Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
SmartCardMonitoringThread Class Reference

#include <nsSmartCardMonitor.h>

Collaboration diagram for SmartCardMonitoringThread:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 SmartCardMonitoringThread (SECMODModule *module)
 ~SmartCardMonitoringThread ()
nsresult Start ()
void Stop ()
void Execute ()
void Interrupt ()
const SECMODModule * GetModule ()

Private Member Functions

void SetTokenName (CK_SLOT_ID slotid, const char *tokenName, PRUint32 series)
const char * GetTokenName (CK_SLOT_ID slotid)
PRUint32 GetTokenSeries (CK_SLOT_ID slotid)
nsresult SendEvent (const nsAString &type, const char *tokenName)

Static Private Member Functions

static void LaunchExecute (void *arg)

Private Attributes

SECMODModule * mModule
PLHashTablemHash
PRThreadmThread

Detailed Description

Definition at line 66 of file nsSmartCardMonitor.h.


Constructor & Destructor Documentation

Definition at line 136 of file nsSmartCardMonitor.cpp.

  : mThread(nsnull)
{
  mModule = SECMOD_ReferenceModule(module_);
  // simple hash functions, most modules have less than 3 slots, so 10 buckets
  // should be plenty
  mHash = PL_NewHashTable(10, unity, PL_CompareValues, 
                           PL_CompareStrings, nsnull, 0);
}

Here is the call graph for this function:

Definition at line 150 of file nsSmartCardMonitor.cpp.

Here is the call graph for this function:


Member Function Documentation

Definition at line 282 of file nsSmartCardMonitor.cpp.

{
  PK11SlotInfo *slot;
  const char *tokenName = nsnull;

  //
  // populate token names for already inserted tokens.
  //
  PK11SlotList *sl =
            PK11_FindSlotsByNames(mModule->dllName, nsnull, nsnull, PR_TRUE);
  PK11SlotListElement *sle;
 
  if (sl) {
    for (sle=PK11_GetFirstSafe(sl); sle; 
                                      sle=PK11_GetNextSafe(sl,sle,PR_FALSE)) {
      SetTokenName(PK11_GetSlotID(sle->slot), 
                  PK11_GetTokenName(sle->slot), PK11_GetSlotSeries(sle->slot));
    }
    PK11_FreeSlotList(sl);
  }

  // loop starts..
  do {
    slot = SECMOD_WaitForAnyTokenEvent(mModule, 0, PR_SecondsToInterval(1)  );
    if (slot == nsnull) {
      break;
    }

    // now we have a potential insertion or removal event, see if the slot
    // is present to determine which it is...
    if (PK11_IsPresent(slot)) {
      // insertion
      CK_SLOT_ID slotID = PK11_GetSlotID(slot);
      PRUint32 series = PK11_GetSlotSeries(slot);

      // skip spurious insertion events...
      if (series != GetTokenSeries(slotID)) {
        // if there's a token name, then we have not yet issued a remove
        // event for the previous token, do so now...
        tokenName = GetTokenName(slotID);
        if (tokenName) {
          SendEvent(NS_LITERAL_STRING(SMARTCARDEVENT_REMOVE), tokenName);
        }
        tokenName = PK11_GetTokenName(slot);
        // save the token name and series
        SetTokenName(slotID, tokenName, series);
        SendEvent(NS_LITERAL_STRING(SMARTCARDEVENT_INSERT), tokenName);
      }
    } else {
      // retrieve token name 
      CK_SLOT_ID slotID = PK11_GetSlotID(slot);
      tokenName = GetTokenName(slotID);
      // if there's not a token name, then the software isn't expecting
      // a (or another) remove event.
      if (tokenName) {
        SendEvent(NS_LITERAL_STRING(SMARTCARDEVENT_REMOVE), tokenName);
        // clear the token name (after we send it)
        SetTokenName(slotID, nsnull, 0);
      }
    }
    PK11_FreeSlot(slot);

  } while (1);
}

Here is the call graph for this function:

Definition at line 348 of file nsSmartCardMonitor.cpp.

{
  return mModule;
}

Here is the caller graph for this function:

Definition at line 231 of file nsSmartCardMonitor.cpp.

{
  const char *tokenName = nsnull;
  const char *entry;

  if (mHash) {
    entry = (const char *)PL_HashTableLookupConst(mHash,(void *)slotid);
    if (entry) {
      tokenName = &entry[sizeof(PRUint32)];
    }
  }
  return tokenName;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 247 of file nsSmartCardMonitor.cpp.

{
  PRUint32 series = 0;
  const char *entry;

  if (mHash) {
    entry = (const char *)PL_HashTableLookupConst(mHash,(void *)slotid);
    if (entry) {
      memcpy(&series,entry,sizeof(PRUint32));
    }
  }
  return series;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void SmartCardMonitoringThread::LaunchExecute ( void arg) [static, private]

Definition at line 354 of file nsSmartCardMonitor.cpp.

{
  ((SmartCardMonitoringThread*)arg)->Execute();
}

Here is the caller graph for this function:

nsresult SmartCardMonitoringThread::SendEvent ( const nsAString &  type,
const char *  tokenName 
) [private]

Definition at line 265 of file nsSmartCardMonitor.cpp.

{
  nsresult rv;
  nsCOMPtr<nsINSSComponent> 
                    nssComponent(do_GetService(kNSSComponentCID, &rv));
  if (NS_FAILED(rv))
    return rv;

  // NSS returns actual UTF8, not ASCII
  nssComponent->PostEvent(eventType, NS_ConvertUTF8toUTF16(tokenName));
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void SmartCardMonitoringThread::SetTokenName ( CK_SLOT_ID  slotid,
const char *  tokenName,
PRUint32  series 
) [private]

Definition at line 208 of file nsSmartCardMonitor.cpp.

{
  if (mHash) {
    if (tokenName) {
      int len = strlen(tokenName) + 1;
      char *entry = (char *)malloc(len+sizeof(PRUint32));
     
      if (entry) {  
        memcpy(entry,&series,sizeof(PRUint32));
        memcpy(&entry[sizeof(PRUint32)],tokenName,len);

        PL_HashTableAdd(mHash,(void *)slotid, entry); /* adopt */
        return;
      }
    } 
    // if tokenName was not provided, remove the old one (implicit delete)
    PL_HashTableRemove(mHash,(void *)slotid);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 160 of file nsSmartCardMonitor.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 176 of file nsSmartCardMonitor.cpp.

{
  SECStatus rv;

  rv = SECMOD_CancelWait(mModule);
  if (rv != SECSuccess) {
    // we didn't wake up the Wait, so don't try to join the thread 
    // otherwise we will hang forever...
    return;
  }
 
  // confused about the memory model here? NSPR owns the memory for
  // threads. non-joinable threads are freed when the thread dies.
  // joinable threads are freed after the call to PR_JoinThread.
  // That means if SECMOD_CancelWait fails, we'll leak the mThread
  // structure. this is considered preferable to hanging (which is
  // what will happen if we try to join a thread that blocked).
  if (mThread) {
    PR_JoinThread(mThread);
    mThread = 0; 
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 90 of file nsSmartCardMonitor.h.

SECMODModule* SmartCardMonitoringThread::mModule [private]

Definition at line 89 of file nsSmartCardMonitor.h.

Definition at line 91 of file nsSmartCardMonitor.h.


The documentation for this class was generated from the following files: