author | sl |
Tue, 10 Jun 2014 14:32:02 +0200 | |
changeset 1 | 260cb5ec6c19 |
permissions | -rw-r--r-- |
sl@0 | 1 |
// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
sl@0 | 2 |
// All rights reserved. |
sl@0 | 3 |
// This component and the accompanying materials are made available |
sl@0 | 4 |
// under the terms of the License "Eclipse Public License v1.0" |
sl@0 | 5 |
// which accompanies this distribution, and is available |
sl@0 | 6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
sl@0 | 7 |
// |
sl@0 | 8 |
// Initial Contributors: |
sl@0 | 9 |
// Nokia Corporation - initial contribution. |
sl@0 | 10 |
// |
sl@0 | 11 |
// Contributors: |
sl@0 | 12 |
// |
sl@0 | 13 |
// Description: |
sl@0 | 14 |
// |
sl@0 | 15 |
|
sl@0 | 16 |
|
sl@0 | 17 |
|
sl@0 | 18 |
/** |
sl@0 | 19 |
@file |
sl@0 | 20 |
@internalTechnology |
sl@0 | 21 |
*/ |
sl@0 | 22 |
|
sl@0 | 23 |
|
sl@0 | 24 |
#include <e32std.h> |
sl@0 | 25 |
#include <f32file.h> |
sl@0 | 26 |
|
sl@0 | 27 |
#include "msmanclientserver.h" |
sl@0 | 28 |
#include "rusbhostsession.h" |
sl@0 | 29 |
#include "tmslog.h" |
sl@0 | 30 |
#include "debug.h" |
sl@0 | 31 |
|
sl@0 | 32 |
|
sl@0 | 33 |
TVersion RUsbHostSession::Version() const |
sl@0 | 34 |
{ |
sl@0 | 35 |
__MSFNSLOG |
sl@0 | 36 |
return(TVersion(KUsbHostSrvMajorVersionNumber, |
sl@0 | 37 |
KUsbHostSrvMinorVersionNumber, |
sl@0 | 38 |
KUsbHostSrvBuildVersionNumber)); |
sl@0 | 39 |
} |
sl@0 | 40 |
|
sl@0 | 41 |
|
sl@0 | 42 |
EXPORT_C RUsbHostSession::RUsbHostSession() |
sl@0 | 43 |
{ |
sl@0 | 44 |
__MSFNSLOG |
sl@0 | 45 |
} |
sl@0 | 46 |
|
sl@0 | 47 |
|
sl@0 | 48 |
EXPORT_C TInt RUsbHostSession::Connect() |
sl@0 | 49 |
{ |
sl@0 | 50 |
__MSFNSLOG |
sl@0 | 51 |
|
sl@0 | 52 |
TInt retry = 2; |
sl@0 | 53 |
for (;;) |
sl@0 | 54 |
{ |
sl@0 | 55 |
TInt r = CreateSession(KUsbHostServerName, Version()); |
sl@0 | 56 |
if ((r != KErrNotFound) && (r != KErrServerTerminated)) |
sl@0 | 57 |
{ |
sl@0 | 58 |
return r; |
sl@0 | 59 |
} |
sl@0 | 60 |
if (--retry == 0) |
sl@0 | 61 |
{ |
sl@0 | 62 |
return r; |
sl@0 | 63 |
} |
sl@0 | 64 |
|
sl@0 | 65 |
r = StartServer(); |
sl@0 | 66 |
if ((r != KErrNone) && (r != KErrAlreadyExists)) |
sl@0 | 67 |
{ |
sl@0 | 68 |
return r; |
sl@0 | 69 |
} |
sl@0 | 70 |
} |
sl@0 | 71 |
} |
sl@0 | 72 |
|
sl@0 | 73 |
|
sl@0 | 74 |
TInt RUsbHostSession::StartServer() |
sl@0 | 75 |
{ |
sl@0 | 76 |
__MSFNSLOG |
sl@0 | 77 |
|
sl@0 | 78 |
const TUidType serverUid(KNullUid, KNullUid, KUsbHostServerUid3); |
sl@0 | 79 |
|
sl@0 | 80 |
// Create the server process |
sl@0 | 81 |
RProcess server; |
sl@0 | 82 |
TInt r = server.Create(KUsbHostServerName, KNullDesC, serverUid); |
sl@0 | 83 |
if (r != KErrNone) |
sl@0 | 84 |
{ |
sl@0 | 85 |
return r; |
sl@0 | 86 |
} |
sl@0 | 87 |
|
sl@0 | 88 |
// Create the rendezvous request with the server process |
sl@0 | 89 |
TRequestStatus status; |
sl@0 | 90 |
server.Rendezvous(status); |
sl@0 | 91 |
if (status != KRequestPending) |
sl@0 | 92 |
{ |
sl@0 | 93 |
User::WaitForRequest(status); |
sl@0 | 94 |
server.Kill(0); // If the outstanding request is not pending then kill the server |
sl@0 | 95 |
server.Close(); |
sl@0 | 96 |
return status.Int(); |
sl@0 | 97 |
} |
sl@0 | 98 |
|
sl@0 | 99 |
server.SetPriority(EPriorityHigh); |
sl@0 | 100 |
server.Resume(); // start the server |
sl@0 | 101 |
|
sl@0 | 102 |
// Test whether the process has ended and if it has ended, return how it ended. |
sl@0 | 103 |
User::WaitForRequest(status); |
sl@0 | 104 |
|
sl@0 | 105 |
if (status == KRequestPending) |
sl@0 | 106 |
{ |
sl@0 | 107 |
server.Close(); |
sl@0 | 108 |
return status.Int(); |
sl@0 | 109 |
} |
sl@0 | 110 |
|
sl@0 | 111 |
server.Close(); |
sl@0 | 112 |
return KErrNone; |
sl@0 | 113 |
} |
sl@0 | 114 |
|
sl@0 | 115 |
|
sl@0 | 116 |
|
sl@0 | 117 |
EXPORT_C TInt RUsbHostSession::Start() |
sl@0 | 118 |
{ |
sl@0 | 119 |
return SendReceive(EUsbHostStart); |
sl@0 | 120 |
} |