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