os/mm/devsoundextensions/drmaudioplayer/DRMPlayUtility/src/mmfdrmSession.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) 2005-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 PlayUtility Session
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#include "mmfdrmSession.h"
sl@0
    20
#include "DRMPlayClientServer.h"
sl@0
    21
sl@0
    22
#ifdef _DEBUG
sl@0
    23
#define DEP_PRN0(str)   RDebug::Print(str)
sl@0
    24
#define DEP_PRN1(str, v1)   RDebug::Print(str, v1)
sl@0
    25
#define DEP_PRN2(str, v1, v2)   RDebug::Print(str, v1, v2)
sl@0
    26
#else
sl@0
    27
#define DEP_PRN0(str)
sl@0
    28
#define DEP_PRN1(str, v1)
sl@0
    29
#define DEP_PRN2(str, v1, v2)
sl@0
    30
#endif // _DEBUG
sl@0
    31
sl@0
    32
sl@0
    33
sl@0
    34
// Standard server startup code
sl@0
    35
//
sl@0
    36
static TInt StartServer()
sl@0
    37
    {
sl@0
    38
    DEP_PRN0(_L("DRM Client: Starting server..."));
sl@0
    39
sl@0
    40
    // EPOC is easy, we just create a new server process. Simultaneous
sl@0
    41
    // launching of two such processes should be detected when the second one
sl@0
    42
    // attempts to create the server object, failing with KErrAlreadyExists.
sl@0
    43
    RProcess server;
sl@0
    44
    //TInt r=server.Create(KHelloWorldServerImg,KNullDesC,serverUid);
sl@0
    45
    TInt r=server.Create(KDRMPlayServerImg,KNullDesC);
sl@0
    46
sl@0
    47
    if (r!=KErrNone)
sl@0
    48
        {
sl@0
    49
        DEP_PRN1(_L(" DRM Client: server start failed %d"),r);
sl@0
    50
sl@0
    51
        return r;
sl@0
    52
        }
sl@0
    53
    TRequestStatus stat;
sl@0
    54
    server.Rendezvous(stat);
sl@0
    55
    if (stat!=KRequestPending)
sl@0
    56
        server.Kill(0);     // abort startup
sl@0
    57
    else
sl@0
    58
        server.Resume();    // logon OK - start the server
sl@0
    59
sl@0
    60
    DEP_PRN0(_L("DRM Client: Started"));
sl@0
    61
sl@0
    62
    User::WaitForRequest(stat);     // wait for start or death
sl@0
    63
    // we can't use the 'exit reason' if the server panicked as this
sl@0
    64
    // is the panic 'reason' and may be '0' which cannot be distinguished
sl@0
    65
    // from KErrNone
sl@0
    66
    r=(server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int();
sl@0
    67
    server.Close();
sl@0
    68
    return r;
sl@0
    69
    }
sl@0
    70
sl@0
    71
sl@0
    72
sl@0
    73
sl@0
    74
RDrmSession::RDrmSession()
sl@0
    75
    {
sl@0
    76
    }
sl@0
    77
sl@0
    78
RDrmSession::~RDrmSession()
sl@0
    79
    {
sl@0
    80
    if ( Handle() )
sl@0
    81
        {
sl@0
    82
        Disconnect();
sl@0
    83
        }
sl@0
    84
    }
sl@0
    85
sl@0
    86
sl@0
    87
TInt RDrmSession::Connect()
sl@0
    88
    {
sl@0
    89
    // Try 2 times
sl@0
    90
    TInt retry(2);
sl@0
    91
    for (;;)
sl@0
    92
        {
sl@0
    93
        TInt r = CreateSession( KDRMPlayServerName, TVersion(0,0,0), -1);
sl@0
    94
        if ((r != KErrNotFound) && (r != KErrServerTerminated) )
sl@0
    95
            return r;
sl@0
    96
        if (--retry == 0)
sl@0
    97
            return r;
sl@0
    98
        r = StartServer();
sl@0
    99
        if (( r!= KErrNone) && (r !=KErrAlreadyExists))
sl@0
   100
            return r;
sl@0
   101
        }
sl@0
   102
    }
sl@0
   103
sl@0
   104
void RDrmSession::Disconnect()
sl@0
   105
    {
sl@0
   106
    RSessionBase::Close();
sl@0
   107
    }
sl@0
   108
sl@0
   109
TVersion RDrmSession::Version() const
sl@0
   110
    {
sl@0
   111
    return(TVersion(KDRMPlayServMajorVersionNumber,
sl@0
   112
                    KDRMPlayServMinorVersionNumber,
sl@0
   113
                    KDRMPlayServBuildVersionNumber));
sl@0
   114
    }
sl@0
   115
sl@0
   116
//Sync send no data
sl@0
   117
TInt RDrmSession::Send(TInt aFunction)
sl@0
   118
    {
sl@0
   119
    TInt status(KErrSessionClosed);
sl@0
   120
    if (Handle())
sl@0
   121
        {
sl@0
   122
        status = RSessionBase::SendReceive(aFunction);
sl@0
   123
        }
sl@0
   124
    return status;
sl@0
   125
    }
sl@0
   126
sl@0
   127
//Sync send with data
sl@0
   128
TInt RDrmSession::Send(TInt aFunction,const TIpcArgs& aArgs)
sl@0
   129
    {
sl@0
   130
    TInt status(KErrSessionClosed);
sl@0
   131
    if (Handle())
sl@0
   132
        {
sl@0
   133
        status = RSessionBase::SendReceive(aFunction, aArgs);
sl@0
   134
        }
sl@0
   135
    return status;
sl@0
   136
    }
sl@0
   137
sl@0
   138
//Async send no data
sl@0
   139
void RDrmSession::Send(TInt aFunction,TRequestStatus& aStatus)
sl@0
   140
    {
sl@0
   141
    if (Handle())
sl@0
   142
        {
sl@0
   143
        RSessionBase::SendReceive(aFunction, aStatus);
sl@0
   144
        }
sl@0
   145
    else
sl@0
   146
        {
sl@0
   147
        TRequestStatus* s = &aStatus;
sl@0
   148
        User::RequestComplete( s , KErrSessionClosed );
sl@0
   149
        }
sl@0
   150
    }
sl@0
   151
sl@0
   152
//Async send with data
sl@0
   153
void RDrmSession::Send(TInt aFunction,const TIpcArgs& aArgs,TRequestStatus& aStatus)
sl@0
   154
    {
sl@0
   155
    if (Handle())
sl@0
   156
        {
sl@0
   157
        RSessionBase::SendReceive(aFunction, aArgs, aStatus);
sl@0
   158
        }
sl@0
   159
    else
sl@0
   160
        {
sl@0
   161
        TRequestStatus* s = &aStatus;
sl@0
   162
        User::RequestComplete( s , KErrSessionClosed );
sl@0
   163
        }
sl@0
   164
    }
sl@0
   165
sl@0
   166
// End of file