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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
22 #ifndef REMCONINTERFACESELECTOR_H
23 #define REMCONINTERFACESELECTOR_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>
32 class CRemConInterfaceBase;
35 class MRemConErrorObserver;
36 class RRemConInterfaceFeatures;
37 class RSpecificThreadCallBack;
38 class CRemConInterfaceDetailsArray;
40 class RRemConController;
46 _LIT(KRemConIfSelPanicCat, "RemConIfSel");
49 /** The client has given a bad message type. */
50 ERemConIfSelBadMessageType = 0,
52 /** The client has already called OpenTargetL successfully.
54 This is no longer an illegal condition and so the panic will never
57 ERemConIfSelTargetSessionAlreadyExists = 1,
59 /** The client has already called OpenControllerL successfully.
61 This is no longer an illegal condition and so the panic will never
64 ERemConIfSelControllerSessionAlreadyExists = 2,
66 /** The client has created (and registered) an outer layer interface of a
67 type which is already registered. */
68 ERemConIfSelInterfaceOfThatTypeAlreadyRegistered = 3,
70 /** The client has not offended- there is a defect in some layer of the
71 Remote Control system. */
72 ERemConIfSelInternalError = 4,
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,
79 /** OpenControllerL has not successfully been called before using an API
80 which expects a controller session to have been created. */
81 ERemConIfSelNoControllerSession = 6,
83 /** OpenTargetL has not successfully been called before using an API which
84 expects a target session to have been created. */
85 ERemConIfSelNoTargetSession = 7,
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,
92 /** An outer layer DLL has instantiated CRemConInterfaceBase with an
93 illegal client type. */
94 ERemConIfSelUndefinedClientType = 9,
96 /** An implementation of CRemConInterfaceBase::GetInterface does not
97 provide an implementation of MRemConInterfaceIf. */
98 ERemConIfSelNoInterfaceImplementation = 10,
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,
106 CRemConInterfaceSelector is only instantiable via its NewL function. It is not
109 NONSHARABLE_CLASS(CRemConInterfaceSelector) : public CBase
114 @return Ownership of a new CRemConInterfaceSelector.
116 IMPORT_C static CRemConInterfaceSelector* NewL();
119 IMPORT_C ~CRemConInterfaceSelector();
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.
131 IMPORT_C void RegisterInterfaceL(CRemConInterfaceBase& aInterface);
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.
144 void RegisterInterfaceL(CRemConInterfaceBase& aInterface, RRemConInterfaceFeatures& aRemConInterfaceFeatures);
146 Register an error observer. This is provided to allow the client to
147 discover when an error has occurred passively.
149 @param aObserver An error observer to be notified on a passive error.
150 NULL to stop receiving notifications.
152 IMPORT_C void RegisterErrorObserver(MRemConErrorObserver* aObserver);
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.
159 IMPORT_C void OpenControllerL();
162 Makes the controller session (which must already exist- use
163 OpenControllerL) connection-oriented.
164 @param aConnection The remote to talk to.
166 IMPORT_C void GoConnectionOrientedL(const TRemConAddress& aConnection);
169 Makes the controller session (which must already exist- use
170 OpenControllerL) connectionless.
172 IMPORT_C void GoConnectionlessL();
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.
180 IMPORT_C void ConnectBearer(TRequestStatus& aStatus);
183 Cancels interest in the completion of a ConnectBearer request.
186 IMPORT_C TInt ConnectBearerCancel();
189 Destroys a bearer-level connection.
190 The controller session must already exist (use OpenControllerL) and be
192 @param aStatus TRequestStatus for asynchronous completion.
194 IMPORT_C void DisconnectBearer(TRequestStatus& aStat);
197 Cancels interest in the completion of a DisconnectBearer request.
200 IMPORT_C TInt DisconnectBearerCancel();
203 Opens a target session to RemCon.
204 @leave KErrInUse If a target session is already open.
206 IMPORT_C void OpenTargetL();
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.
215 IMPORT_C void OpenTargetL(TPlayerType aPlayerType, TPlayerSubType aPlayerSubType, const TDesC8& aPlayerName);
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
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.
230 IMPORT_C void Send(TRequestStatus& aStatus,
234 TRemConMessageType aMsgType,
235 const TDesC8& aData = KNullDesC8());
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
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.
249 IMPORT_C void Send(TRequestStatus& aStatus,
253 TRemConMessageType aMsgType,
254 TRemConMessageSubType aMsgSubType,
255 const TDesC8& aData = KNullDesC8());
260 IMPORT_C void SendNotify(TRequestStatus& aStatus,
263 TRemConMessageType aMsgType,
264 TRemConMessageSubType aMsgSubType,
265 const TDesC8& aData = KNullDesC8());
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
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.
276 IMPORT_C TInt SendUnreliable(
279 TRemConMessageType aMsgType,
280 const TDesC8& aData = KNullDesC8());
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
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.
292 IMPORT_C TInt SendUnreliable(
295 TRemConMessageType aMsgType,
296 TRemConMessageSubType aMsgSubType,
297 const TDesC8& aData = KNullDesC8());
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.
307 IMPORT_C TInt SendCancel(TRemConMessageType aMsgType);
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
318 @param aOperationId The interface-specific operation identifier.
319 @param aData Any associated message data in interface-specific format.
321 IMPORT_C void SendBulk(TRequestStatus& aStatus,
324 const TDesC8& aData = KNullDesC8());
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
332 @param aOperationId The interface-specific operation identifier.
333 @param aData Any associated message data in interface-specific format.
335 IMPORT_C TInt SendBulkUnreliable(
338 const TDesC8& aData = KNullDesC8());
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.
345 IMPORT_C TInt SendBulkCancel();
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).
359 void ReceiveComplete(TUid aInterfaceUid,
361 TRemConMessageSubType aMsgSubType,
362 const TRemConAddress& aRemoteAddress,
364 TRemConClientType aType);
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.
374 void BulkReceiveComplete(TUid aInterfaceUid,
376 const TDesC8& aData);
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.
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.
386 void Error(TInt aError);
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.
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.
396 void BulkError(TInt aError);
399 Only called internally, by the Active Object which sucks messages out of
400 RemCon (bulk server).
402 void BulkSessionConnectL();
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.
412 IMPORT_C TInt GetConnections(TSglQue<TRemConAddress>& aConnections);
415 Notification for changes in the set of connections.
416 @param aStatus TRequestStatus for asynchronous completion.
418 IMPORT_C void NotifyConnectionsChange(TRequestStatus& aStatus);
421 Cancels interest in the completion of an outstanding
422 NotifyConnectionsChange operation.
425 IMPORT_C TInt NotifyConnectionsChangeCancel();
428 To determine if a target session has been opened.
429 @return EFalse if no session has been opened, ETrue otherwise.
431 IMPORT_C TBool TargetOpened() const;
434 To determine if a controller session has been opened.
435 @return EFalse if no session has been opened, ETrue otherwise.
437 IMPORT_C TBool ControllerOpened() const;
440 CRemConInterfaceSelector();
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);
451 void EstablishBulkThreadBindingL();
453 static TInt StaticBulkCleanup(TAny* aSelf);
455 TBool BulkOpened() const;
458 CRemConInterfaceDetailsArray* iInterfaces;
460 RRemConController* iControllerSession;
461 RRemConTarget* iTargetSession;
462 RRemConBulk* iBulkSession;
464 CReceiver* iTargetReceiver;
465 CReceiver* iControllerReceiver;
466 CBulkReceiver* iBulkReceiver;
468 /** For all registered interfaces, this is the size of the biggest
469 operation-associated data lump. */
470 TUint iControlMaxDataLength;
471 TUint iBulkMaxDataLength;
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;
481 TRemConAddress iAddress;
485 RHeap* iSharedThreadHeap;
486 RSpecificThreadCallBack* iBulkCleanupCall;
487 RNestableLock* iLock;
489 MRemConErrorObserver* iErrorObserver;
492 #endif // REMCONINTERFACESELECTOR_H