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 the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
24 #ifndef REMCONINTERFACESELECTOR_H
25 #define REMCONINTERFACESELECTOR_H
28 #include <remcon/messagetype.h>
29 #include <remcon/clienttype.h>
30 #include <remcon/remconclient.h>
31 #include <remcon/remconinterfaceif.h>
32 #include <remconaddress.h>
34 class CRemConInterfaceBase;
36 class MRemConErrorObserver;
39 _LIT(KRemConIfSelPanicCat, "RemConIfSel");
42 /** The client has given a bad message type. */
43 ERemConIfSelBadMessageType = 0,
45 /** The client has already called OpenTargetL successfully.
47 This is no longer an illegal condition and so the panic will never
50 ERemConIfSelTargetSessionAlreadyExists = 1,
52 /** The client has already called OpenControllerL successfully.
54 This is no longer an illegal condition and so the panic will never
57 ERemConIfSelControllerSessionAlreadyExists = 2,
59 /** The client has created (and registered) an outer layer interface of a
60 type which is already registered. */
61 ERemConIfSelInterfaceOfThatTypeAlreadyRegistered = 3,
63 /** The client has not offended- there is a defect in some layer of the
64 Remote Control system. */
65 ERemConIfSelInternalError = 4,
67 /** An outer-layer interface has been instantiated (and registered with
68 the intermediate layer) after OpenControllerL or OpenTargetL has been
69 successfully called. */
70 ERemConIfSelTardyInterfaceRegistration = 5,
72 /** OpenControllerL has not successfully been called before using an API
73 which expects a controller session to have been created. */
74 ERemConIfSelNoControllerSession = 6,
76 /** OpenTargetL has not successfully been called before using an API which
77 expects a target session to have been created. */
78 ERemConIfSelNoTargetSession = 7,
80 /** Neither OpenControllerL not OpenTargetL has been successfully called
81 before using an API which expects either a controller or a target session
82 to have been created. */
83 ERemConIfSelNoSession = 8,
85 /** An outer layer DLL has instantiated CRemConInterfaceBase with an
86 illegal client type. */
87 ERemConIfSelUndefinedClientType = 9,
89 /** An implementation of CRemConInterfaceBase::GetInterface does not
90 provide an implementation of MRemConInterfaceIf. */
91 ERemConIfSelNoInterfaceImplementation = 10,
95 CRemConInterfaceSelector is only instantiable via its NewL function. It is not
98 NONSHARABLE_CLASS(CRemConInterfaceSelector) : public CBase
103 @return Ownership of a new CRemConInterfaceSelector.
105 IMPORT_C static CRemConInterfaceSelector* NewL();
108 IMPORT_C ~CRemConInterfaceSelector();
112 Register the interface with the selector. This is called by the
113 interface's BaseConstructL. Takes ownership of aInterface.
114 This function is not to be called outside of remconinterfacebase.dll. It is available for compatibility with previous
115 versions, but it is intended to be called only by CRemConInterfaceBase::BaseConstructL.
116 CRemConInterfaceBase-derived classes should indirectly perform a RegisterInterfaceL, by calling
117 CRemConInterfaceBase::BaseConstructL from their construction functions.
118 @param aInterface The interface.
120 IMPORT_C void RegisterInterfaceL(CRemConInterfaceBase& aInterface);
123 Register an error observer. This is provided to allow the client to
124 discover when an error has occurred passively.
126 @param aObserver An error observer to be notified on a passive error.
127 NULL to stop receiving notifications.
129 IMPORT_C void RegisterErrorObserver(MRemConErrorObserver* aObserver);
132 Opens a controller session to RemCon. The session is connectionless until
133 such time as GoConnectionOriented may be called.
134 @leave KErrInUse If a controller session is already open.
136 IMPORT_C void OpenControllerL();
139 Makes the controller session (which must already exist- use
140 OpenControllerL) connection-oriented.
141 @param aConnection The remote to talk to.
143 IMPORT_C void GoConnectionOrientedL(const TRemConAddress& aConnection);
146 Makes the controller session (which must already exist- use
147 OpenControllerL) connectionless.
149 IMPORT_C void GoConnectionlessL();
152 Brings up a bearer-level connection.
153 The controller session must already exist (use OpenControllerL) and
154 be connection-oriented.
155 @param aStatus TRequestStatus for asynchronous completion.
157 IMPORT_C void ConnectBearer(TRequestStatus& aStatus);
160 Cancels interest in the completion of a ConnectBearer request.
163 IMPORT_C TInt ConnectBearerCancel();
166 Destroys a bearer-level connection.
167 The controller session must already exist (use OpenControllerL) and be
169 @param aStatus TRequestStatus for asynchronous completion.
171 IMPORT_C void DisconnectBearer(TRequestStatus& aStat);
174 Cancels interest in the completion of a DisconnectBearer request.
177 IMPORT_C TInt DisconnectBearerCancel();
180 Opens a target session to RemCon.
181 @leave KErrInUse If a target session is already open.
183 IMPORT_C void OpenTargetL();
186 Sends a message to the remote device(s).
187 There should be only one command and response outstanding at any one time.
188 Send cannot be called again until aStatus is completed.
189 @panic RemConClient 4 If a send is already outstanding
190 @param aStatus TRequestStatus for asynchronous completion.
191 @param aInterfaceUid The UID of the concrete (outer-layer) interface
193 @param aOperationId The interface-specific operation identifier.
194 @param aNumRemotes On success, the number of remotes the message was
195 successfully sent to.
196 @param aMsgType Whether the message is a command or a response.
197 @param aData Any associated message data in interface-specific format.
199 IMPORT_C void Send(TRequestStatus& aStatus,
203 TRemConMessageType aMsgType,
204 const TDesC8& aData = KNullDesC8());
207 Sends a message to the remote device(s).
208 @param aStatus TRequestStatus for asynchronous completion.
209 @param aInterfaceUid The UID of the concrete (outer-layer) interface
211 @param aOperationId The interface-specific operation identifier.
212 @param aNumRemotes On success, the number of remotes the message was
213 successfully sent to.
214 @param aMsgType Whether the message is a command or a response.
215 @param aMsgSubType The subtype of the command of response
216 @param aData Any associated message data in interface-specific format.
218 IMPORT_C void Send(TRequestStatus& aStatus,
222 TRemConMessageType aMsgType,
223 TRemConMessageSubType aMsgSubType,
224 const TDesC8& aData = KNullDesC8());
229 Sends a message to the remote device(s), without waiting for the send to complete
230 @param aInterfaceUid The UID of the concrete (outer-layer) interface
232 @param aOperationId The interface-specific operation identifier.
233 @param aMsgType Whether the message is a command or a response.
234 @param aData Any associated message data in interface-specific format.
236 IMPORT_C TInt SendUnreliable(
239 TRemConMessageType aMsgType,
240 const TDesC8& aData = KNullDesC8());
244 Sends a message to the remote device(s), without waiting for the send to complete
245 @param aInterfaceUid The UID of the concrete (outer-layer) interface
247 @param aOperationId The interface-specific operation identifier.
248 @param aMsgType Whether the message is a command or a response.
249 @param aMsgSubType The subtype of the command of response
250 @param aData Any associated message data in interface-specific format.
252 IMPORT_C TInt SendUnreliable(
255 TRemConMessageType aMsgType,
256 TRemConMessageSubType aMsgSubType,
257 const TDesC8& aData = KNullDesC8());
260 Cancels interest in the completion of a Send request.
261 @param aMsgType The type of the message, the completion of the send of
262 which we are not interested in. This is needed because a single
263 CRemConInterfaceSelector may have two sends outstanding at once, one on
264 a controller session and another on a target session.
267 IMPORT_C TInt SendCancel(TRemConMessageType aMsgType);
270 Only called internally, by the Active Object which sucks messages out of
271 RemCon. Note that the message type is not given- it is interpolated from
272 the type of the session doing the receiving.
273 @param aInterfaceUid Interface UID of the new message.
274 @param aOperationId Operation ID of the new message.
275 @param aData Data associated with the new message.
276 @param aType The type of session which received the message (from which
277 the type of the message can be interpolated).
279 void ReceiveComplete(TUid aInterfaceUid,
281 TRemConMessageSubType aMsgSubType,
283 TRemConClientType aType);
286 Only called internally, by the Active Object which sucks messages out of
287 RemCon. This is called in the case of a session error.
289 @param The error that has occurred. If this is KErrServerTerminated, the
290 error is fatal and the session must be restarted before any new
291 messages can be received.
293 void Error(TInt aError);
296 Getter for the current set of connections in the system (not just those
297 associated with this session). The client is responsible for cleaning up
298 aConnections- the addresses will be on the heap.
299 @param aConnections A collection of remote addresses, representing all the
300 currently extant connections.
303 IMPORT_C TInt GetConnections(TSglQue<TRemConAddress>& aConnections);
306 Notification for changes in the set of connections.
307 @param aStatus TRequestStatus for asynchronous completion.
309 IMPORT_C void NotifyConnectionsChange(TRequestStatus& aStatus);
312 Cancels interest in the completion of an outstanding
313 NotifyConnectionsChange operation.
316 IMPORT_C TInt NotifyConnectionsChangeCancel();
319 To determine if a target session has been opened.
320 @return EFalse if no session has been opened, ETrue otherwise.
322 IMPORT_C TBool TargetOpened() const;
325 To determine if a controller session has been opened.
326 @return EFalse if no session has been opened, ETrue otherwise.
328 IMPORT_C TBool ControllerOpened() const;
331 CRemConInterfaceSelector();
334 void AssertSession(RRemCon* aSess, TInt aPanicCode) const;
335 TInt TryToReconnect();
338 RPointerArray<CRemConInterfaceBase> iInterfaces;
340 RRemConController iControllerSession;
341 RRemConTarget iTargetSession;
343 CReceiver* iTargetReceiver;
344 CReceiver* iControllerReceiver;
346 /** For all registered interfaces, this is the size of the biggest
347 operation-associated data lump. */
348 TUint iMaxDataLength;
350 // The session to use for NotifyConnectionsChange and
351 // NotifyConnectionsChangeCancel. It doesn't matter which we use- just one
352 // that's connected will do. The only interesting bit is that the session
353 // we called NotifyConnectionsChange on should be the one we call
354 // NotifyConnectionsChangeCancel on, but as sessions are only closed when
355 // 'this' comes down that's not a complication.
356 RRemCon* iNotificationSession;
358 TRemConAddress iAddress;
361 MRemConErrorObserver* iErrorObserver;
364 #endif // REMCONINTERFACESELECTOR_H