os/kernelhwsrv/kerneltest/f32test/shostmassstorage/msman/client/rusbotgsession.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
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
// rusbhostmsdevice.cpp
sl@0
    15
//
sl@0
    16
//
sl@0
    17
sl@0
    18
sl@0
    19
sl@0
    20
/**
sl@0
    21
 @file
sl@0
    22
 @internalTechnology
sl@0
    23
*/
sl@0
    24
sl@0
    25
sl@0
    26
#include <e32std.h>
sl@0
    27
#include <f32file.h>
sl@0
    28
sl@0
    29
#include "msmanclientserver.h"
sl@0
    30
#include "rusbotgsession.h"
sl@0
    31
#include "tmslog.h"
sl@0
    32
#include "debug.h"
sl@0
    33
sl@0
    34
sl@0
    35
TVersion RUsbOtgSession::Version() const
sl@0
    36
    {
sl@0
    37
    __MSFNSLOG
sl@0
    38
    return(TVersion(KUsbOtgSrvMajorVersionNumber,
sl@0
    39
                    KUsbOtgSrvMinorVersionNumber,
sl@0
    40
                    KUsbOtgSrvBuildVersionNumber));
sl@0
    41
    }
sl@0
    42
sl@0
    43
sl@0
    44
EXPORT_C RUsbOtgSession::RUsbOtgSession()
sl@0
    45
    {
sl@0
    46
    __MSFNSLOG
sl@0
    47
    }
sl@0
    48
sl@0
    49
sl@0
    50
EXPORT_C RUsbOtgSession::RUsbOtgSession(TInt /* aParam */)
sl@0
    51
    {
sl@0
    52
    __MSFNSLOG
sl@0
    53
    }
sl@0
    54
sl@0
    55
EXPORT_C TInt RUsbOtgSession::Connect()
sl@0
    56
    {
sl@0
    57
    __MSFNSLOG
sl@0
    58
sl@0
    59
    TInt retry = 2;
sl@0
    60
    for (;;)
sl@0
    61
        {
sl@0
    62
        TInt r = CreateSession(KUsbOtgServerName, Version());
sl@0
    63
        if ((r != KErrNotFound) && (r != KErrServerTerminated))
sl@0
    64
            {
sl@0
    65
            return r;
sl@0
    66
            }
sl@0
    67
        if (--retry == 0)
sl@0
    68
            {
sl@0
    69
            return r;
sl@0
    70
            }
sl@0
    71
sl@0
    72
        r = StartServer();
sl@0
    73
        if ((r != KErrNone) && (r != KErrAlreadyExists))
sl@0
    74
            {
sl@0
    75
            return r;
sl@0
    76
            }
sl@0
    77
        }
sl@0
    78
    }
sl@0
    79
sl@0
    80
sl@0
    81
TInt RUsbOtgSession::StartServer()
sl@0
    82
    {
sl@0
    83
    __MSFNSLOG
sl@0
    84
sl@0
    85
    const TUidType serverUid(KNullUid, KNullUid, KUsbOtgServerUid3);
sl@0
    86
sl@0
    87
    // Create the server process
sl@0
    88
    RProcess server;
sl@0
    89
    TInt r = server.Create(KUsbOtgServerName, KNullDesC, serverUid);
sl@0
    90
    if (r != KErrNone)
sl@0
    91
        {
sl@0
    92
        return r;
sl@0
    93
        }
sl@0
    94
sl@0
    95
    // Create the rendezvous request with the server process
sl@0
    96
    TRequestStatus status;
sl@0
    97
    server.Rendezvous(status);
sl@0
    98
    if (status != KRequestPending)
sl@0
    99
        {
sl@0
   100
        User::WaitForRequest(status);
sl@0
   101
        server.Kill(0);    // If the outstanding request is not pending then kill the server
sl@0
   102
        server.Close();
sl@0
   103
        return status.Int();
sl@0
   104
        }
sl@0
   105
sl@0
   106
	server.SetPriority(EPriorityHigh);
sl@0
   107
    server.Resume(); // start the server
sl@0
   108
sl@0
   109
    // Test whether the process has ended and if it has ended, return how it ended.
sl@0
   110
    User::WaitForRequest(status);
sl@0
   111
sl@0
   112
    if (status == KRequestPending)
sl@0
   113
        {
sl@0
   114
        server.Close();
sl@0
   115
        return status.Int();
sl@0
   116
        }
sl@0
   117
sl@0
   118
    server.Close();
sl@0
   119
    return KErrNone;
sl@0
   120
    }
sl@0
   121
sl@0
   122
sl@0
   123
EXPORT_C TBool RUsbOtgSession::DeviceInserted()
sl@0
   124
    {
sl@0
   125
    __MSFNSLOG
sl@0
   126
    TPckgBuf<TBool> pckg;
sl@0
   127
    TIpcArgs args(&pckg);
sl@0
   128
sl@0
   129
    SendReceive(EUsbOtgDeviceInserted, args);
sl@0
   130
    TBool res = pckg();
sl@0
   131
    return res;
sl@0
   132
    }
sl@0
   133
sl@0
   134
sl@0
   135
EXPORT_C void RUsbOtgSession::NotifyChange(TBool& /* aChanged */, TRequestStatus& aStatus)
sl@0
   136
    {
sl@0
   137
    __MSFNSLOG
sl@0
   138
    TPckgBuf<TBool> pckg;
sl@0
   139
    TIpcArgs args(&pckg);
sl@0
   140
sl@0
   141
    SendReceive(EUsbOtgNotifyChange, args, aStatus);
sl@0
   142
    }
sl@0
   143
sl@0
   144
sl@0
   145
EXPORT_C TInt RUsbOtgSession::NotifyChangeCancel()
sl@0
   146
    {
sl@0
   147
    __MSFNSLOG
sl@0
   148
    return SendReceive(EUsbOtgNotifyChangeCancel);
sl@0
   149
    }
sl@0
   150
sl@0
   151
sl@0
   152
EXPORT_C TInt RUsbOtgSession::BusDrop()
sl@0
   153
	{
sl@0
   154
    __MSFNSLOG
sl@0
   155
	return SendReceive(EUsbOtgBusDrop);
sl@0
   156
	}