sl@0: /* sl@0: * Copyright (c) 2005-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 PlayUtility Session sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "mmfdrmSession.h" sl@0: #include "DRMPlayClientServer.h" sl@0: sl@0: #ifdef _DEBUG sl@0: #define DEP_PRN0(str) RDebug::Print(str) sl@0: #define DEP_PRN1(str, v1) RDebug::Print(str, v1) sl@0: #define DEP_PRN2(str, v1, v2) RDebug::Print(str, v1, v2) sl@0: #else sl@0: #define DEP_PRN0(str) sl@0: #define DEP_PRN1(str, v1) sl@0: #define DEP_PRN2(str, v1, v2) sl@0: #endif // _DEBUG sl@0: sl@0: sl@0: sl@0: // Standard server startup code sl@0: // sl@0: static TInt StartServer() sl@0: { sl@0: DEP_PRN0(_L("DRM Client: Starting server...")); sl@0: sl@0: // EPOC is easy, we just create a new server process. Simultaneous sl@0: // launching of two such processes should be detected when the second one sl@0: // attempts to create the server object, failing with KErrAlreadyExists. sl@0: RProcess server; sl@0: //TInt r=server.Create(KHelloWorldServerImg,KNullDesC,serverUid); sl@0: TInt r=server.Create(KDRMPlayServerImg,KNullDesC); sl@0: sl@0: if (r!=KErrNone) sl@0: { sl@0: DEP_PRN1(_L(" DRM Client: server start failed %d"),r); sl@0: sl@0: return r; sl@0: } sl@0: TRequestStatus stat; sl@0: server.Rendezvous(stat); sl@0: if (stat!=KRequestPending) sl@0: server.Kill(0); // abort startup sl@0: else sl@0: server.Resume(); // logon OK - start the server sl@0: sl@0: DEP_PRN0(_L("DRM Client: Started")); sl@0: sl@0: User::WaitForRequest(stat); // wait for start or death sl@0: // we can't use the 'exit reason' if the server panicked as this sl@0: // is the panic 'reason' and may be '0' which cannot be distinguished sl@0: // from KErrNone sl@0: r=(server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int(); sl@0: server.Close(); sl@0: return r; sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: RDrmSession::RDrmSession() sl@0: { sl@0: } sl@0: sl@0: RDrmSession::~RDrmSession() sl@0: { sl@0: if ( Handle() ) sl@0: { sl@0: Disconnect(); sl@0: } sl@0: } sl@0: sl@0: sl@0: TInt RDrmSession::Connect() sl@0: { sl@0: // Try 2 times sl@0: TInt retry(2); sl@0: for (;;) sl@0: { sl@0: TInt r = CreateSession( KDRMPlayServerName, TVersion(0,0,0), -1); sl@0: if ((r != KErrNotFound) && (r != KErrServerTerminated) ) sl@0: return r; sl@0: if (--retry == 0) sl@0: return r; sl@0: r = StartServer(); sl@0: if (( r!= KErrNone) && (r !=KErrAlreadyExists)) sl@0: return r; sl@0: } sl@0: } sl@0: sl@0: void RDrmSession::Disconnect() sl@0: { sl@0: RSessionBase::Close(); sl@0: } sl@0: sl@0: TVersion RDrmSession::Version() const sl@0: { sl@0: return(TVersion(KDRMPlayServMajorVersionNumber, sl@0: KDRMPlayServMinorVersionNumber, sl@0: KDRMPlayServBuildVersionNumber)); sl@0: } sl@0: sl@0: //Sync send no data sl@0: TInt RDrmSession::Send(TInt aFunction) sl@0: { sl@0: TInt status(KErrSessionClosed); sl@0: if (Handle()) sl@0: { sl@0: status = RSessionBase::SendReceive(aFunction); sl@0: } sl@0: return status; sl@0: } sl@0: sl@0: //Sync send with data sl@0: TInt RDrmSession::Send(TInt aFunction,const TIpcArgs& aArgs) sl@0: { sl@0: TInt status(KErrSessionClosed); sl@0: if (Handle()) sl@0: { sl@0: status = RSessionBase::SendReceive(aFunction, aArgs); sl@0: } sl@0: return status; sl@0: } sl@0: sl@0: //Async send no data sl@0: void RDrmSession::Send(TInt aFunction,TRequestStatus& aStatus) sl@0: { sl@0: if (Handle()) sl@0: { sl@0: RSessionBase::SendReceive(aFunction, aStatus); sl@0: } sl@0: else sl@0: { sl@0: TRequestStatus* s = &aStatus; sl@0: User::RequestComplete( s , KErrSessionClosed ); sl@0: } sl@0: } sl@0: sl@0: //Async send with data sl@0: void RDrmSession::Send(TInt aFunction,const TIpcArgs& aArgs,TRequestStatus& aStatus) sl@0: { sl@0: if (Handle()) sl@0: { sl@0: RSessionBase::SendReceive(aFunction, aArgs, aStatus); sl@0: } sl@0: else sl@0: { sl@0: TRequestStatus* s = &aStatus; sl@0: User::RequestComplete( s , KErrSessionClosed ); sl@0: } sl@0: } sl@0: sl@0: // End of file