|
1 /** |
|
2 * Copyright (c) 1997-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 * Implements a Session of a Symbian OS server for the RUsb API |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 /** |
|
23 @file |
|
24 */ |
|
25 |
|
26 #ifndef __CUSBSESSION_H__ |
|
27 #define __CUSBSESSION_H__ |
|
28 |
|
29 #include <e32std.h> |
|
30 #include "MUsbDeviceNotify.h" |
|
31 #include <usb/usbshared.h> |
|
32 |
|
33 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
|
34 #include "musbotghostnotifyobserver.h" |
|
35 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
|
36 |
|
37 // device event queue size is number of device states + 1 |
|
38 // (+1 so we can distinguish full & empty!) |
|
39 // (any state can only appear in the queue once) |
|
40 const TInt KDeviceStatesQueueSize = KUsbDeviceStates + 1; |
|
41 const TInt KOtgHostMessageQueueSize = KDeviceStatesQueueSize * 2; |
|
42 |
|
43 // |
|
44 // Forward declarations |
|
45 // |
|
46 class CUsbServer; |
|
47 |
|
48 /** |
|
49 * The CUsbSession class |
|
50 * |
|
51 * Implements a Session of a Symbian OS server for the RUsb API |
|
52 */ |
|
53 NONSHARABLE_CLASS(CUsbSession) : public CSession2 |
|
54 , public MUsbDeviceNotify |
|
55 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
|
56 , public MUsbOtgHostNotifyObserver |
|
57 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
|
58 { |
|
59 public: |
|
60 static CUsbSession* NewL(CUsbServer* aServer); |
|
61 virtual ~CUsbSession(); |
|
62 |
|
63 // CSession2 |
|
64 virtual void ServiceL(const RMessage2& aMessage); |
|
65 virtual void CreateL(); |
|
66 |
|
67 // MUsbDeviceNotify |
|
68 virtual void UsbDeviceStateChange(TInt aLastError, TUsbDeviceState aOldState, TUsbDeviceState aNewState); |
|
69 virtual void UsbServiceStateChange(TInt aLastError, TUsbServiceState aOldState, TUsbServiceState aNewState); |
|
70 |
|
71 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
|
72 // MUsbOtgHostNotifyObserver |
|
73 virtual void UsbOtgHostMessage(TInt aMessage); |
|
74 virtual void UsbHostEvent(TDeviceEventInformation& aDevInfo); |
|
75 |
|
76 TInt DoRequestSession(); |
|
77 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
|
78 |
|
79 protected: |
|
80 CUsbSession(CUsbServer* aServer); |
|
81 |
|
82 void DispatchMessageL(const RMessage2& aMessage); |
|
83 TInt StartDeviceL(const RMessage2& aMessage, TBool& aComplete); |
|
84 TInt StopDeviceL(const RMessage2& aMessage, TBool& aComplete); |
|
85 TInt StartCancel(const RMessage2& aMessage, TBool& aComplete); |
|
86 TInt StopCancel(const RMessage2& aMessage, TBool& aComplete); |
|
87 TInt RegisterDeviceObserver(const RMessage2& aMessage, TBool& aComplete); |
|
88 TInt RegisterServiceObserver(const RMessage2& aMessage, TBool& aComplete); |
|
89 TInt GetCurrentServiceState(const RMessage2& aMessage); |
|
90 TInt GetCurrentDeviceState(const RMessage2& aMessage); |
|
91 TInt DeRegisterServiceObserver(); |
|
92 TInt DeRegisterDeviceObserver(); |
|
93 TInt TryStartDeviceL(const RMessage2& aMessage, TBool& aComplete); |
|
94 TInt TryStopDeviceL(const RMessage2& aMessage, TBool& aComplete); |
|
95 TInt CancelInterest(const RMessage2& aMessage); |
|
96 TInt GetCurrentPersonalityId(const RMessage2& aMessage); |
|
97 TInt GetSupportedClasses(const RMessage2& aMessage); |
|
98 TInt GetPersonalityIds(const RMessage2& aMessage); |
|
99 TInt GetDescription(const RMessage2& aMessage); |
|
100 TInt GetDetailedDescription(const RMessage2& aMessage); |
|
101 TInt ClassSupported(const RMessage2& aMessage); |
|
102 TInt GetPersonalityProperty(const RMessage2& aMessage); |
|
103 |
|
104 void UsbDeviceDequeueEvent(); |
|
105 |
|
106 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
|
107 // Common functions |
|
108 TInt SetCtlSessionMode(const RMessage2& aMessage); |
|
109 TInt RegisterMsgObserver(const RMessage2& aMessage, TBool& aComplete); |
|
110 TInt DeRegisterMsgObserver(); |
|
111 |
|
112 // OTG |
|
113 TInt BusRequest(); |
|
114 TInt BusRespondSrp(); |
|
115 |
|
116 TInt BusClearError(); |
|
117 |
|
118 TInt BusDrop(); |
|
119 |
|
120 // HOST |
|
121 TInt EnableFunctionDriverLoading(); |
|
122 TInt DisableFunctionDriverLoading(); |
|
123 TInt GetSupportedLanguages(const RMessage2& aMessage); |
|
124 TInt GetManufacturerStringDescriptor(const RMessage2& aMessage); |
|
125 TInt GetProductStringDescriptor(const RMessage2& aMessage); |
|
126 TInt GetOtgDescriptor(const RMessage2& aMessage); |
|
127 |
|
128 TInt RegisterHostObserver(const RMessage2& aMessage, TBool& aComplete); |
|
129 TInt DeRegisterHostObserver(); |
|
130 TInt RequestSession(); |
|
131 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
|
132 |
|
133 private: |
|
134 void HandleServiceStateChangeWhileStarting(TInt aLastError, |
|
135 TUsbServiceState aNewState); |
|
136 void HandleServiceStateChangeWhileStopping(TInt aLastError, |
|
137 TUsbServiceState aNewState); |
|
138 |
|
139 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
|
140 void UsbMsgDequeue(); |
|
141 |
|
142 void UsbHostEventDequeue(); |
|
143 TInt GetSupportedLanguagesL(const RMessage2& aMessage); |
|
144 |
|
145 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
|
146 |
|
147 private: |
|
148 CUsbServer* iUsbServer; |
|
149 |
|
150 RMessage2 iStartMessage; |
|
151 RMessage2 iStopMessage; |
|
152 RMessage2 iCancelMessage; |
|
153 RMessage2 iServiceObserverMessage; |
|
154 RMessage2 iDeviceObserverMessage; |
|
155 |
|
156 TBool iStartOutstanding; |
|
157 TBool iStopOutstanding; |
|
158 TBool iCancelOutstanding; |
|
159 TBool iDeviceObserverOutstanding; |
|
160 TBool iServiceObserverOutstanding; |
|
161 TBool iPersonalityCfged; |
|
162 |
|
163 TFixedArray<TUsbDeviceState, KDeviceStatesQueueSize> iDeviceStateQueue; |
|
164 TUsbDeviceState iNotifiedDevState; |
|
165 TBool iObserverQueueEvents; |
|
166 TInt iDevStateQueueHead; |
|
167 TInt iDevStateQueueTail; |
|
168 |
|
169 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
|
170 static CUsbSession* iCtlSession; |
|
171 TBool iSessionCtlMode; |
|
172 |
|
173 RMessage2 iMsgObserverMessage; |
|
174 TBool iMsgObserverOutstanding; |
|
175 TFixedArray<TInt, KOtgHostMessageQueueSize> iMsgQueue; |
|
176 TBool iMsgObserverQueueEvents; |
|
177 TInt iMsgQueueHead; |
|
178 TInt iMsgQueueTail; |
|
179 TInt iNotifiedMsg; |
|
180 |
|
181 RMessage2 iHostEventObserverMessage; |
|
182 TBool iHostEventObserverOutstanding; |
|
183 TFixedArray<TDeviceEventInformation, KDeviceStatesQueueSize> iHostStateQueue; |
|
184 TBool iHostEventObserverQueueEvents; |
|
185 TInt iHostEventQueueHead; |
|
186 TInt iHostEventQueueTail; |
|
187 TDeviceEventInformation iNotifiedHostState; |
|
188 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
|
189 }; |
|
190 |
|
191 #endif //__CUSBSESSION_H__ |