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

static void ContextThread ( LPVOID  dwIndex  )  [static]

Handles messages received from Clients.

For each Client message a new instance of this thread is created.

Parameters:
[in] dwIndex Index of an avaiable Application Context slot in psContext.

Definition at line 125 of file winscard_svc.c.

References rxSharedSegment::command, rxSharedSegment::data, version_struct::major, version_struct::minor, MSGFunctionDemarshall(), rxSharedSegment::mtype, PCSCLITE_SERVER_ATTEMPTS, _psContext::protocol_major, _psContext::protocol_minor, PROTOCOL_VERSION_MAJOR, PROTOCOL_VERSION_MINOR, psContext, version_struct::rv, SHMMessageSend(), and SHMProcessEventsContext().

Referenced by CreateContextThread().

{
      LONG rv;
      sharedSegmentMsg msgStruct;
      DWORD dwContextIndex = (DWORD)dwIndex;

      Log2(PCSC_LOG_DEBUG, "Thread is started: %d",
            psContext[dwContextIndex].dwClientID);
      
      while (1)
      {
            switch (rv = SHMProcessEventsContext(&psContext[dwContextIndex].dwClientID, &msgStruct, 0))
            {
            case 0:
                  if (msgStruct.mtype == CMD_CLIENT_DIED)
                  {
                        /*
                         * Clean up the dead client
                         */
                        Log2(PCSC_LOG_DEBUG, "Client die: %d",
                              psContext[dwContextIndex].dwClientID);
                        MSGCleanupClient(dwContextIndex);
                        SYS_ThreadExit((LPVOID) NULL);
                  } 
                  break;

            case 1:
                  if (msgStruct.mtype == CMD_FUNCTION)
                  {
                        /*
                         * Command must be found
                         */
                        MSGFunctionDemarshall(&msgStruct, dwContextIndex);

                        /* the SCARD_TRANSMIT_EXTENDED anwser is already sent by
                         * MSGFunctionDemarshall */
                        if (msgStruct.command != SCARD_TRANSMIT_EXTENDED)
                              rv = SHMMessageSend(&msgStruct, sizeof(msgStruct),
                                    psContext[dwContextIndex].dwClientID,
                                    PCSCLITE_SERVER_ATTEMPTS);
                  }
                  else
                        /* pcsc-lite client/server protocol version */
                        if (msgStruct.mtype == CMD_VERSION)
                        {
                              version_struct *veStr;
                              veStr = (version_struct *) msgStruct.data;

                              /* get the client protocol version */
                              psContext[dwContextIndex].protocol_major = veStr->major;
                              psContext[dwContextIndex].protocol_minor = veStr->minor;

                              Log3(PCSC_LOG_DEBUG,
                                    "Client is protocol version %d:%d",
                                    veStr->major, veStr->minor);

                              /* set the server protocol version */
                              veStr->major = PROTOCOL_VERSION_MAJOR;
                              veStr->minor = PROTOCOL_VERSION_MINOR;
                              veStr->rv = SCARD_S_SUCCESS;

                              /* send back the response */
                              rv = SHMMessageSend(&msgStruct, sizeof(msgStruct),
                                    psContext[dwContextIndex].dwClientID,
                                  PCSCLITE_SERVER_ATTEMPTS);
                        }
                        else
                              continue;

                  break;

            case 2:
                  /*
                   * timeout in SHMProcessEventsContext(): do nothing
                   * this is used to catch the Ctrl-C signal at some time when
                   * nothing else happens
                   */
                  break;
                  
            case -1:
                  Log1(PCSC_LOG_ERROR, "Error in SHMProcessEventsContext");
                  break;
                  
            default:
                  Log2(PCSC_LOG_ERROR,
                        "SHMProcessEventsContext unknown retval: %d", rv);
                  break;
            }
      }
}


Generated by  Doxygen 1.6.0   Back to index