Exemple #1
0
void AmsConnection::Recv()
{
    AmsTcpHeader amsTcpHeader;
    AoEHeader aoeHeader;
    for ( ; ownIp; ) {
        Receive(amsTcpHeader);
        if (amsTcpHeader.length() < sizeof(aoeHeader)) {
            LOG_WARN("Frame to short to be AoE");
            ReceiveJunk(amsTcpHeader.length());
            continue;
        }

        Receive(aoeHeader);
        if (aoeHeader.cmdId() == AoEHeader::DEVICE_NOTIFICATION) {
            ReceiveNotification(aoeHeader);
            continue;
        }

        auto response = GetPending(aoeHeader.invokeId(), aoeHeader.targetPort());
        if (!response) {
            LOG_WARN("No response pending");
            ReceiveJunk(aoeHeader.length());
            continue;
        }

        ReceiveFrame(response->frame, aoeHeader.length());

        switch (aoeHeader.cmdId()) {
        case AoEHeader::READ_DEVICE_INFO:
        case AoEHeader::READ:
        case AoEHeader::WRITE:
        case AoEHeader::READ_STATE:
        case AoEHeader::WRITE_CONTROL:
        case AoEHeader::ADD_DEVICE_NOTIFICATION:
        case AoEHeader::DEL_DEVICE_NOTIFICATION:
        case AoEHeader::READ_WRITE:
            break;

        default:
            LOG_WARN("Unkown AMS command id");
            response->frame.clear();
        }

        response->errorCode = aoeHeader.errorCode();
        response->Notify();
    }
}
// -----------------------------------------------------------------------------
// CConnMonEventHandler::ReceiveNotification
// Receives the new event from Connection Monitor server and passes it to the
// client interface.
// -----------------------------------------------------------------------------
//
void CConnMonEventHandler::RunL()
    {
    if ( KErrServerBusy == iStatus.Int() )
        {
        // Message slot was reserved
        // Try again
        LOGIT("Client [%d]: CConnMonEventHandler::RunL() KErrServerBusy, trying again")
        ReceiveNotification();
        }
    else if ( KErrNone == iStatus.Int() )
        {
        // A new event has arrived
        switch ( iEventInfo.iEventType )
            {
            case EConnMonCreateConnection :
                iConnMonEvent = new (ELeave) CConnMonCreateConnection(
                        iEventInfo.iConnectionId );
                break;

            case EConnMonDeleteConnection :
                iConnMonEvent = new (ELeave) CConnMonDeleteConnection(
                        iEventInfo.iConnectionId,
                        iEventInfo.iData,
                        iEventInfo.iData2,
                        iEventInfo.iData3 );
                break;

            case EConnMonDownlinkDataThreshold :
                iConnMonEvent = new (ELeave) CConnMonDownlinkDataThreshold(
                        iEventInfo.iConnectionId,
                        iEventInfo.iSubConnectionId,
                        iEventInfo.iData );
                break;

            case EConnMonUplinkDataThreshold :
                iConnMonEvent = new (ELeave) CConnMonUplinkDataThreshold(
                        iEventInfo.iConnectionId,
                        iEventInfo.iSubConnectionId,
                        iEventInfo.iData );
                break;

            case EConnMonNetworkStatusChange :
                iConnMonEvent = new (ELeave) CConnMonNetworkStatusChange(
                        iEventInfo.iConnectionId,
                        iEventInfo.iData );
                break;

            case EConnMonConnectionStatusChange :
                iConnMonEvent = new (ELeave) CConnMonConnectionStatusChange(
                        iEventInfo.iConnectionId,
                        iEventInfo.iSubConnectionId,
                        iEventInfo.iData );
                break;

            case EConnMonConnectionActivityChange :
                iConnMonEvent = new (ELeave) CConnMonConnectionActivityChange(
                        iEventInfo.iConnectionId,
                        iEventInfo.iSubConnectionId,
                        iEventInfo.iData );
                break;

            case EConnMonNetworkRegistrationChange :
                iConnMonEvent = new (ELeave) CConnMonNetworkRegistrationChange(
                        iEventInfo.iConnectionId,
                        iEventInfo.iData );
                break;

            case EConnMonBearerChange :
                iConnMonEvent = new (ELeave) CConnMonBearerChange(
                        iEventInfo.iConnectionId,
                        iEventInfo.iData );
                break;

            case EConnMonSignalStrengthChange :
                iConnMonEvent = new (ELeave) CConnMonSignalStrengthChange(
                        iEventInfo.iConnectionId,
                        iEventInfo.iData );
                break;

            case EConnMonBearerAvailabilityChange :
                iConnMonEvent = new (ELeave) CConnMonBearerAvailabilityChange(
                        iEventInfo.iConnectionId,
                        iEventInfo.iData );
                break;

            case EConnMonIapAvailabilityChange :
                iConnMonEvent = new (ELeave) CConnMonIapAvailabilityChange(
                        iEventInfo.iConnectionId,
                        reinterpret_cast<const TConnMonIapInfo*>( iExtraBuf.Ptr() ) );
                break;

            case EConnMonTransmitPowerChange :
                iConnMonEvent = new (ELeave) CConnMonTransmitPowerChange(
                        iEventInfo.iConnectionId,
                        iEventInfo.iData );
                break;

            case EConnMonSNAPsAvailabilityChange :
                iConnMonEvent = new (ELeave) CConnMonSNAPsAvailabilityChange(
                        iEventInfo.iConnectionId, iEventInfo.iData,
                        reinterpret_cast< const TConnMonSNAPInfo* >( iExtraBuf.Ptr() ) );
                break;

            case EConnMonNewWLANNetworkDetected :
                iConnMonEvent = new (ELeave) CConnMonNewWLANNetworkDetected(
                        iEventInfo.iConnectionId );
                break;

            case EConnMonOldWLANNetworkLost :
                iConnMonEvent = new (ELeave) CConnMonOldWLANNetworkLost(
                        iEventInfo.iConnectionId );
                break;

            case EConnMonPacketDataUnavailable :
                iConnMonEvent = new (ELeave) CConnMonPacketDataUnavailable(
                        iEventInfo.iConnectionId );
                break;

            case EConnMonPacketDataAvailable :
                iConnMonEvent = new (ELeave) CConnMonPacketDataAvailable(
                        iEventInfo.iConnectionId );
                break;

            case EConnMonBearerInfoChange :
                iConnMonEvent = new (ELeave) CConnMonBearerInfoChange(
                        iEventInfo.iConnectionId,
                        iEventInfo.iData );
                break;

            case EConnMonBearerGroupChange :
                iConnMonEvent = new (ELeave) CConnMonBearerGroupChange(
                        iEventInfo.iConnectionId,
                        iEventInfo.iData2,
                        iEventInfo.iData3,
                        iEventInfo.iData );
                break;

            default:
                if ( iEventInfo.iEventType >= EConnMonPluginEventBase )
                    {
                    // Size of the data is in 'iEventInfo.iData2'
                    iConnMonEvent = new (ELeave) CConnMonGenericEvent(
                            iEventInfo.iEventType,
                            iEventInfo.iConnectionId,
                            reinterpret_cast<TAny*>( &( iEventInfo.iData ) ) );
                    }
                else
                    {
                    iConnMonEvent = new (ELeave) CConnMonEventBase(
                            iEventInfo.iEventType,
                            iEventInfo.iConnectionId );
                    }
            }

        // Deliver the event to client handler
        TRAPD( leaveCode,
                iObserver->EventL( reinterpret_cast<CConnMonEventBase&>( *iConnMonEvent ) ) );

        delete iConnMonEvent;
        iConnMonEvent = NULL;

        LOGIT6("Client [%d]: GOT EVENT: type %d, id %d, data1 %d, data2 %d, data3 %d",
                &iSession,
                iEventInfo.iEventType,
                iEventInfo.iConnectionId,
                iEventInfo.iData,
                iEventInfo.iData2,
                iEventInfo.iData3 )

        // Initiate the next receive
        ReceiveNotification();

        // If leave occurs in EventL, log and ignore
        if ( leaveCode )
            {
            LOGIT2("Client [%d]: CConnMonEventHandler::RunL() iObserver->EventL() call left <%d>",
                    &iSession, leaveCode)
            }
        }
    else
        {
// -----------------------------------------------------------------------------
// CConnMonEventHandler::Continue
// Continues receiving events.
// -----------------------------------------------------------------------------
//
void CConnMonEventHandler::Continue( MConnectionMonitorObserver* aObserver )
    {
    iPause = EFalse;
    iObserver = aObserver;
    ReceiveNotification();
    }