devsoundextensions/drmaudioplayer/DRMPlayServer/src/DRMCustomCommandAsyncAO.cpp
changeset 0 b8ed18f6c07b
equal deleted inserted replaced
-1:000000000000 0:b8ed18f6c07b
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   DRM Play Session
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "DRMCustomCommandAsyncAO.h"
       
    21 #include "DRMPlaySession.h"
       
    22 
       
    23 #ifdef _DEBUG
       
    24 #include <e32debug.h>
       
    25 
       
    26 #define TRACEPRNFNIN RDebug::Printf( "%s @ %d, %s>ENTER", __FILE__, __LINE__,  __PRETTY_FUNCTION__ );
       
    27 #define TRACEPRNFNOUT RDebug::Printf( "%s @ %d, %s>EXIT", __FILE__, __LINE__,  __PRETTY_FUNCTION__ );
       
    28 #define DEBPRN2(s, v1) RDebug::Print(s, v1);
       
    29 #define DEBPRN3(s, v1, v2) RDebug::Print(s, v1, v2);
       
    30 #else
       
    31 #define TRACEPRNFNIN
       
    32 #define TRACEPRNFNOUT
       
    33 #define DEBPRN2(s, v1)
       
    34 #define DEBPRN3(s, v1, v2)
       
    35 #endif
       
    36 
       
    37 
       
    38 CDRMCustomCommandAsyncAO::CDRMCustomCommandAsyncAO( TCustomCommandType aType, CDRMPlayServerSession& aParent )
       
    39 : CActive(CActive::EPriorityStandard),
       
    40  iCustomCommandType(aType),
       
    41  iAmCompleted(EFalse),
       
    42  iParent(aParent),
       
    43  iData1FromClient(NULL),
       
    44  iData2FromClient(NULL),
       
    45  iDataToClient(NULL)
       
    46     {
       
    47     TRACEPRNFNIN;
       
    48     CActiveScheduler::Add(this);
       
    49     TRACEPRNFNOUT;
       
    50     }
       
    51 
       
    52 CDRMCustomCommandAsyncAO::~CDRMCustomCommandAsyncAO()
       
    53     {
       
    54     TRACEPRNFNIN;
       
    55     Cancel();
       
    56     if ( !iAmCompleted && iMessage)
       
    57         {
       
    58         iMessage->Complete( KErrCancel );
       
    59         }
       
    60 
       
    61     // Delete the descriptors created on heap
       
    62     delete iData1FromClient;
       
    63     delete iData2FromClient;
       
    64     delete iDataToClient;
       
    65 
       
    66     delete iMessage;
       
    67 
       
    68     TRACEPRNFNOUT;
       
    69     }
       
    70 
       
    71 CDRMCustomCommandAsyncAO* CDRMCustomCommandAsyncAO::NewL( const RMessage2& aMessage,
       
    72                                                           TCustomCommandType aType,
       
    73                                                           CDRMPlayServerSession& aParent )
       
    74     {
       
    75     TRACEPRNFNIN;
       
    76     CDRMCustomCommandAsyncAO* self = new ( ELeave )CDRMCustomCommandAsyncAO( aType, aParent );
       
    77     CleanupStack::PushL( self );
       
    78     self->ConstructL(aMessage);
       
    79     CleanupStack::Pop( self );
       
    80     TRACEPRNFNOUT;
       
    81     return self;
       
    82     }
       
    83 
       
    84 void CDRMCustomCommandAsyncAO::ConstructL( const RMessage2& aMessage )
       
    85     {
       
    86     TRACEPRNFNIN;
       
    87 
       
    88     //Read mmf message destination information
       
    89     TPckgCustomCommand thePckg;
       
    90     User::LeaveIfError( aMessage.Read(0, thePckg) );
       
    91 
       
    92     iMMFMessageDestinationPckg = thePckg().iDestination;
       
    93     iMMFMessageFunction = thePckg().iFunction;
       
    94 
       
    95 /*
       
    96     RDebug::Print(_L("CDRMCustomCommandAsyncAO::ConstructL:InterfaceId[%x]DestinationHandle[%d]"), \
       
    97                                 iMMFMessageDestinationPckg().InterfaceId(),
       
    98                                 iMMFMessageDestinationPckg().DestinationHandle() );
       
    99 */
       
   100 
       
   101     // Create descriptors to hold data1, data2
       
   102 
       
   103     // Get Data 1 from client
       
   104     TInt dataLen = aMessage.GetDesLengthL( 1 );
       
   105     iData1FromClient = HBufC8::NewL( dataLen );
       
   106     TPtr8 data1Ptr = iData1FromClient->Des();
       
   107     aMessage.ReadL( 1, data1Ptr );
       
   108 
       
   109     // Get Data 2 from client
       
   110     dataLen = aMessage.GetDesLengthL( 2 );
       
   111     iData2FromClient = HBufC8::NewL( dataLen );
       
   112     TPtr8 data2Ptr = iData2FromClient->Des();
       
   113     aMessage.ReadL( 2, data2Ptr );
       
   114 
       
   115     TRACEPRNFNOUT;
       
   116     }
       
   117 
       
   118 TMMFMessageDestinationPckg& CDRMCustomCommandAsyncAO::GetMMFMessageDestinationPckg()
       
   119     {
       
   120     return iMMFMessageDestinationPckg;
       
   121     }
       
   122 
       
   123 TInt CDRMCustomCommandAsyncAO::GetMMFMessageFunction()
       
   124     {
       
   125     return iMMFMessageFunction;
       
   126     }
       
   127 
       
   128 HBufC8* CDRMCustomCommandAsyncAO::GetData1FromClient()
       
   129     {
       
   130     return iData1FromClient;
       
   131     }
       
   132 
       
   133 HBufC8* CDRMCustomCommandAsyncAO::GetData2FromClient()
       
   134     {
       
   135     return iData2FromClient;
       
   136     }
       
   137 
       
   138 HBufC8* CDRMCustomCommandAsyncAO::GetDataToClient()
       
   139     {
       
   140     return iDataToClient;
       
   141     }
       
   142 
       
   143 TInt CDRMCustomCommandAsyncAO::SetActive()
       
   144     {
       
   145     TRACEPRNFNIN;
       
   146     TInt status(KErrNotReady);
       
   147     if ( !IsActive() && iMessage )
       
   148         {
       
   149         CActive::SetActive();
       
   150         status = KErrNone;
       
   151         }
       
   152     TRACEPRNFNOUT;
       
   153     return status;
       
   154     }
       
   155 
       
   156 void CDRMCustomCommandAsyncAO::TransferOwnershipL( const RMessage2& aMessage )
       
   157     {
       
   158     // If this is a async custom command with result back to client
       
   159     // Descriptor place holder is passed in the async message 'aMessage'.
       
   160     if ( iCustomCommandType == ECustomCommandWithResult )
       
   161         {
       
   162         // Create buffer to hold the result back
       
   163         TInt dataLen = aMessage.GetDesMaxLengthL( 0 );
       
   164         iDataToClient = HBufC8::NewL( dataLen );
       
   165         }
       
   166 
       
   167     iMessage = new (ELeave) RMessage2(aMessage);
       
   168     }
       
   169 
       
   170 void CDRMCustomCommandAsyncAO::RunL()
       
   171     {
       
   172     TRACEPRNFNIN;
       
   173     TInt status(KErrNone);
       
   174     // Write the result back if client is expecting one
       
   175     TPtr8 dataPtr = iDataToClient->Des();
       
   176     if ( ( iCustomCommandType == ECustomCommandWithResult ) &&
       
   177          (dataPtr.Length() > 0 ) )
       
   178         {
       
   179         status = iMessage->Write( 0, dataPtr );
       
   180 #ifdef _DEBUG
       
   181         if ( status != KErrNone )
       
   182             {
       
   183             RDebug::Print(_L("CDRMCustomCommandAsyncAO::RunL:iMessage.Write()->Len[%d]MaxLen[%d]Status[%d]"),
       
   184                             dataPtr.Length(),
       
   185                             dataPtr.MaxLength(),
       
   186                             status);
       
   187             }
       
   188 #endif // _DEBUG
       
   189         }
       
   190     // Complete the message
       
   191     status = iStatus.Int();
       
   192     DEBPRN2(_L("CDRMCustomCommandAsyncAO::RunL[%d]"), status );
       
   193     iMessage->Complete( status );
       
   194     iAmCompleted = ETrue;
       
   195 
       
   196     // Signal the parent
       
   197     iParent.AsyncCustomCommandCompleted( this );
       
   198 
       
   199     TRACEPRNFNOUT;
       
   200     }
       
   201 
       
   202 void CDRMCustomCommandAsyncAO::DoCancel()
       
   203     {
       
   204     TRACEPRNFNIN;
       
   205     iMessage->Complete( KErrCancel );
       
   206     iAmCompleted = ETrue;
       
   207     TRACEPRNFNOUT;
       
   208     }
       
   209 
       
   210 TInt CDRMCustomCommandAsyncAO::RunError( TInt /*aError*/ )
       
   211     {
       
   212     TRACEPRNFNIN;
       
   213     // There was some error completing message....
       
   214     TRACEPRNFNOUT;
       
   215     return KErrNone;
       
   216     }
       
   217 
       
   218 // End of File