os/kernelhwsrv/kerneltest/f32test/shostmassstorage/msman/client/rusbhostsession.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/shostmassstorage/msman/client/rusbhostsession.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,120 @@
1.4 +// Copyright (c) 2009 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 the License "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 +
1.20 +
1.21 +/**
1.22 + @file
1.23 + @internalTechnology
1.24 +*/
1.25 +
1.26 +
1.27 +#include <e32std.h>
1.28 +#include <f32file.h>
1.29 +
1.30 +#include "msmanclientserver.h"
1.31 +#include "rusbhostsession.h"
1.32 +#include "tmslog.h"
1.33 +#include "debug.h"
1.34 +
1.35 +
1.36 +TVersion RUsbHostSession::Version() const
1.37 + {
1.38 + __MSFNSLOG
1.39 + return(TVersion(KUsbHostSrvMajorVersionNumber,
1.40 + KUsbHostSrvMinorVersionNumber,
1.41 + KUsbHostSrvBuildVersionNumber));
1.42 + }
1.43 +
1.44 +
1.45 +EXPORT_C RUsbHostSession::RUsbHostSession()
1.46 + {
1.47 + __MSFNSLOG
1.48 + }
1.49 +
1.50 +
1.51 +EXPORT_C TInt RUsbHostSession::Connect()
1.52 + {
1.53 + __MSFNSLOG
1.54 +
1.55 + TInt retry = 2;
1.56 + for (;;)
1.57 + {
1.58 + TInt r = CreateSession(KUsbHostServerName, Version());
1.59 + if ((r != KErrNotFound) && (r != KErrServerTerminated))
1.60 + {
1.61 + return r;
1.62 + }
1.63 + if (--retry == 0)
1.64 + {
1.65 + return r;
1.66 + }
1.67 +
1.68 + r = StartServer();
1.69 + if ((r != KErrNone) && (r != KErrAlreadyExists))
1.70 + {
1.71 + return r;
1.72 + }
1.73 + }
1.74 + }
1.75 +
1.76 +
1.77 +TInt RUsbHostSession::StartServer()
1.78 + {
1.79 + __MSFNSLOG
1.80 +
1.81 + const TUidType serverUid(KNullUid, KNullUid, KUsbHostServerUid3);
1.82 +
1.83 + // Create the server process
1.84 + RProcess server;
1.85 + TInt r = server.Create(KUsbHostServerName, KNullDesC, serverUid);
1.86 + if (r != KErrNone)
1.87 + {
1.88 + return r;
1.89 + }
1.90 +
1.91 + // Create the rendezvous request with the server process
1.92 + TRequestStatus status;
1.93 + server.Rendezvous(status);
1.94 + if (status != KRequestPending)
1.95 + {
1.96 + User::WaitForRequest(status);
1.97 + server.Kill(0); // If the outstanding request is not pending then kill the server
1.98 + server.Close();
1.99 + return status.Int();
1.100 + }
1.101 +
1.102 + server.SetPriority(EPriorityHigh);
1.103 + server.Resume(); // start the server
1.104 +
1.105 + // Test whether the process has ended and if it has ended, return how it ended.
1.106 + User::WaitForRequest(status);
1.107 +
1.108 + if (status == KRequestPending)
1.109 + {
1.110 + server.Close();
1.111 + return status.Int();
1.112 + }
1.113 +
1.114 + server.Close();
1.115 + return KErrNone;
1.116 + }
1.117 +
1.118 +
1.119 +
1.120 +EXPORT_C TInt RUsbHostSession::Start()
1.121 + {
1.122 + return SendReceive(EUsbHostStart);
1.123 + }