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