|
1 /* |
|
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalComponent |
|
21 */ |
|
22 |
|
23 #include "msmmsession.h" |
|
24 #include "msmmserver.h" |
|
25 #include "msmmengine.h" |
|
26 #include "eventqueue.h" |
|
27 #include <usb/hostms/srverr.h> |
|
28 #include <usb/hostms/msmmpolicypluginbase.h> |
|
29 #include "msmmnodebase.h" |
|
30 #include <usb/usblogger.h> |
|
31 |
|
32 #ifdef __FLOG_ACTIVE |
|
33 _LIT8(KLogComponent, "UsbHostMsmmServer"); |
|
34 #endif |
|
35 |
|
36 CMsmmSession::~CMsmmSession() |
|
37 { |
|
38 LOG_FUNC |
|
39 delete iErrData; |
|
40 iServer.RemoveSession(); |
|
41 } |
|
42 |
|
43 CMsmmSession* CMsmmSession::NewL(CMsmmServer& aServer, |
|
44 CDeviceEventQueue& anEventQueue) |
|
45 { |
|
46 LOG_STATIC_FUNC_ENTRY |
|
47 CMsmmSession* self = new(ELeave) CMsmmSession(aServer, anEventQueue); |
|
48 CleanupStack::PushL(self); |
|
49 self->ConstructL(); |
|
50 CleanupStack::Pop(self); |
|
51 return self; |
|
52 } |
|
53 |
|
54 void CMsmmSession::ServiceL(const RMessage2& aMessage) |
|
55 { |
|
56 LOG_STATIC_FUNC_ENTRY |
|
57 TInt ret(KErrNone); |
|
58 |
|
59 #ifdef _DEBUG |
|
60 TInt* heapObj= NULL; |
|
61 #endif // _DEBUG |
|
62 |
|
63 switch (aMessage.Function()) |
|
64 { |
|
65 case EHostMsmmServerAddFunction: |
|
66 AddUsbMsInterfaceL(aMessage); |
|
67 break; |
|
68 |
|
69 case EHostMsmmServerRemoveDevice: |
|
70 RemoveUsbMsDeviceL(aMessage); |
|
71 break; |
|
72 |
|
73 // Supporting for server side OOM testing |
|
74 case EHostMsmmServerDbgFailNext: |
|
75 ret = KErrNone; |
|
76 #ifdef _DEBUG |
|
77 if (aMessage.Int0() == 0 ) |
|
78 { |
|
79 __UHEAP_RESET; |
|
80 } |
|
81 else |
|
82 { |
|
83 __UHEAP_FAILNEXT(aMessage.Int0()); |
|
84 } |
|
85 #endif // _DEBUG |
|
86 break; |
|
87 |
|
88 case EHostMsmmServerDbgAlloc: |
|
89 ret = KErrNone; |
|
90 #ifdef _DEBUG |
|
91 TRAP(ret, heapObj = new (ELeave) TInt); |
|
92 delete heapObj; |
|
93 #endif // _DEBUG |
|
94 break; |
|
95 |
|
96 default: |
|
97 // Unsupported function number - panic the client |
|
98 PanicClient(aMessage, EBadRequest); |
|
99 } |
|
100 |
|
101 // Complete the request |
|
102 aMessage.Complete(ret); |
|
103 } |
|
104 |
|
105 void CMsmmSession::ServiceError(const RMessage2 &aMessage, TInt aError) |
|
106 { |
|
107 LOG_FUNC |
|
108 CMsmmPolicyPluginBase* plugin = iServer.PolicyPlugin(); |
|
109 TUSBMSDeviceDescription& device = iDevicePkg(); |
|
110 |
|
111 switch (aError) |
|
112 { |
|
113 case KErrNoMemory: |
|
114 iErrData->iError = EHostMsErrOutOfMemory; |
|
115 break; |
|
116 case KErrArgument: |
|
117 iErrData->iError = EHostMsErrInvalidParameter; |
|
118 break; |
|
119 case KErrNotFound: |
|
120 iErrData->iError = EHostMsErrInvalidParameter; |
|
121 break; |
|
122 default: |
|
123 iErrData->iError = EHostMsErrGeneral; |
|
124 } |
|
125 |
|
126 iErrData->iE32Error = aError; |
|
127 iErrData->iManufacturerString = device.iManufacturerString; |
|
128 iErrData->iProductString = device.iProductString; |
|
129 iErrData->iDriveName = 0x0; |
|
130 |
|
131 TInt err(KErrNone); |
|
132 TRAP(err, plugin->SendErrorNotificationL(*iErrData)); |
|
133 aMessage.Complete(aError); |
|
134 } |
|
135 |
|
136 CMsmmSession::CMsmmSession(CMsmmServer& aServer, |
|
137 CDeviceEventQueue& anEventQueue) : |
|
138 iServer(aServer), |
|
139 iEngine(aServer.Engine()), |
|
140 iEventQueue(anEventQueue) |
|
141 { |
|
142 LOG_FUNC |
|
143 aServer.AddSession(); |
|
144 } |
|
145 |
|
146 void CMsmmSession::ConstructL() |
|
147 { |
|
148 LOG_FUNC |
|
149 iErrData = new (ELeave) THostMsErrData; |
|
150 } |
|
151 |
|
152 void CMsmmSession::AddUsbMsInterfaceL(const RMessage2& aMessage) |
|
153 { |
|
154 LOG_FUNC |
|
155 aMessage.Read(0, iDevicePkg); |
|
156 iInterfaceNumber = aMessage.Int1(); |
|
157 iInterfaceToken = static_cast<TInt32>(aMessage.Int2()); |
|
158 TUSBMSDeviceDescription& device = iDevicePkg(); |
|
159 |
|
160 // Put currently adding USB MS function related device |
|
161 // information into engine |
|
162 iEngine.AddUsbMsDeviceL(device); |
|
163 |
|
164 // Put device event into queue |
|
165 TDeviceEvent event(EDeviceEventAddFunction, |
|
166 device.iDeviceId, iInterfaceNumber, iInterfaceToken); |
|
167 iEventQueue.PushL(event); |
|
168 } |
|
169 |
|
170 void CMsmmSession::RemoveUsbMsDeviceL(const RMessage2& aMessage) |
|
171 { |
|
172 LOG_FUNC |
|
173 iDeviceID = aMessage.Int0(); |
|
174 |
|
175 // Put device event into queue |
|
176 TDeviceEvent event(EDeviceEventRemoveDevice, iDeviceID, 0, 0); |
|
177 iEventQueue.PushL(event); |
|
178 } |
|
179 |
|
180 // End of file |