author | sl@SLION-WIN7.fritz.box |
Fri, 15 Jun 2012 03:10:57 +0200 | |
changeset 0 | bde4ae8d615e |
permissions | -rw-r--r-- |
sl@0 | 1 |
// Copyright (c) 2004-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 |
// Implements a Session of a Symbian OS server for the RUsbMassStorage API |
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 |
#include "cusbmassstoragesession.h" |
sl@0 | 24 |
#include "cusbmassstoragecontroller.h" |
sl@0 | 25 |
#include "cusbmassstorageserver.h" |
sl@0 | 26 |
#include "usbmsshared.h" |
sl@0 | 27 |
|
sl@0 | 28 |
/** |
sl@0 | 29 |
Construct a Symbian OS session object. |
sl@0 | 30 |
|
sl@0 | 31 |
@param aServer Service the session will be a member of |
sl@0 | 32 |
@param aMessage The message from the client. |
sl@0 | 33 |
@return A new CUsbMassStorageSession object |
sl@0 | 34 |
*/ |
sl@0 | 35 |
CUsbMassStorageSession* CUsbMassStorageSession::NewL(CUsbMassStorageServer& aServer) |
sl@0 | 36 |
{ |
sl@0 | 37 |
CUsbMassStorageSession* r = new (ELeave) CUsbMassStorageSession(aServer); |
sl@0 | 38 |
CleanupStack::PushL(r); |
sl@0 | 39 |
r->ConstructL(); |
sl@0 | 40 |
CleanupStack::Pop(); |
sl@0 | 41 |
return r; |
sl@0 | 42 |
} |
sl@0 | 43 |
|
sl@0 | 44 |
/** |
sl@0 | 45 |
Constructor. |
sl@0 | 46 |
|
sl@0 | 47 |
@param aServer Service the session will be a member of |
sl@0 | 48 |
*/ |
sl@0 | 49 |
CUsbMassStorageSession::CUsbMassStorageSession(CUsbMassStorageServer& aServer) |
sl@0 | 50 |
: iUsbMsServer(aServer) |
sl@0 | 51 |
{ |
sl@0 | 52 |
__PRINT(_L("CUsbMassStorageSession::CUsbMassStorageSession\n")); |
sl@0 | 53 |
} |
sl@0 | 54 |
|
sl@0 | 55 |
|
sl@0 | 56 |
/** |
sl@0 | 57 |
2nd Phase Construction. |
sl@0 | 58 |
*/ |
sl@0 | 59 |
void CUsbMassStorageSession::ConstructL() |
sl@0 | 60 |
{ |
sl@0 | 61 |
iUsbMsServer.IncrementSessionCount(); |
sl@0 | 62 |
if (iUsbMsServer.SessionCount() > 1) |
sl@0 | 63 |
{ |
sl@0 | 64 |
__PRINT1(_L("\tiSessionCount: %d\n"), iUsbMsServer.SessionCount()); |
sl@0 | 65 |
// Only one session is allowed |
sl@0 | 66 |
User::Leave(KErrInUse); |
sl@0 | 67 |
} |
sl@0 | 68 |
} |
sl@0 | 69 |
|
sl@0 | 70 |
|
sl@0 | 71 |
/** |
sl@0 | 72 |
Destructor. |
sl@0 | 73 |
*/ |
sl@0 | 74 |
CUsbMassStorageSession::~CUsbMassStorageSession() |
sl@0 | 75 |
{ |
sl@0 | 76 |
iUsbMsServer.DecrementSessionCount(); |
sl@0 | 77 |
} |
sl@0 | 78 |
|
sl@0 | 79 |
/** |
sl@0 | 80 |
Called when a message is received from the client. |
sl@0 | 81 |
|
sl@0 | 82 |
@param aMessage Message received from the client |
sl@0 | 83 |
*/ |
sl@0 | 84 |
void CUsbMassStorageSession::ServiceL(const RMessage2& aMessage) |
sl@0 | 85 |
{ |
sl@0 | 86 |
DispatchMessageL(aMessage); |
sl@0 | 87 |
} |
sl@0 | 88 |
|
sl@0 | 89 |
/** |
sl@0 | 90 |
Handles the request (in the form of a the message) received from the client |
sl@0 | 91 |
|
sl@0 | 92 |
@internalTechnology |
sl@0 | 93 |
@param aMessage The received message |
sl@0 | 94 |
*/ |
sl@0 | 95 |
void CUsbMassStorageSession::DispatchMessageL(const RMessage2& aMessage) |
sl@0 | 96 |
{ |
sl@0 | 97 |
TInt ret = KErrNone; |
sl@0 | 98 |
|
sl@0 | 99 |
switch (aMessage.Function()) |
sl@0 | 100 |
{ |
sl@0 | 101 |
case EUsbMsStart: |
sl@0 | 102 |
ret = Start(aMessage); |
sl@0 | 103 |
break; |
sl@0 | 104 |
case EUsbMsStop: |
sl@0 | 105 |
ret = Stop(); |
sl@0 | 106 |
break; |
sl@0 | 107 |
case EUsbMsShutdown: |
sl@0 | 108 |
ret = Shutdown(); |
sl@0 | 109 |
break; |
sl@0 | 110 |
|
sl@0 | 111 |
default: |
sl@0 | 112 |
aMessage.Panic(KUsbMsCliPncCat, EUsbMsPanicIllegalIPC); |
sl@0 | 113 |
break; |
sl@0 | 114 |
} |
sl@0 | 115 |
|
sl@0 | 116 |
aMessage.Complete(ret); |
sl@0 | 117 |
} |
sl@0 | 118 |
|
sl@0 | 119 |
/** |
sl@0 | 120 |
Client request to start the device. |
sl@0 | 121 |
|
sl@0 | 122 |
@return Any error that occurred or KErrNone |
sl@0 | 123 |
*/ |
sl@0 | 124 |
TInt CUsbMassStorageSession::Start(const RMessage2& aMessage) |
sl@0 | 125 |
{ |
sl@0 | 126 |
__PRINT(_L("CUsbMassStorageSession::Start\n")); |
sl@0 | 127 |
|
sl@0 | 128 |
TMassStorageConfig msConfig; |
sl@0 | 129 |
TRAPD(err, GetMsConfigL(aMessage, msConfig)); |
sl@0 | 130 |
if (err != KErrNone) |
sl@0 | 131 |
{ |
sl@0 | 132 |
__PRINT(_L("Failed to get mass storage configuration data\n")); |
sl@0 | 133 |
return err; |
sl@0 | 134 |
} |
sl@0 | 135 |
|
sl@0 | 136 |
return iUsbMsServer.Controller().Start(msConfig); |
sl@0 | 137 |
} |
sl@0 | 138 |
|
sl@0 | 139 |
/** |
sl@0 | 140 |
Client request to stop the device. |
sl@0 | 141 |
|
sl@0 | 142 |
@return Any error that occurred or KErrNone |
sl@0 | 143 |
*/ |
sl@0 | 144 |
TInt CUsbMassStorageSession::Stop() |
sl@0 | 145 |
{ |
sl@0 | 146 |
__PRINT(_L("CUsbMassStorageSession::Stop\n")); |
sl@0 | 147 |
TInt err = iUsbMsServer.Controller().Stop(); |
sl@0 | 148 |
return err; |
sl@0 | 149 |
} |
sl@0 | 150 |
|
sl@0 | 151 |
/** |
sl@0 | 152 |
Client request to shut down the server |
sl@0 | 153 |
|
sl@0 | 154 |
@return KErrNone |
sl@0 | 155 |
*/ |
sl@0 | 156 |
TInt CUsbMassStorageSession::Shutdown() |
sl@0 | 157 |
{ |
sl@0 | 158 |
__PRINT(_L("CUsbMassStorageSession::Shutdown\n")); |
sl@0 | 159 |
CActiveScheduler::Stop(); |
sl@0 | 160 |
return KErrNone; |
sl@0 | 161 |
} |
sl@0 | 162 |
|
sl@0 | 163 |
/** |
sl@0 | 164 |
Get mass storage configuration data from the received message |
sl@0 | 165 |
*/ |
sl@0 | 166 |
void CUsbMassStorageSession::GetMsConfigL(const RMessage2& aMessage, TMassStorageConfig& aMsStorage) |
sl@0 | 167 |
{ |
sl@0 | 168 |
aMessage.ReadL(0,aMsStorage.iVendorId); |
sl@0 | 169 |
aMessage.ReadL(1,aMsStorage.iProductId); |
sl@0 | 170 |
aMessage.ReadL(2,aMsStorage.iProductRev); |
sl@0 | 171 |
} |