os/mm/devsoundextensions/drmaudioplayer/DRMPlayUtility/src/mmfdrmSession.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/devsoundextensions/drmaudioplayer/DRMPlayUtility/src/mmfdrmSession.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,166 @@
     1.4 +/*
     1.5 +* Copyright (c) 2005-2006 Nokia Corporation and/or its subsidiary(-ies). 
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description:   DRM PlayUtility Session
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include "mmfdrmSession.h"
    1.23 +#include "DRMPlayClientServer.h"
    1.24 +
    1.25 +#ifdef _DEBUG
    1.26 +#define DEP_PRN0(str)   RDebug::Print(str)
    1.27 +#define DEP_PRN1(str, v1)   RDebug::Print(str, v1)
    1.28 +#define DEP_PRN2(str, v1, v2)   RDebug::Print(str, v1, v2)
    1.29 +#else
    1.30 +#define DEP_PRN0(str)
    1.31 +#define DEP_PRN1(str, v1)
    1.32 +#define DEP_PRN2(str, v1, v2)
    1.33 +#endif // _DEBUG
    1.34 +
    1.35 +
    1.36 +
    1.37 +// Standard server startup code
    1.38 +//
    1.39 +static TInt StartServer()
    1.40 +    {
    1.41 +    DEP_PRN0(_L("DRM Client: Starting server..."));
    1.42 +
    1.43 +    // EPOC is easy, we just create a new server process. Simultaneous
    1.44 +    // launching of two such processes should be detected when the second one
    1.45 +    // attempts to create the server object, failing with KErrAlreadyExists.
    1.46 +    RProcess server;
    1.47 +    //TInt r=server.Create(KHelloWorldServerImg,KNullDesC,serverUid);
    1.48 +    TInt r=server.Create(KDRMPlayServerImg,KNullDesC);
    1.49 +
    1.50 +    if (r!=KErrNone)
    1.51 +        {
    1.52 +        DEP_PRN1(_L(" DRM Client: server start failed %d"),r);
    1.53 +
    1.54 +        return r;
    1.55 +        }
    1.56 +    TRequestStatus stat;
    1.57 +    server.Rendezvous(stat);
    1.58 +    if (stat!=KRequestPending)
    1.59 +        server.Kill(0);     // abort startup
    1.60 +    else
    1.61 +        server.Resume();    // logon OK - start the server
    1.62 +
    1.63 +    DEP_PRN0(_L("DRM Client: Started"));
    1.64 +
    1.65 +    User::WaitForRequest(stat);     // wait for start or death
    1.66 +    // we can't use the 'exit reason' if the server panicked as this
    1.67 +    // is the panic 'reason' and may be '0' which cannot be distinguished
    1.68 +    // from KErrNone
    1.69 +    r=(server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int();
    1.70 +    server.Close();
    1.71 +    return r;
    1.72 +    }
    1.73 +
    1.74 +
    1.75 +
    1.76 +
    1.77 +RDrmSession::RDrmSession()
    1.78 +    {
    1.79 +    }
    1.80 +
    1.81 +RDrmSession::~RDrmSession()
    1.82 +    {
    1.83 +    if ( Handle() )
    1.84 +        {
    1.85 +        Disconnect();
    1.86 +        }
    1.87 +    }
    1.88 +
    1.89 +
    1.90 +TInt RDrmSession::Connect()
    1.91 +    {
    1.92 +    // Try 2 times
    1.93 +    TInt retry(2);
    1.94 +    for (;;)
    1.95 +        {
    1.96 +        TInt r = CreateSession( KDRMPlayServerName, TVersion(0,0,0), -1);
    1.97 +        if ((r != KErrNotFound) && (r != KErrServerTerminated) )
    1.98 +            return r;
    1.99 +        if (--retry == 0)
   1.100 +            return r;
   1.101 +        r = StartServer();
   1.102 +        if (( r!= KErrNone) && (r !=KErrAlreadyExists))
   1.103 +            return r;
   1.104 +        }
   1.105 +    }
   1.106 +
   1.107 +void RDrmSession::Disconnect()
   1.108 +    {
   1.109 +    RSessionBase::Close();
   1.110 +    }
   1.111 +
   1.112 +TVersion RDrmSession::Version() const
   1.113 +    {
   1.114 +    return(TVersion(KDRMPlayServMajorVersionNumber,
   1.115 +                    KDRMPlayServMinorVersionNumber,
   1.116 +                    KDRMPlayServBuildVersionNumber));
   1.117 +    }
   1.118 +
   1.119 +//Sync send no data
   1.120 +TInt RDrmSession::Send(TInt aFunction)
   1.121 +    {
   1.122 +    TInt status(KErrSessionClosed);
   1.123 +    if (Handle())
   1.124 +        {
   1.125 +        status = RSessionBase::SendReceive(aFunction);
   1.126 +        }
   1.127 +    return status;
   1.128 +    }
   1.129 +
   1.130 +//Sync send with data
   1.131 +TInt RDrmSession::Send(TInt aFunction,const TIpcArgs& aArgs)
   1.132 +    {
   1.133 +    TInt status(KErrSessionClosed);
   1.134 +    if (Handle())
   1.135 +        {
   1.136 +        status = RSessionBase::SendReceive(aFunction, aArgs);
   1.137 +        }
   1.138 +    return status;
   1.139 +    }
   1.140 +
   1.141 +//Async send no data
   1.142 +void RDrmSession::Send(TInt aFunction,TRequestStatus& aStatus)
   1.143 +    {
   1.144 +    if (Handle())
   1.145 +        {
   1.146 +        RSessionBase::SendReceive(aFunction, aStatus);
   1.147 +        }
   1.148 +    else
   1.149 +        {
   1.150 +        TRequestStatus* s = &aStatus;
   1.151 +        User::RequestComplete( s , KErrSessionClosed );
   1.152 +        }
   1.153 +    }
   1.154 +
   1.155 +//Async send with data
   1.156 +void RDrmSession::Send(TInt aFunction,const TIpcArgs& aArgs,TRequestStatus& aStatus)
   1.157 +    {
   1.158 +    if (Handle())
   1.159 +        {
   1.160 +        RSessionBase::SendReceive(aFunction, aArgs, aStatus);
   1.161 +        }
   1.162 +    else
   1.163 +        {
   1.164 +        TRequestStatus* s = &aStatus;
   1.165 +        User::RequestComplete( s , KErrSessionClosed );
   1.166 +        }
   1.167 +    }
   1.168 +
   1.169 +// End of file