1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmlibs/mmfw/src/Client/Video/mediaclientpolicyserversession.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,119 @@
1.4 +// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "mediaclientpolicyserversession.h"
1.20 +#include <e32std.h>
1.21 +#include "mediaclientvideotrace.h"
1.22 +
1.23 +// Policy Server EXE name
1.24 +_LIT( KIvePolicyServerImg, "ivepolicyserver" );
1.25 +
1.26 +// Policy Server thread name
1.27 +_LIT( KIvePolicyServerName, "!ivepolicyserver0x10204C27" );
1.28 +
1.29 +// Number of asynchronous message slots
1.30 +const TInt KIveAsyncMessageSlots = 1;
1.31 +
1.32 +static TInt StartServer()
1.33 + {
1.34 + DEBUG_PRINTF("medialclientsession StartServer +++");
1.35 +
1.36 + RProcess server;
1.37 + TInt error = server.Create(KIvePolicyServerImg, KNullDesC);
1.38 + if (error != KErrNone)
1.39 + {
1.40 + DEBUG_PRINTF2("medialclientsession StartServer server creation failed %d", error);
1.41 + return error;
1.42 + }
1.43 +
1.44 + TRequestStatus status;
1.45 +
1.46 + server.Rendezvous(status);
1.47 + if (status != KRequestPending)
1.48 + {
1.49 + server.Kill( 0 );
1.50 + // abort startup
1.51 + }
1.52 + else
1.53 + {
1.54 + server.Resume();
1.55 + // logon OK - start the server
1.56 + }
1.57 +
1.58 + User::WaitForRequest(status);
1.59 + // wait for start or death
1.60 + error = (server.ExitType() == EExitPanic) ? KErrGeneral : status.Int();
1.61 + server.Close();
1.62 +
1.63 + DEBUG_PRINTF(" medialclientsession StartServer ---");
1.64 + return error;
1.65 + }
1.66 +
1.67 +RMediaClientPolicyServerSession::RMediaClientPolicyServerSession():
1.68 + RSessionBase()
1.69 + {
1.70 + DEBUG_PRINTF(" RMediaClientPolicyServerSession::RMediaClientPolicyServerSession +++");
1.71 + DEBUG_PRINTF(" RMediaClientPolicyServerSession::RMediaClientPolicyServerSession ---");
1.72 + }
1.73 +
1.74 +TInt RMediaClientPolicyServerSession::Connect()
1.75 + {
1.76 + DEBUG_PRINTF(" RMediaClientPolicyServerSession::Connect +++");
1.77 +
1.78 + TInt error = KErrNone;
1.79 + for (TInt i = 0; i < 2; i++)
1.80 + {
1.81 + // Try to create session.
1.82 + error = CreateSession(KIvePolicyServerName, TVersion( 0, 0, 0 ), KIveAsyncMessageSlots);
1.83 +
1.84 + if (error != KErrNotFound && error != KErrServerTerminated)
1.85 + {
1.86 + DEBUG_PRINTF("RMediaClientPolicyServerSession::Connect Server found and session created.");
1.87 + DEBUG_PRINTF2("RMediaClientPolicyServerSession::Connect --- returns %d", error);
1.88 + return error;
1.89 + }
1.90 +
1.91 + // If session failed, try to start server once.
1.92 + if (i == 0)
1.93 + {
1.94 + DEBUG_PRINTF("RMediaClientPolicyServerSession::Connect StartServer");
1.95 + // Start server
1.96 + error = StartServer();
1.97 + if (error != KErrNone && error != KErrAlreadyExists)
1.98 + {
1.99 + DEBUG_PRINTF("RMediaClientPolicyServerSession::Connect Server startup failed.");
1.100 + DEBUG_PRINTF2("RMediaClientPolicyServerSession::Connect --- returns %d", error);
1.101 + return error;
1.102 + }
1.103 + }
1.104 + else
1.105 + {
1.106 + DEBUG_PRINTF2("RMediaClientPolicyServerSession::Connect Session creation failed error %d", error);
1.107 + }
1.108 + }
1.109 +
1.110 + DEBUG_PRINTF2("RMediaClientPolicyServerSession::Connect --- returns %d", error);
1.111 + return error;
1.112 + }
1.113 +
1.114 +TInt RMediaClientPolicyServerSession::SendMessage( TInt aFunction, const TIpcArgs &aArgs ) const
1.115 + {
1.116 + DEBUG_PRINTF("RMediaClientPolicyServerSession::SendMessage +++");
1.117 +
1.118 + TInt error = SendReceive( aFunction, aArgs );
1.119 +
1.120 + DEBUG_PRINTF2("RMediaClientPolicyServerSession::SendMessage --- returns %d", error);
1.121 + return error;
1.122 + }