|
1 // Copyright (c) 2005-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 "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 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @internalComponent |
|
19 */ |
|
20 |
|
21 #ifndef AVCTPMUXER_H |
|
22 #define AVCTPMUXER_H |
|
23 |
|
24 #include <es_prot.h> |
|
25 #include <e32hashtab.h> |
|
26 #include "avctpconstants.h" |
|
27 #include "avctpcommon.h" |
|
28 |
|
29 class CAvctpPacketMgr; |
|
30 class CAvctpProtocol; |
|
31 class CBluetoothSAP; |
|
32 class TAvctpMuxerState; |
|
33 class TAvctpStateClosed; |
|
34 class TAvctpStateLinkPending; |
|
35 class TAvctpStateOpen; |
|
36 |
|
37 class MSecondChannelPseudoSocketNotify; |
|
38 class TClientItem; |
|
39 |
|
40 typedef THashMapIter<TInt, const TClientItem*> TClientItemIter; |
|
41 |
|
42 class TAvctpSecondChannelPseudoSocket : public MSocketNotify |
|
43 { |
|
44 public: |
|
45 TAvctpSecondChannelPseudoSocket(MSecondChannelPseudoSocketNotify& aNotify); |
|
46 private: |
|
47 // Pure virtuals From MSocketNotify |
|
48 // Made private so that only people accessing this class through the M- base class |
|
49 // can get at them since these methods are public in the M- class. |
|
50 void NewData(TUint aCount); |
|
51 void CanSend(); |
|
52 void ConnectComplete(); |
|
53 void ConnectComplete(const TDesC8& /*aConnectData*/); |
|
54 void ConnectComplete(CServProviderBase& aSSP); |
|
55 void ConnectComplete(CServProviderBase& /*aSSP*/,const TDesC8& /*aConnectData*/); |
|
56 void CanClose(TDelete aDelete); |
|
57 void CanClose(const TDesC8& /*aDisconnectData*/,TDelete /*aDelete*/); |
|
58 void Error(TInt aError, TUint aOperationMask); |
|
59 void Disconnect(); |
|
60 void Disconnect(TDesC8& /*aDisconnectData*/) {/*drop*/}; |
|
61 void IoctlComplete(TDesC8* /*aBuf*/); |
|
62 void NoBearer(const TDesC8& /*aConnectionInfo*/) {/*drop*/}; |
|
63 void Bearer(const TDesC8& /*aConnectionInfo*/) {/*drop*/}; |
|
64 |
|
65 private: |
|
66 MSecondChannelPseudoSocketNotify& iNotify; |
|
67 }; |
|
68 |
|
69 |
|
70 /* |
|
71 This class doesn't derive from MSocketNotify, so it has only the methods we need to be implemented. |
|
72 */ |
|
73 |
|
74 class MSecondChannelPseudoSocketNotify |
|
75 { |
|
76 public: |
|
77 virtual void MbpsnNewData(TUint aCount) =0; |
|
78 virtual void MbpsnCanSend() =0; |
|
79 virtual void MbpsnConnectComplete() =0; |
|
80 virtual void MbpsnConnectComplete(CServProviderBase& aSAP) =0; |
|
81 virtual void MbpsnCanClose(MSocketNotify::TDelete aDelete=MSocketNotify::EDelete) =0; |
|
82 virtual void MbpsnError(TInt aError, TUint aOperationMask=MSocketNotify::EErrorAllOperations) =0; |
|
83 virtual void MbpsnDisconnect() =0; |
|
84 }; |
|
85 |
|
86 /** |
|
87 Acts as the "channel management entity". |
|
88 |
|
89 There is one of these per remote device, as only one L2CAP connection |
|
90 can exist between two devices for AVCTP. This class acts as an internal |
|
91 socket binding to a lower level SAP. Thus we derive from MSocketNotify |
|
92 so that SAP can directly notify us of events. |
|
93 |
|
94 Even though in the current usage of AVCTP via RAvctp, this class will not |
|
95 be managed by a CSubConnection class in ESOCK, it is a CFactoryObject and |
|
96 hence will be the responsibility of the CSubConnectionProviderFactoryBase |
|
97 to delete. |
|
98 |
|
99 This class leaves the data handling completely up to CAvctpSap. All it does |
|
100 is provide a path for the data. The only slightly clever thing it does is |
|
101 get any data that the lower protocol sap indicates has arrived (NewData upcall) |
|
102 and gives this to the protocol for distribution to the relevant CAvctpSap. |
|
103 So data to send is pushed from the Sap to the Muxer and data received is |
|
104 pushed from the Muxer to the Sap. |
|
105 |
|
106 Note that this class doesn't currently support ioctls on the lower protocol |
|
107 sap below. |
|
108 |
|
109 @internalComponent |
|
110 @see MSocketNotify |
|
111 */ |
|
112 NONSHARABLE_CLASS(CAvctpTransport) : public CBase, public MSocketNotify, public MSecondChannelPseudoSocketNotify |
|
113 { |
|
114 friend class CAvctpProtocol; // needed for iQueLink access |
|
115 |
|
116 // States can all be friends if they want to be ;-) |
|
117 friend class TAvctpMuxerState; |
|
118 friend class TAvctpStateClosed; |
|
119 friend class TAvctpStateLinkPending; |
|
120 friend class TAvctpStateOpen; |
|
121 |
|
122 friend class TAvctpStateSecondChannelPending; |
|
123 friend class TAvctpStateFullyOpen; |
|
124 |
|
125 public: |
|
126 // Create/destroy |
|
127 static CAvctpTransport* NewL(CAvctpProtocol& aProt); |
|
128 |
|
129 // Start functions |
|
130 TInt Start(const TBTDevAddr& aAddr, TUint16 aClientId); // outgoing |
|
131 TInt StartIncoming(const TBTDevAddr& aAddr, CServProviderBase* aL2CAPConSAP); |
|
132 |
|
133 // Commands from the Avctp Sap |
|
134 TInt Send(const RMBufChain& aData, TInt aChannel); |
|
135 |
|
136 inline const TBTDevAddr& DevAddr() const; |
|
137 inline TBool IsClearToSend(TInt aChannel) const; |
|
138 inline CAvctpPacketMgr& PacketMgr(); |
|
139 |
|
140 TBool HasDataToSend(); |
|
141 void Shutdown(TInt aError); |
|
142 TInt GetCurrentInboundMtu(TInt aChannel); |
|
143 TInt GetCurrentOutboundMtu(TInt aChannel); |
|
144 TInt DoWrite(RMBufChain& aPDU, TInt aChannel); |
|
145 |
|
146 void CheckForIdle(); |
|
147 |
|
148 void NotifyAttachConfirm(TInt aError, TBool aIsSecondChannel); |
|
149 void NotifyAttachConfirm(TUint16 aClientId, TInt aError, TBool aIsSecondChannel); |
|
150 void NotifyDetachConfirm(TUint16 aClientId, TInt aError, TBool aOnlySecondChannel = EFalse); |
|
151 void NotifyLinkError(TInt aError, TBool aIsSecondChannel); |
|
152 |
|
153 TInt AddSecondChannel(CServProviderBase& aSAP); |
|
154 TBool HasSecondChannel() const; |
|
155 void RemoveSecondChannel(); |
|
156 |
|
157 void NotifyLinkUp(const TBTDevAddr& aAddr, TBool aIsSecondChannel = EFalse); |
|
158 void NotifyLinkDown(const TBTDevAddr& aAddr, TBool aIsSecondChannel = EFalse, TInt aError = KErrNone); |
|
159 TInt GetChannelMtu(TInt aChannel, TInt& aMtu) const; |
|
160 |
|
161 void SetSecondChannelCtrlNotify(TUint16 aClientId, MSocketNotify& aSecondChannelControlSocket); |
|
162 TInt AddPrimaryChannelRef(const TClientItem* aItem); |
|
163 void RemovePrimaryChannelRef(TUint16 aClientId); |
|
164 void AddSecondaryChannelRef(); |
|
165 void RemoveSecondaryChannelRef(TUint16 aClientId); |
|
166 TInt ClientCount(); |
|
167 TInt ClientSecondaryChannelCount(); |
|
168 TBool HasClient(TUint16 aClientId); |
|
169 void BindSecondaryChannelSap(CServProviderBase& aSAP); |
|
170 private: |
|
171 ~CAvctpTransport(); |
|
172 // Pure virtuals From MSocketNotify |
|
173 // Made private so that only people accessing this class through the M- base class |
|
174 // can get at them since these methods are public in the M- class. |
|
175 void NewData(TUint aCount); |
|
176 void CanSend(); |
|
177 void ConnectComplete(); |
|
178 void ConnectComplete(const TDesC8& aConnectData); |
|
179 void ConnectComplete(CServProviderBase& aSSP); |
|
180 void ConnectComplete(CServProviderBase& aSSP,const TDesC8& aConnectData); |
|
181 void CanClose(TDelete aDelete=EDelete); |
|
182 void CanClose(const TDesC8& aDisconnectData,TDelete aDelete=EDelete); |
|
183 void Error(TInt aError, TUint aOperationMask=EErrorAllOperations); |
|
184 void Disconnect(void); |
|
185 void Disconnect(TDesC8& aDisconnectData); |
|
186 void IoctlComplete(TDesC8* aBuf); |
|
187 void NoBearer(const TDesC8& /*aConnectionInfo*/) {}; |
|
188 void Bearer(const TDesC8& /*aConnectionInfo*/) {}; |
|
189 |
|
190 private: |
|
191 virtual void MbpsnNewData(TUint aCount); |
|
192 virtual void MbpsnCanSend(); |
|
193 virtual void MbpsnConnectComplete(); |
|
194 virtual void MbpsnConnectComplete(CServProviderBase& aSAP); |
|
195 virtual void MbpsnCanClose(MSocketNotify::TDelete aDelete=MSocketNotify::EDelete); |
|
196 virtual void MbpsnError(TInt aError, TUint aOperationMask=MSocketNotify::EErrorAllOperations); |
|
197 virtual void MbpsnDisconnect(); |
|
198 |
|
199 private: |
|
200 CAvctpTransport(CAvctpProtocol& aProtocol); |
|
201 void ConstructL(); |
|
202 |
|
203 // Utility Functions |
|
204 void AssignToDevice(const TBTDevAddr& aRemoteAddr); |
|
205 // Management functions for iIsClearToSend |
|
206 inline void SetSendBlocked(TInt aChannel); |
|
207 inline void SetClearToSend(TInt aChannel); |
|
208 |
|
209 // NewData Callback functions |
|
210 static TInt SecondChannelNewDataAsyncCallBack(TAny* aMuxer); |
|
211 inline void StartSecondChannelNewDataAsyncCallBack(); |
|
212 inline void CancelSecondChannelNewDataAsyncCallBack(); |
|
213 |
|
214 // Idle Functions |
|
215 TBool IsIdle(); |
|
216 void QueIdleTimer(); |
|
217 void DequeIdleTimer(); |
|
218 static TInt IdleTimerExpired(TAny* aMux); |
|
219 void NotifyLinkState(const TBTDevAddr& aAddr, SymbianAvctp::TControlIoctls aIoctl, TInt aChannel, TInt aError); |
|
220 |
|
221 private: |
|
222 static const TUint KMaxChannels = 2; |
|
223 |
|
224 CAvctpProtocol& iProtocol; /** The avctp protocol object */ |
|
225 |
|
226 /** Endpoints in the lower protocol over which we are communicating (normally L2CAP) */ |
|
227 TFixedArray<CServProviderBase*, KMaxChannels> iChannelSAPs; |
|
228 |
|
229 TAvctpSecondChannelPseudoSocket iSecondChannelSocket; |
|
230 |
|
231 TAvctpMuxerState* iState; /** The current state */ |
|
232 TBTDevAddr iRemoteAddr; /** The Bluetooth address of the remote device */ |
|
233 TDeltaTimerEntry iIdleTimerEntry; /** Disconnection idle timer */ |
|
234 TBool iIdleTimerQueued; /** Whether we have an idle timer queued */ |
|
235 |
|
236 TDblQueLink iQueLink; /** A link so that the protocol can queue multiplexors */ |
|
237 |
|
238 TFixedArray<TBool,2> iIsClearToSend; |
|
239 |
|
240 // Incoming data asyncs for second channel |
|
241 CAsyncCallBack* iNewDataAsyncCallBack; /** Async Callback to get New Data from L2CAP */ |
|
242 TUint iSecondChannelPacketsWaiting; /** The number of packets waiting for us to pick up from L2CAP */ |
|
243 |
|
244 CAvctpPacketMgr* iPacketMgr; |
|
245 RHashMap<TInt, const TClientItem*> iClientItems; |
|
246 TBTDevAddr iAddress; |
|
247 TInt iSecondaryChannelClientRefCount; |
|
248 }; |
|
249 |
|
250 |
|
251 |
|
252 #include "avctpmuxer.inl" |
|
253 |
|
254 #endif |
|
255 // AVCTPMUXER_H |
|
256 |