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