sl@0: // Copyright (c) 2009 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 the License "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: sl@0: // sl@0: sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @internalTechnology sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include sl@0: sl@0: #include "msmanclientserver.h" sl@0: #include "rusbhostsession.h" sl@0: #include "tmslog.h" sl@0: #include "debug.h" sl@0: sl@0: sl@0: TVersion RUsbHostSession::Version() const sl@0: { sl@0: __MSFNSLOG sl@0: return(TVersion(KUsbHostSrvMajorVersionNumber, sl@0: KUsbHostSrvMinorVersionNumber, sl@0: KUsbHostSrvBuildVersionNumber)); sl@0: } sl@0: sl@0: sl@0: EXPORT_C RUsbHostSession::RUsbHostSession() sl@0: { sl@0: __MSFNSLOG sl@0: } sl@0: sl@0: sl@0: EXPORT_C TInt RUsbHostSession::Connect() sl@0: { sl@0: __MSFNSLOG sl@0: sl@0: TInt retry = 2; sl@0: for (;;) sl@0: { sl@0: TInt r = CreateSession(KUsbHostServerName, Version()); sl@0: if ((r != KErrNotFound) && (r != KErrServerTerminated)) sl@0: { sl@0: return r; sl@0: } sl@0: if (--retry == 0) sl@0: { sl@0: return r; sl@0: } sl@0: sl@0: r = StartServer(); sl@0: if ((r != KErrNone) && (r != KErrAlreadyExists)) sl@0: { sl@0: return r; sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: TInt RUsbHostSession::StartServer() sl@0: { sl@0: __MSFNSLOG sl@0: sl@0: const TUidType serverUid(KNullUid, KNullUid, KUsbHostServerUid3); sl@0: sl@0: // Create the server process sl@0: RProcess server; sl@0: TInt r = server.Create(KUsbHostServerName, KNullDesC, serverUid); sl@0: if (r != KErrNone) sl@0: { sl@0: return r; sl@0: } sl@0: sl@0: // Create the rendezvous request with the server process sl@0: TRequestStatus status; sl@0: server.Rendezvous(status); sl@0: if (status != KRequestPending) sl@0: { sl@0: User::WaitForRequest(status); sl@0: server.Kill(0); // If the outstanding request is not pending then kill the server sl@0: server.Close(); sl@0: return status.Int(); sl@0: } sl@0: sl@0: server.SetPriority(EPriorityHigh); sl@0: server.Resume(); // start the server sl@0: sl@0: // Test whether the process has ended and if it has ended, return how it ended. sl@0: User::WaitForRequest(status); sl@0: sl@0: if (status == KRequestPending) sl@0: { sl@0: server.Close(); sl@0: return status.Int(); sl@0: } sl@0: sl@0: server.Close(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: sl@0: EXPORT_C TInt RUsbHostSession::Start() sl@0: { sl@0: return SendReceive(EUsbHostStart); sl@0: }