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