PCSC那事儿(十三--SCardListReaderGroups)

 

SCardListReaderGroups

实现在 winscard_clnt.c

定义如下:

3395 LONG SCardListReaderGroups(SCARDCONTEXT hContext, LPSTR mszGroups,

3396         LPDWORD pcchGroups)

3397 {

3398         LONG rv = SCARD_S_SUCCESS;

3399         LONG dwContextIndex;

3400         char *buf = NULL;

3401

3402         PROFILE_START

3403

3404         /* Multi-string with two trailing /0 */

3405         const char ReaderGroup[] = "SCard$DefaultReaders/0";

3406          const int dwGroups = sizeof(ReaderGroup);

3407

3408         rv = SCardCheckDaemonAvailability();

3409         if (rv != SCARD_S_SUCCESS)

3410                 return rv;

3411

3412         /*

3413          * Make sure this context has been opened

3414           */

3415         dwContextIndex = SCardGetContextIndice(hContext);

3416         if (dwContextIndex == -1)

3417                 return SCARD_E_INVALID_HANDLE;

3418

3419         (void)SYS_MutexLock(psContextMap[dwContextIndex].mMutex);

3420

3421          /* check the context is still opened */

3422         dwContextIndex = SCardGetContextIndice(hContext);

3423         if (dwContextIndex == -1)

3424                 /* the context is now invalid

3425                  * -> another thread may have called SCardReleaseContext

3426                  * -> so the mMutex has been unlocked */

3427                 return SCARD_E_INVALID_HANDLE;

3428

3429         if (SCARD_AUTOALLOCATE == *pcchGroups)

3430         {

3431                 buf = malloc(dwGroups);

3432                  if (NULL == buf)

 

3433                 {

3434                         rv = SCARD_E_NO_MEMORY;

3435                         goto end;

3436                 }

3437                 if (NULL == mszGroups)

3438                 {

3439                          rv = SCARD_E_INVALID_PARAMETER;

3440                         goto end;

3441                 }

3442                 *(char **)mszGroups = buf;

3443         }

3444         else

3445         {

3446                 buf = mszGroups;

3447

3448                  if ((NULL != mszGroups) && (*pcchGroups < dwGroups))

3449                 {

3450                         rv = SCARD_E_INSUFFICIENT_BUFFER;

3451                         goto end;

3452                 }

3453         }

3454

 

3455         if (buf)

3456                 memcpy(buf, ReaderGroup, dwGroups);

3457

3458 end:

3459         *pcchGroups = dwGroups;

3460

3461         (void)SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);

3462

3463         PROFILE_END(rv)

3464

3465         return rv;

3466 }

 

 

先说明下, SCardListReaderGroups 调用成功, mszGroups 将返回类似

"SCard$DefaultReaders//0Group 2//0//0" 的多字符串。最后有两个 0.

 

3408 行, SCardCheckDaemonAvailability 做什么,不说了。上面提了 n 次了。

如果表示震撼,说明了需要重新来过。

 

3415~3427 说明了什么。 SCardGetContextIndice 在前面解释了。重复检查两次,

原因正如注释所说的, SYS_MutexLock 之前,如果 SCardReleaseContext 发生了。

则世界改变了。 Don't panic.

Take it easy.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值