sl@0: /* sl@0: * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: DRM Play Session sl@0: * sl@0: */ sl@0: sl@0: sl@0: sl@0: #include "DRMCustomCommandAsyncAO.h" sl@0: #include "DRMPlaySession.h" sl@0: sl@0: #ifdef _DEBUG sl@0: #include sl@0: sl@0: #define TRACEPRNFNIN RDebug::Printf( "%s @ %d, %s>ENTER", __FILE__, __LINE__, __PRETTY_FUNCTION__ ); sl@0: #define TRACEPRNFNOUT RDebug::Printf( "%s @ %d, %s>EXIT", __FILE__, __LINE__, __PRETTY_FUNCTION__ ); sl@0: #define DEBPRN2(s, v1) RDebug::Print(s, v1); sl@0: #define DEBPRN3(s, v1, v2) RDebug::Print(s, v1, v2); sl@0: #else sl@0: #define TRACEPRNFNIN sl@0: #define TRACEPRNFNOUT sl@0: #define DEBPRN2(s, v1) sl@0: #define DEBPRN3(s, v1, v2) sl@0: #endif sl@0: sl@0: sl@0: CDRMCustomCommandAsyncAO::CDRMCustomCommandAsyncAO( TCustomCommandType aType, CDRMPlayServerSession& aParent ) sl@0: : CActive(CActive::EPriorityStandard), sl@0: iCustomCommandType(aType), sl@0: iAmCompleted(EFalse), sl@0: iParent(aParent), sl@0: iData1FromClient(NULL), sl@0: iData2FromClient(NULL), sl@0: iDataToClient(NULL) sl@0: { sl@0: TRACEPRNFNIN; sl@0: CActiveScheduler::Add(this); sl@0: TRACEPRNFNOUT; sl@0: } sl@0: sl@0: CDRMCustomCommandAsyncAO::~CDRMCustomCommandAsyncAO() sl@0: { sl@0: TRACEPRNFNIN; sl@0: Cancel(); sl@0: if ( !iAmCompleted && iMessage) sl@0: { sl@0: iMessage->Complete( KErrCancel ); sl@0: } sl@0: sl@0: // Delete the descriptors created on heap sl@0: delete iData1FromClient; sl@0: delete iData2FromClient; sl@0: delete iDataToClient; sl@0: sl@0: delete iMessage; sl@0: sl@0: TRACEPRNFNOUT; sl@0: } sl@0: sl@0: CDRMCustomCommandAsyncAO* CDRMCustomCommandAsyncAO::NewL( const RMessage2& aMessage, sl@0: TCustomCommandType aType, sl@0: CDRMPlayServerSession& aParent ) sl@0: { sl@0: TRACEPRNFNIN; sl@0: CDRMCustomCommandAsyncAO* self = new ( ELeave )CDRMCustomCommandAsyncAO( aType, aParent ); sl@0: CleanupStack::PushL( self ); sl@0: self->ConstructL(aMessage); sl@0: CleanupStack::Pop( self ); sl@0: TRACEPRNFNOUT; sl@0: return self; sl@0: } sl@0: sl@0: void CDRMCustomCommandAsyncAO::ConstructL( const RMessage2& aMessage ) sl@0: { sl@0: TRACEPRNFNIN; sl@0: sl@0: //Read mmf message destination information sl@0: TPckgCustomCommand thePckg; sl@0: User::LeaveIfError( aMessage.Read(0, thePckg) ); sl@0: sl@0: iMMFMessageDestinationPckg = thePckg().iDestination; sl@0: iMMFMessageFunction = thePckg().iFunction; sl@0: sl@0: /* sl@0: RDebug::Print(_L("CDRMCustomCommandAsyncAO::ConstructL:InterfaceId[%x]DestinationHandle[%d]"), \ sl@0: iMMFMessageDestinationPckg().InterfaceId(), sl@0: iMMFMessageDestinationPckg().DestinationHandle() ); sl@0: */ sl@0: sl@0: // Create descriptors to hold data1, data2 sl@0: sl@0: // Get Data 1 from client sl@0: TInt dataLen = aMessage.GetDesLengthL( 1 ); sl@0: iData1FromClient = HBufC8::NewL( dataLen ); sl@0: TPtr8 data1Ptr = iData1FromClient->Des(); sl@0: aMessage.ReadL( 1, data1Ptr ); sl@0: sl@0: // Get Data 2 from client sl@0: dataLen = aMessage.GetDesLengthL( 2 ); sl@0: iData2FromClient = HBufC8::NewL( dataLen ); sl@0: TPtr8 data2Ptr = iData2FromClient->Des(); sl@0: aMessage.ReadL( 2, data2Ptr ); sl@0: sl@0: TRACEPRNFNOUT; sl@0: } sl@0: sl@0: TMMFMessageDestinationPckg& CDRMCustomCommandAsyncAO::GetMMFMessageDestinationPckg() sl@0: { sl@0: return iMMFMessageDestinationPckg; sl@0: } sl@0: sl@0: TInt CDRMCustomCommandAsyncAO::GetMMFMessageFunction() sl@0: { sl@0: return iMMFMessageFunction; sl@0: } sl@0: sl@0: HBufC8* CDRMCustomCommandAsyncAO::GetData1FromClient() sl@0: { sl@0: return iData1FromClient; sl@0: } sl@0: sl@0: HBufC8* CDRMCustomCommandAsyncAO::GetData2FromClient() sl@0: { sl@0: return iData2FromClient; sl@0: } sl@0: sl@0: HBufC8* CDRMCustomCommandAsyncAO::GetDataToClient() sl@0: { sl@0: return iDataToClient; sl@0: } sl@0: sl@0: TInt CDRMCustomCommandAsyncAO::SetActive() sl@0: { sl@0: TRACEPRNFNIN; sl@0: TInt status(KErrNotReady); sl@0: if ( !IsActive() && iMessage ) sl@0: { sl@0: CActive::SetActive(); sl@0: status = KErrNone; sl@0: } sl@0: TRACEPRNFNOUT; sl@0: return status; sl@0: } sl@0: sl@0: void CDRMCustomCommandAsyncAO::TransferOwnershipL( const RMessage2& aMessage ) sl@0: { sl@0: // If this is a async custom command with result back to client sl@0: // Descriptor place holder is passed in the async message 'aMessage'. sl@0: if ( iCustomCommandType == ECustomCommandWithResult ) sl@0: { sl@0: // Create buffer to hold the result back sl@0: TInt dataLen = aMessage.GetDesMaxLengthL( 0 ); sl@0: iDataToClient = HBufC8::NewL( dataLen ); sl@0: } sl@0: sl@0: iMessage = new (ELeave) RMessage2(aMessage); sl@0: } sl@0: sl@0: void CDRMCustomCommandAsyncAO::RunL() sl@0: { sl@0: TRACEPRNFNIN; sl@0: TInt status(KErrNone); sl@0: // Write the result back if client is expecting one sl@0: TPtr8 dataPtr = iDataToClient->Des(); sl@0: if ( ( iCustomCommandType == ECustomCommandWithResult ) && sl@0: (dataPtr.Length() > 0 ) ) sl@0: { sl@0: status = iMessage->Write( 0, dataPtr ); sl@0: #ifdef _DEBUG sl@0: if ( status != KErrNone ) sl@0: { sl@0: RDebug::Print(_L("CDRMCustomCommandAsyncAO::RunL:iMessage.Write()->Len[%d]MaxLen[%d]Status[%d]"), sl@0: dataPtr.Length(), sl@0: dataPtr.MaxLength(), sl@0: status); sl@0: } sl@0: #endif // _DEBUG sl@0: } sl@0: // Complete the message sl@0: status = iStatus.Int(); sl@0: DEBPRN2(_L("CDRMCustomCommandAsyncAO::RunL[%d]"), status ); sl@0: iMessage->Complete( status ); sl@0: iAmCompleted = ETrue; sl@0: sl@0: // Signal the parent sl@0: iParent.AsyncCustomCommandCompleted( this ); sl@0: sl@0: TRACEPRNFNOUT; sl@0: } sl@0: sl@0: void CDRMCustomCommandAsyncAO::DoCancel() sl@0: { sl@0: TRACEPRNFNIN; sl@0: iMessage->Complete( KErrCancel ); sl@0: iAmCompleted = ETrue; sl@0: TRACEPRNFNOUT; sl@0: } sl@0: sl@0: TInt CDRMCustomCommandAsyncAO::RunError( TInt /*aError*/ ) sl@0: { sl@0: TRACEPRNFNIN; sl@0: // There was some error completing message.... sl@0: TRACEPRNFNOUT; sl@0: return KErrNone; sl@0: } sl@0: sl@0: // End of File