videofeeds/clientapi/src/CIptvMyVideosContentUpdateObserver.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Tue, 14 Sep 2010 21:23:06 +0300
branchRCL_3
changeset 24 f87e8c4ac026
parent 0 96612d01cf9f
permissions -rw-r--r--
Revision: 201033 Kit: 201035

/*
* Copyright (c) 2006-2008 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of the License "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:    Observer for content updates from server.*
*/




#include <e32base.h>
#include <s32mem.h>
#include "IptvDebug.h"

#include "IptvClientServerCommon.h"
#include "RIptvClientSession.h"
#include "CIptvMyVideosContentUpdateObserver.h"
#include "MIptvMyVideosClientObserver.h"

// ======== MEMBER FUNCTIONS ========

// ---------------------------------------------------------------------------
// CIptvMyVideosContentUpdateObserver::CIptvMyVideosContentUpdateObserver()
// ---------------------------------------------------------------------------
//
CIptvMyVideosContentUpdateObserver::CIptvMyVideosContentUpdateObserver(
    MIptvMyVideosClientObserver& aClientObserver,
    RIptvClientSession& aSession )
 :  CActive( EPriorityStandard ),
    iClientObserver( aClientObserver ),
    iSession( aSession ),
    iObserverMsgPtr( static_cast<unsigned char*>( 0 ), 0 )
    {
    CActiveScheduler::Add( this );
    }

// ---------------------------------------------------------------------------
// CIptvMyVideosContentUpdateObserver::NewL()
// ---------------------------------------------------------------------------
//
CIptvMyVideosContentUpdateObserver* CIptvMyVideosContentUpdateObserver::NewL(
    MIptvMyVideosClientObserver& aClientObserver,
    RIptvClientSession& aSession )
    {
    CIptvMyVideosContentUpdateObserver* self =
        new ( ELeave ) CIptvMyVideosContentUpdateObserver(
            aClientObserver, aSession );
    CleanupStack::PushL( self );
    self->ConstructL();
    CleanupStack::Pop( self );
    return self;
    }

// ---------------------------------------------------------------------------
// CIptvMyVideosContentUpdateObserver::ConstructL()
// ---------------------------------------------------------------------------
//
void CIptvMyVideosContentUpdateObserver::ConstructL()
    {
    SendObserverRequestL();
    SetActive();
    }

// ---------------------------------------------------------------------------
// CIptvMyVideosContentUpdateObserver::~CIptvMyVideosContentUpdateObserver()
// ---------------------------------------------------------------------------
//
CIptvMyVideosContentUpdateObserver::~CIptvMyVideosContentUpdateObserver()
    {
    delete iObserverMsg;
    Cancel();
    }

// ---------------------------------------------------------------------------
// CIptvMyVideosContentUpdateObserver::RunL()
// ---------------------------------------------------------------------------
//
void CIptvMyVideosContentUpdateObserver::RunL()
    {
    if ( iStatus.Int() == KErrNone )
        {
        MIptvMyVideosClientObserver::TIptvContentUpdatedEvent event;

        RDesReadStream stream;
        stream.Open( iObserverMsgPtr );
        CleanupClosePushL( stream );

        event.iEventType = static_cast<MIptvMyVideosClientObserver::TIptvContentUpdatedEventType>
            ( stream.ReadUint32L() );
        event.iDrive = stream.ReadUint32L();
        event.iFileId = stream.ReadUint32L();
        CleanupStack::PopAndDestroy( &stream );

        iClientObserver.ContentsUpdated( event );

        // Only set active if previous completed without error. Otherwise
        // we make eternal loop; client sending new messages and server
        // completing them instantly with error.
        SendObserverRequestL();
        SetActive();
        }
    }

// ---------------------------------------------------------------------------
// CIptvMyVideosContentUpdateObserver::SendObserverRequestL
// ---------------------------------------------------------------------------
//
void CIptvMyVideosContentUpdateObserver::SendObserverRequestL()
    {
    IPTVLOGSTRING_LOW_LEVEL(
        "CIptvMyVideosContentUpdateObserver::SendObserverRequestL" );

    delete iObserverMsg;
    iObserverMsg = NULL;

    iObserverMsg = HBufC8::NewL( KIptvMyVideosObserverRequestSize );
    iObserverMsgPtr.Set( iObserverMsg->Des() );

    iSession.SendRequest(
        EIptvEngineMyVideosContentUpdateReq,
        iObserverMsgPtr,
        iStatus );
    }

// ---------------------------------------------------------------------------
// CIptvMyVideosContentUpdateObserver::DoCancel()
// ---------------------------------------------------------------------------
//
void CIptvMyVideosContentUpdateObserver::DoCancel()
    {
    }