|
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 "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 @publishedAll |
|
19 @released |
|
20 */ |
|
21 |
|
22 #ifndef REMCONINTERFACESELECTOR_H |
|
23 #define REMCONINTERFACESELECTOR_H |
|
24 |
|
25 #include <e32base.h> |
|
26 #include <remcon/messagetype.h> |
|
27 #include <remcon/clienttype.h> |
|
28 #include <remcon/playertype.h> |
|
29 #include <remcon/remconinterfaceif.h> |
|
30 #include <remconaddress.h> |
|
31 |
|
32 class CRemConInterfaceBase; |
|
33 class CBulkReceiver; |
|
34 class CReceiver; |
|
35 class MRemConErrorObserver; |
|
36 class RRemConInterfaceFeatures; |
|
37 class RSpecificThreadCallBack; |
|
38 class CRemConInterfaceDetailsArray; |
|
39 class RNestableLock; |
|
40 class RRemConController; |
|
41 class RRemConTarget; |
|
42 class RRemConBulk; |
|
43 class RRemCon; |
|
44 |
|
45 // Panic information |
|
46 _LIT(KRemConIfSelPanicCat, "RemConIfSel"); |
|
47 enum |
|
48 { |
|
49 /** The client has given a bad message type. */ |
|
50 ERemConIfSelBadMessageType = 0, |
|
51 |
|
52 /** The client has already called OpenTargetL successfully. |
|
53 |
|
54 This is no longer an illegal condition and so the panic will never |
|
55 be raised. |
|
56 */ |
|
57 ERemConIfSelTargetSessionAlreadyExists = 1, |
|
58 |
|
59 /** The client has already called OpenControllerL successfully. |
|
60 |
|
61 This is no longer an illegal condition and so the panic will never |
|
62 be raised. |
|
63 */ |
|
64 ERemConIfSelControllerSessionAlreadyExists = 2, |
|
65 |
|
66 /** The client has created (and registered) an outer layer interface of a |
|
67 type which is already registered. */ |
|
68 ERemConIfSelInterfaceOfThatTypeAlreadyRegistered = 3, |
|
69 |
|
70 /** The client has not offended- there is a defect in some layer of the |
|
71 Remote Control system. */ |
|
72 ERemConIfSelInternalError = 4, |
|
73 |
|
74 /** An outer-layer interface has been instantiated (and registered with |
|
75 the intermediate layer) after OpenControllerL or OpenTargetL has been |
|
76 successfully called. */ |
|
77 ERemConIfSelTardyInterfaceRegistration = 5, |
|
78 |
|
79 /** OpenControllerL has not successfully been called before using an API |
|
80 which expects a controller session to have been created. */ |
|
81 ERemConIfSelNoControllerSession = 6, |
|
82 |
|
83 /** OpenTargetL has not successfully been called before using an API which |
|
84 expects a target session to have been created. */ |
|
85 ERemConIfSelNoTargetSession = 7, |
|
86 |
|
87 /** Neither OpenControllerL not OpenTargetL has been successfully called |
|
88 before using an API which expects either a controller or a target session |
|
89 to have been created. */ |
|
90 ERemConIfSelNoSession = 8, |
|
91 |
|
92 /** An outer layer DLL has instantiated CRemConInterfaceBase with an |
|
93 illegal client type. */ |
|
94 ERemConIfSelUndefinedClientType = 9, |
|
95 |
|
96 /** An implementation of CRemConInterfaceBase::GetInterface does not |
|
97 provide an implementation of MRemConInterfaceIf. */ |
|
98 ERemConIfSelNoInterfaceImplementation = 10, |
|
99 |
|
100 /** A client has created bulk interfaces in multiple different threads, |
|
101 all bulk interfaces must be created in the same thread*/ |
|
102 ERemConIfSelMultipleBulkInterfaceThreads = 11, |
|
103 }; |
|
104 |
|
105 /** |
|
106 CRemConInterfaceSelector is only instantiable via its NewL function. It is not |
|
107 derivable. |
|
108 */ |
|
109 NONSHARABLE_CLASS(CRemConInterfaceSelector) : public CBase |
|
110 { |
|
111 public: |
|
112 /** |
|
113 Factory method. |
|
114 @return Ownership of a new CRemConInterfaceSelector. |
|
115 */ |
|
116 IMPORT_C static CRemConInterfaceSelector* NewL(); |
|
117 |
|
118 /** Destructor. */ |
|
119 IMPORT_C ~CRemConInterfaceSelector(); |
|
120 |
|
121 public: |
|
122 /** |
|
123 Register the interface with the selector. This is called by the |
|
124 interface's BaseConstructL. Takes ownership of aInterface. |
|
125 This function is not to be called outside of remconinterfacebase.dll. It is available for compatibility with previous |
|
126 versions, but it is intended to be called only by CRemConInterfaceBase::BaseConstructL. |
|
127 CRemConInterfaceBase-derived classes should indirectly perform a RegisterInterfaceL, by calling |
|
128 CRemConInterfaceBase::BaseConstructL from their construction functions. |
|
129 @param aInterface The interface. |
|
130 */ |
|
131 IMPORT_C void RegisterInterfaceL(CRemConInterfaceBase& aInterface); |
|
132 |
|
133 /** |
|
134 Register the interface with the selector. This is called by the |
|
135 interface's BaseConstructL. Takes ownership of aInterface. |
|
136 This function is not to be called outside of remconinterfacebase.dll. It is available for compatibility with previous |
|
137 versions, but it is intended to be called only by CRemConInterfaceBase::BaseConstructL. |
|
138 CRemConInterfaceBase-derived classes should indirectly perform a RegisterInterfaceL, by calling |
|
139 CRemConInterfaceBase::BaseConstructL from their construction functions. |
|
140 @param aInterface The interface. |
|
141 @param aRemConInterfaceFeatures The operation IDs of the interface. Ownership is retained by the caller. Any necessary |
|
142 data will be copied by the interface selector. |
|
143 */ |
|
144 void RegisterInterfaceL(CRemConInterfaceBase& aInterface, RRemConInterfaceFeatures& aRemConInterfaceFeatures); |
|
145 /** |
|
146 Register an error observer. This is provided to allow the client to |
|
147 discover when an error has occurred passively. |
|
148 |
|
149 @param aObserver An error observer to be notified on a passive error. |
|
150 NULL to stop receiving notifications. |
|
151 */ |
|
152 IMPORT_C void RegisterErrorObserver(MRemConErrorObserver* aObserver); |
|
153 |
|
154 /** |
|
155 Opens a controller session to RemCon. The session is connectionless until |
|
156 such time as GoConnectionOriented may be called. |
|
157 @leave KErrInUse If a controller session is already open. |
|
158 */ |
|
159 IMPORT_C void OpenControllerL(); |
|
160 |
|
161 /** |
|
162 Makes the controller session (which must already exist- use |
|
163 OpenControllerL) connection-oriented. |
|
164 @param aConnection The remote to talk to. |
|
165 */ |
|
166 IMPORT_C void GoConnectionOrientedL(const TRemConAddress& aConnection); |
|
167 |
|
168 /** |
|
169 Makes the controller session (which must already exist- use |
|
170 OpenControllerL) connectionless. |
|
171 */ |
|
172 IMPORT_C void GoConnectionlessL(); |
|
173 |
|
174 /** |
|
175 Brings up a bearer-level connection. |
|
176 The controller session must already exist (use OpenControllerL) and |
|
177 be connection-oriented. |
|
178 @param aStatus TRequestStatus for asynchronous completion. |
|
179 */ |
|
180 IMPORT_C void ConnectBearer(TRequestStatus& aStatus); |
|
181 |
|
182 /** |
|
183 Cancels interest in the completion of a ConnectBearer request. |
|
184 @return KErrNone. |
|
185 */ |
|
186 IMPORT_C TInt ConnectBearerCancel(); |
|
187 |
|
188 /** |
|
189 Destroys a bearer-level connection. |
|
190 The controller session must already exist (use OpenControllerL) and be |
|
191 connection-oriented. |
|
192 @param aStatus TRequestStatus for asynchronous completion. |
|
193 */ |
|
194 IMPORT_C void DisconnectBearer(TRequestStatus& aStat); |
|
195 |
|
196 /** |
|
197 Cancels interest in the completion of a DisconnectBearer request. |
|
198 @return KErrNone. |
|
199 */ |
|
200 IMPORT_C TInt DisconnectBearerCancel(); |
|
201 |
|
202 /** |
|
203 Opens a target session to RemCon. |
|
204 @leave KErrInUse If a target session is already open. |
|
205 */ |
|
206 IMPORT_C void OpenTargetL(); |
|
207 |
|
208 /** |
|
209 Opens a target session to RemCon. |
|
210 @param aPlayerType The type of player |
|
211 @param aPlayerSubType The sub-type of the player |
|
212 @param aPlayerName The name of the player in UTF-8. |
|
213 @leave KErrInUse If a target session is already open. |
|
214 */ |
|
215 IMPORT_C void OpenTargetL(TPlayerType aPlayerType, TPlayerSubType aPlayerSubType, const TDesC8& aPlayerName); |
|
216 /** |
|
217 Sends a message to the remote device(s). |
|
218 There should be only one command and response outstanding at any one time. |
|
219 Send cannot be called again until aStatus is completed. |
|
220 @panic RemConClient 4 If a send is already outstanding |
|
221 @param aStatus TRequestStatus for asynchronous completion. |
|
222 @param aInterfaceUid The UID of the concrete (outer-layer) interface |
|
223 sending the message. |
|
224 @param aOperationId The interface-specific operation identifier. |
|
225 @param aNumRemotes On success, the number of remotes the message was |
|
226 successfully sent to. |
|
227 @param aMsgType Whether the message is a command or a response. |
|
228 @param aData Any associated message data in interface-specific format. |
|
229 */ |
|
230 IMPORT_C void Send(TRequestStatus& aStatus, |
|
231 TUid aInterfaceUid, |
|
232 TUint aOperationId, |
|
233 TUint& aNumRemotes, |
|
234 TRemConMessageType aMsgType, |
|
235 const TDesC8& aData = KNullDesC8()); |
|
236 |
|
237 /** |
|
238 Sends a message to the remote device(s). |
|
239 @param aStatus TRequestStatus for asynchronous completion. |
|
240 @param aInterfaceUid The UID of the concrete (outer-layer) interface |
|
241 sending the message. |
|
242 @param aOperationId The interface-specific operation identifier. |
|
243 @param aNumRemotes On success, the number of remotes the message was |
|
244 successfully sent to. |
|
245 @param aMsgType Whether the message is a command or a response. |
|
246 @param aMsgSubType The subtype of the command of response |
|
247 @param aData Any associated message data in interface-specific format. |
|
248 */ |
|
249 IMPORT_C void Send(TRequestStatus& aStatus, |
|
250 TUid aInterfaceUid, |
|
251 TUint aOperationId, |
|
252 TUint& aNumRemotes, |
|
253 TRemConMessageType aMsgType, |
|
254 TRemConMessageSubType aMsgSubType, |
|
255 const TDesC8& aData = KNullDesC8()); |
|
256 |
|
257 /** |
|
258 Sends a |
|
259 */ |
|
260 IMPORT_C void SendNotify(TRequestStatus& aStatus, |
|
261 TUid aInterfaceUid, |
|
262 TUint aOperationId, |
|
263 TRemConMessageType aMsgType, |
|
264 TRemConMessageSubType aMsgSubType, |
|
265 const TDesC8& aData = KNullDesC8()); |
|
266 |
|
267 /** |
|
268 This method is for internal sub-system use only and should be not be used otherwise. |
|
269 Sends a message to the remote device(s), without waiting for the send to complete |
|
270 @param aInterfaceUid The UID of the concrete (outer-layer) interface |
|
271 sending the message. |
|
272 @param aOperationId The interface-specific operation identifier. |
|
273 @param aMsgType Whether the message is a command or a response. |
|
274 @param aData Any associated message data in interface-specific format. |
|
275 */ |
|
276 IMPORT_C TInt SendUnreliable( |
|
277 TUid aInterfaceUid, |
|
278 TUint aOperationId, |
|
279 TRemConMessageType aMsgType, |
|
280 const TDesC8& aData = KNullDesC8()); |
|
281 |
|
282 /** |
|
283 This method is for internal sub-system use only and should be not be used otherwise. |
|
284 Sends a message to the remote device(s), without waiting for the send to complete |
|
285 @param aInterfaceUid The UID of the concrete (outer-layer) interface |
|
286 sending the message. |
|
287 @param aOperationId The interface-specific operation identifier. |
|
288 @param aMsgType Whether the message is a command or a response. |
|
289 @param aMsgSubType The subtype of the command of response |
|
290 @param aData Any associated message data in interface-specific format. |
|
291 */ |
|
292 IMPORT_C TInt SendUnreliable( |
|
293 TUid aInterfaceUid, |
|
294 TUint aOperationId, |
|
295 TRemConMessageType aMsgType, |
|
296 TRemConMessageSubType aMsgSubType, |
|
297 const TDesC8& aData = KNullDesC8()); |
|
298 |
|
299 /** |
|
300 Cancels interest in the completion of a Send request. |
|
301 @param aMsgType The type of the message, the completion of the send of |
|
302 which we are not interested in. This is needed because a single |
|
303 CRemConInterfaceSelector may have two sends outstanding at once, one on |
|
304 a controller session and another on a target session. |
|
305 @return KErrNone. |
|
306 */ |
|
307 IMPORT_C TInt SendCancel(TRemConMessageType aMsgType); |
|
308 |
|
309 /** |
|
310 This method is for internal sub-system use only and should be not be used otherwise. |
|
311 Sends a message to the remote device(s) through the bulk path. |
|
312 There should be only one response outstanding at any one time. |
|
313 Send cannot be called again until aStatus is completed. |
|
314 @panic RemConClient 4 If a send is already outstanding |
|
315 @param aStatus TRequestStatus for asynchronous completion. |
|
316 @param aInterfaceUid The UID of the concrete (outer-layer) interface |
|
317 sending the message. |
|
318 @param aOperationId The interface-specific operation identifier. |
|
319 @param aData Any associated message data in interface-specific format. |
|
320 */ |
|
321 IMPORT_C void SendBulk(TRequestStatus& aStatus, |
|
322 TUid aInterfaceUid, |
|
323 TUint aOperationId, |
|
324 const TDesC8& aData = KNullDesC8()); |
|
325 |
|
326 /** |
|
327 This method is for internal sub-system use only and should be not be used otherwise. |
|
328 Sends a message to the remote device(s) through the bulk path, without |
|
329 waiting for the send to complete. |
|
330 @param aInterfaceUid The UID of the concrete (outer-layer) interface |
|
331 sending the message. |
|
332 @param aOperationId The interface-specific operation identifier. |
|
333 @param aData Any associated message data in interface-specific format. |
|
334 */ |
|
335 IMPORT_C TInt SendBulkUnreliable( |
|
336 TUid aInterfaceUid, |
|
337 TUint aOperationId, |
|
338 const TDesC8& aData = KNullDesC8()); |
|
339 |
|
340 /** |
|
341 This method is for internal sub-system use only and should be not be used otherwise. |
|
342 Cancels interest in the completion of a BulkSend request. |
|
343 @return KErrNone. |
|
344 */ |
|
345 IMPORT_C TInt SendBulkCancel(); |
|
346 |
|
347 /** |
|
348 Only called internally, by the Active Object which sucks messages out of |
|
349 RemCon. Note that the message type is not given- it is interpolated from |
|
350 the type of the session doing the receiving. |
|
351 @param aInterfaceUid Interface UID of the new message. |
|
352 @param aOperationId Operation ID of the new message. |
|
353 @param aMsgSubType The message subtype. |
|
354 @param aRemoteAddress The address of the remote which sent the message. |
|
355 @param aData Data associated with the new message. |
|
356 @param aType The type of session which received the message (from which |
|
357 the type of the message can be interpolated). |
|
358 */ |
|
359 void ReceiveComplete(TUid aInterfaceUid, |
|
360 TUint aOperationId, |
|
361 TRemConMessageSubType aMsgSubType, |
|
362 const TRemConAddress& aRemoteAddress, |
|
363 const TDesC8& aData, |
|
364 TRemConClientType aType); |
|
365 |
|
366 /** |
|
367 Only called internally, by the Active Object which sucks messages out of |
|
368 RemCon. Note that the message type is not given- it is interpolated from |
|
369 the type of the session doing the receiving. |
|
370 @param aInterfaceUid Interface UID of the new message. |
|
371 @param aOperationId Operation ID of the new message. |
|
372 @param aData Data associated with the new message. |
|
373 */ |
|
374 void BulkReceiveComplete(TUid aInterfaceUid, |
|
375 TUint aOperationId, |
|
376 const TDesC8& aData); |
|
377 |
|
378 /** |
|
379 Only called internally, by the Active Object which sucks messages out of |
|
380 RemCon. This is called in the case of a session error. |
|
381 |
|
382 @param The error that has occurred. If this is KErrServerTerminated, the |
|
383 error is fatal and the session must be restarted before any new |
|
384 messages can be received. |
|
385 */ |
|
386 void Error(TInt aError); |
|
387 |
|
388 /** |
|
389 Only called internally, by the Active Object which sucks messages out of |
|
390 RemCon Bulk Server. This is called in the case of a session error. |
|
391 |
|
392 @param The error that has occurred. If this is KErrServerTerminated, the |
|
393 error is fatal and the session must be restarted before any new |
|
394 messages can be received. |
|
395 */ |
|
396 void BulkError(TInt aError); |
|
397 |
|
398 /** |
|
399 Only called internally, by the Active Object which sucks messages out of |
|
400 RemCon (bulk server). |
|
401 */ |
|
402 void BulkSessionConnectL(); |
|
403 |
|
404 /** |
|
405 Getter for the current set of connections in the system (not just those |
|
406 associated with this session). The client is responsible for cleaning up |
|
407 aConnections- the addresses will be on the heap. |
|
408 @param aConnections A collection of remote addresses, representing all the |
|
409 currently extant connections. |
|
410 @return Error. |
|
411 */ |
|
412 IMPORT_C TInt GetConnections(TSglQue<TRemConAddress>& aConnections); |
|
413 |
|
414 /** |
|
415 Notification for changes in the set of connections. |
|
416 @param aStatus TRequestStatus for asynchronous completion. |
|
417 */ |
|
418 IMPORT_C void NotifyConnectionsChange(TRequestStatus& aStatus); |
|
419 |
|
420 /** |
|
421 Cancels interest in the completion of an outstanding |
|
422 NotifyConnectionsChange operation. |
|
423 @return KErrNone. |
|
424 */ |
|
425 IMPORT_C TInt NotifyConnectionsChangeCancel(); |
|
426 |
|
427 /** |
|
428 To determine if a target session has been opened. |
|
429 @return EFalse if no session has been opened, ETrue otherwise. |
|
430 */ |
|
431 IMPORT_C TBool TargetOpened() const; |
|
432 |
|
433 /** |
|
434 To determine if a controller session has been opened. |
|
435 @return EFalse if no session has been opened, ETrue otherwise. |
|
436 */ |
|
437 IMPORT_C TBool ControllerOpened() const; |
|
438 |
|
439 private: |
|
440 CRemConInterfaceSelector(); |
|
441 void ConstructL(); |
|
442 |
|
443 private: // utility |
|
444 void AssertSession(RRemCon* aSess, TInt aPanicCode) const; |
|
445 TInt TryToReconnect(); |
|
446 TInt TryToReconnectBulk(); |
|
447 void OpenTargetCommonL(); |
|
448 void RegisterInterfaceCommonL(CRemConInterfaceBase& aInterface, const TDesC8& aFeatures); |
|
449 void RegisterInterestedApisL(TRemConClientType aType); |
|
450 |
|
451 void EstablishBulkThreadBindingL(); |
|
452 |
|
453 static TInt StaticBulkCleanup(TAny* aSelf); |
|
454 void BulkCleanup(); |
|
455 TBool BulkOpened() const; |
|
456 |
|
457 private: // owned |
|
458 CRemConInterfaceDetailsArray* iInterfaces; |
|
459 |
|
460 RRemConController* iControllerSession; |
|
461 RRemConTarget* iTargetSession; |
|
462 RRemConBulk* iBulkSession; |
|
463 |
|
464 CReceiver* iTargetReceiver; |
|
465 CReceiver* iControllerReceiver; |
|
466 CBulkReceiver* iBulkReceiver; |
|
467 |
|
468 /** For all registered interfaces, this is the size of the biggest |
|
469 operation-associated data lump. */ |
|
470 TUint iControlMaxDataLength; |
|
471 TUint iBulkMaxDataLength; |
|
472 |
|
473 // The session to use for NotifyConnectionsChange and |
|
474 // NotifyConnectionsChangeCancel. It doesn't matter which we use- just one |
|
475 // that's connected will do. The only interesting bit is that the session |
|
476 // we called NotifyConnectionsChange on should be the one we call |
|
477 // NotifyConnectionsChangeCancel on, but as sessions are only closed when |
|
478 // 'this' comes down that's not a complication. |
|
479 RRemCon* iNotificationSession; |
|
480 |
|
481 TRemConAddress iAddress; |
|
482 |
|
483 RHeap* iBulkHeap; |
|
484 RThread iBulkThread; |
|
485 RHeap* iSharedThreadHeap; |
|
486 RSpecificThreadCallBack* iBulkCleanupCall; |
|
487 RNestableLock* iLock; |
|
488 private: // unowned |
|
489 MRemConErrorObserver* iErrorObserver; |
|
490 }; |
|
491 |
|
492 #endif // REMCONINTERFACESELECTOR_H |