// ----------------------------------------------------------------------------
// CWmDrmDlaDefaultHttpManager::RunL
// Overrides CActive::RunL
// ----------------------------------------------------------------------------
void CWmDrmDlaDefaultHttpManager::RunL()
    {
    LOGFN( "CWmDrmDlaDefaultHttpManager::RunL" );
    TInt error( iStatus.Int() );
    LOG3( "CWmDrmDlaDefaultHttpManager State: %d Status: %d", iState, error );

    if ( iState == EOpen && error == KErrNotFound )
        {
        iState=EOpenFailed;
        }
    else
        {
        User::LeaveIfError( error );
        }

    switch (iState)
        {
        case EStart:
            InitializeL();
            break;
        case EInitialize:
            OpenL();
            break;
        case EOpenFailed: // Called only if open fails
            ReconnectL();
            break;
        case EReconnect:
            iState=EOpen;
            // Note: intentionally no break
            // Successfully completed EReconnect is same as EOpen.
        case EOpen:
            SubmitL();
            break;
        default:
            // Panic if called while in ESubmit
            ASSERT( 0 );
            break;
        }

    // Do not advance the state if the transaction was submitted
    // MHFRunL will be called by the HTTP stack while the transaction
    // progresses
    if ( iState != ESubmit )
        {
        // Go to the next state if not finished
        CompleteSelf();
        }
    }
void CBBSessionImpl::CheckedRunL()
{
	CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("CheckedRunL"));

	if (iStatus.Int() < KErrNone) {
		CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("err"));
		if (iStatus.Int()==KClientBufferTooSmall) {
			CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("toosmall"));
			iNotifyBuf->Des().Zero();
			iNotifyBuf=iNotifyBuf->ReAllocL(iNotifyBuf->Des().MaxLength()*2);
			iNotifyBufP.Set(iNotifyBuf->Des());
			iStatus=KRequestPending;
			SetActive();
			iClientSession.WaitForNotify(iFull, iNotifyBufP, iStatus);
			return;
		} else if(iStatus.Int()==KErrServerTerminated) {
			CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("terminated"));
			ReconnectL();
			return;
		} else {
			CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("other"));
			User::Leave(iStatus.Int());
		}
	}
	if (iStatus.Int() == EDeleteNotification) {
		CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("deleted"));
		NotifyDeletedL(iFull.iTupleName, iFull.iSubName);
	} else if (iNotifyBuf->Des().Length()>0) {
		{
			CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("read"));
			RDesReadStream rs(*iNotifyBuf);
			TTypeName tn;
			TInt err;
			MBBData* datap=0;
			CC_TRAP(err, tn=TTypeName::IdFromStreamL(rs));
			if (err!=KErrNone) {
				CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("err1"));
				TBBLongString* s=new (ELeave) TBBLongString(KEvent);
				datap=s;
				s->Value().Append(_L("error reading datatype: "));
				s->Value().AppendNum(err);
			}
			if (err==KErrNone) {
				CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("create"));
				CC_TRAP(err, datap=iFactory->CreateBBDataL(tn, KEvent, iFactory));
				if (err!=KErrNone) {
					CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("err2"));
					TBBLongString* s=new (ELeave) TBBLongString(KEvent);
					datap=s;
					s->Value().Append(_L("error creating data: "));
					s->Value().AppendNum(err);
					s->Value().Append(_L(", type: "));
					tn.IntoStringL(s->Value());
				}
			}
			refcounted_ptr<CRefCountedData> data(CRefCountedData::NewL(datap));
			if (err==KErrNone) {
				CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("internalize"));
				CC_TRAP(err, data->Get()->InternalizeL(rs));
				if (err!=KErrNone) {
					CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("err"));
					TBBLongString* s=new (ELeave) TBBLongString(KEvent);
					data.reset(CRefCountedData::NewL(s));
					s->Value().Append(_L("error internalizing data: "));
					s->Value().AppendNum(err);
					s->Value().Append(_L(", type: "));
					tn.IntoStringL(s->Value());
				}
			}
			{
			TNotifyType nt=EByTuple;
			if (iFull.iTupleType==ETuplePermanentSubscriptionEvent || 
				iFull.iTupleType==ETupleReply) {
					nt=EByComponent;
			}
			{
				CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("notify"));
				NotifyL(iFull.iId, iFull.iTupleName, iFull.iSubName, 
					iFull.iComponentName, data.get(), nt);
			}
			}
		}
	}

	{
		CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("next"));
		iNotifyBuf->Des().Zero();
		iNotifyBufP.Set(iNotifyBuf->Des());
		iStatus=KRequestPending;
		SetActive();
		iClientSession.WaitForNotify(iFull, iNotifyBufP, iStatus);
	}
}