Esempio n. 1
0
tCardStatus CReader::Status(bool bReconnect)
{
	tCardStatus status;
	static int iStatusCount = 0;

	if (m_poCard == NULL)
	{
		if (m_poContext->m_oPCSC.Status(m_csReader)){
			status = Connect() ? CARD_INSERTED : CARD_NOT_PRESENT;
		}
		else
			status = CARD_NOT_PRESENT;
	}
	else
	{
		bool bCardStillPresent = m_poCard->Status();
		if (bCardStillPresent){
			status = CARD_STILL_PRESENT;
		}else
		{	
			Disconnect();
			// if bReconnect = true, then we try to connect to a
			// possibly new card that has been inserted
			if (bReconnect && m_poContext->m_oPCSC.Status(m_csReader))
				status = Connect() ? CARD_OTHER : CARD_REMOVED;
			else
				status = CARD_REMOVED;
		}
	}

	if (iStatusCount < 5)
	{
		MWLOG(LEV_DEBUG, MOD_CAL, L"    ReaderStatus(): %ls", Status2String(status));
		iStatusCount++;
	}

	return status;
}
Esempio n. 2
0
/********************************************************************************************
 * OpenChannel
 * purpose : Open an outgoing channel
 * input   : Call           - Call to associate with the channel
 *           MediaType      - Type of media to use for the channel
 *           DataType       - Data type parameter for the channel
 *           MimicChannel   - Pointer of a channel we mimic. NULL if not mimicing
 *           ReplaceChannel - Pointer of a channel we replace. NULL not replacing
 * output  : none
 * return  : TCL_OK on success
 ********************************************************************************************/
int OpenChannel(CallInfo *    Call,
                char *        DataType,
                ChannelInfo * MimicChannel,
                ChannelInfo * ReplaceChannel)
{
    ChannelInfo*       NewChan;
    int                status;

    /* Make sure we're not in an endless loop of mimicing channels */
    if (MimicChannel != NULL)
    {
        HAPPCHAN haSameSession = NULL;
        HCHAN hsSameSession = NULL;
        cmChannelSameSession(MimicChannel->hChan, &haSameSession, &hsSameSession);
        if(haSameSession != NULL) return 0;
    }

    /* Increase the number of channels for this call */
    NewChan = ChannelCreate(NULL, TRUE, FALSE, Call);

    /* Create and open channel */
    status = cmChannelNew(Call->hsCall, (HAPPCHAN) NewChan, (LPHCHAN)&NewChan->hChan);

    if (status >= 0)
    {
        /* See if we're mimicing this channel */
        if (MimicChannel == NULL)
        {
            /* Open an RTP session for this channel */
            if(Call->action == RTP_Replay)
                NewChan->rtpSession = RTP_TestOpen("testChannel");
            if (ReplaceChannel != NULL)
                cmChannelReplace(NewChan->hChan, ReplaceChannel->hChan);
        }
        else
        {
            /* Channel is mimiced */
            NewChan->rtpSession = MimicChannel->rtpSession;
            RTP_TestSetAction(NewChan->rtpSession, Call->action);
            RTP_TestOpenSecondChannel(NewChan->rtpSession);
        }

        /* set RTCP address  and open the channel*/
        if (DataType[0] == 't')
        {
            /* Data channel (Duplex) */
            cmTransportAddress ta={0,0x0e2472c0,(UINT16)1503/*port*/,cmTransportTypeIP};
            cmChannelDuplex(NewChan->hChan);
            cmChannelSetDuplexAddress(NewChan->hChan,ta,1,(char *)"1",FALSE);
        }
        else
            cmChannelSetRTCPAddress(NewChan->hChan, 0,
                (UINT16) (RTP_TestGetLocalPort(NewChan->rtpSession) + 1));
        
        /* set data type */
        strncpy(NewChan->dataType, DataType, sizeof(NewChan->dataType));

        if (MimicChannel)
        {
            if (MimicChannel->dynPayloadType != 0)
                cmChannelSetDynamicRTPPayloadType(NewChan->hChan, MimicChannel->dynPayloadType);

            /* Since this is a mimiced channel, we'll open it in exactly the same manner as the original channel */
            status = cmChannelOpenDynamic(NewChan->hChan, MimicChannel->dataTypeNode, MimicChannel->hChan, NULL, FALSE);
        }
        else
            status = cmChannelOpen(NewChan->hChan, DataType, NULL, NULL, 0);
        
        TclExecute("call:Log %d {ChannelOpen. result=%s}", Call->counter, Status2String(status));
    }
    else
    {
        FreeChannel(NewChan);
        TclExecute("call:Log %d {ChannelNew. result=%s}", Call->counter, Status2String(status));
    }

    /* Add the new channel to the channels list on the main window */
    return DisplayChannelList(Call, NULL);
}