Logo Search packages:      
Sourcecode: pcsc-lite version File versions  Download package

LONG SCardBeginTransaction ( SCARDHANDLE  hCard )

Establishes a temporary exclusive access mode for doing a serie of commands in a transaction.

You might want to use this when you are selecting a few files and then writing a large file so you can make sure that another application will not change the current file. If another application has a lock on this reader or this application is in SCARD_SHARE_EXCLUSIVE there will be no action taken.

Parameters:
[in]hCardConnection made from SCardConnect().
Returns:
Error code.
Return values:
SCARD_S_SUCCESSSuccessful (SCARD_S_SUCCESS)
SCARD_E_INVALID_HANDLEInvalid hCard handle (SCARD_E_INVALID_HANDLE)
SCARD_E_NO_SERVICEThe server is not runing (SCARD_E_NO_SERVICE)
SCARD_E_READER_UNAVAILABLEThe reader has been removed (SCARD_E_READER_UNAVAILABLE)
SCARD_E_SHARING_VIOLATIONSomeone else has exclusive rights (SCARD_E_SHARING_VIOLATION)
SCARD_F_COMM_ERRORAn internal communications error has been detected (SCARD_F_COMM_ERROR)
 SCARDCONTEXT hContext;
 SCARDHANDLE hCard;
 DWORD dwActiveProtocol;
 LONG rv;
 ...
 rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
 rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED,
          SCARD_PROTOCOL_T0, &hCard, &dwActiveProtocol);
 rv = SCardBeginTransaction(hCard);
 ...
 / * Do some transmit commands * /

Definition at line 1231 of file winscard_clnt.c.

References MessageReceive(), MessageSendWithHeader(), PCSCLITE_LOCK_POLL_RATE, SCARD_BEGIN_TRANSACTION, SCARD_E_INVALID_HANDLE, SCARD_E_SHARING_VIOLATION, SCARD_S_SUCCESS, and SYS_USleep().

{

      LONG rv;
      struct begin_struct scBeginStruct;
      SCONTEXTMAP * currentContextMap;
      CHANNEL_MAP * pChannelMap;

      PROFILE_START

      CHECK_SAME_PROCESS

      /*
       * Make sure this handle has been opened
       */
      rv = SCardGetContextAndChannelFromHandle(hCard, &currentContextMap,
            &pChannelMap);
      if (rv == -1)
            return SCARD_E_INVALID_HANDLE;

      (void)pthread_mutex_lock(currentContextMap->mMutex);

      /* check the handle is still valid */
      rv = SCardGetContextAndChannelFromHandle(hCard, &currentContextMap,
            &pChannelMap);
      if (rv == -1)
            /* the handle is now invalid
             * -> another thread may have called SCardReleaseContext
             * -> so the mMutex has been unlocked */
            return SCARD_E_INVALID_HANDLE;

      scBeginStruct.hCard = hCard;
      scBeginStruct.rv = SCARD_S_SUCCESS;

      /*
       * Query the server every so often until the sharing violation ends
       * and then hold the lock for yourself.
       */

      do
      {
            rv = MessageSendWithHeader(SCARD_BEGIN_TRANSACTION,
                  currentContextMap->dwClientID,
                  sizeof(scBeginStruct), (void *) &scBeginStruct);

            if (rv != SCARD_S_SUCCESS)
                  goto end;

            /*
             * Read a message from the server
             */
            rv = MessageReceive(&scBeginStruct, sizeof(scBeginStruct),
                  currentContextMap->dwClientID);

            if (rv != SCARD_S_SUCCESS)
                  goto end;

            rv = scBeginStruct.rv;
      }
      while (SCARD_E_SHARING_VIOLATION == rv);

end:
      (void)pthread_mutex_unlock(currentContextMap->mMutex);

    PROFILE_END(rv)

      return rv;
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index