accessoryservices/remotecontrolfw/server/inc/session.h
changeset 0 4e1aa6a622a0
child 56 1ddbe54d0645
child 70 653a8b91b95e
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     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  @internalComponent
       
    19 */
       
    20 
       
    21 #ifndef REMCONSESSION_H
       
    22 #define REMCONSESSION_H
       
    23 
       
    24 #include <e32base.h>
       
    25 #include <remconserverpanic.h>
       
    26 #include <remconaddress.h>
       
    27 #include <remcon/clientinfo.h>
       
    28 #include <remcon/clienttype.h>
       
    29 #include <remcon/playertype.h>
       
    30 #include <remcon/clientid.h>
       
    31 
       
    32 class CRemConServer;
       
    33 class CBearerManager;
       
    34 class CRemConMessage;
       
    35 class CActiveHelper;
       
    36 class CMessageQueue;
       
    37 class CRemConInterfaceDetailsArray;
       
    38 class CRemConInterfaceDetails;
       
    39 
       
    40 /**
       
    41 Rem Con session.
       
    42 */
       
    43 NONSHARABLE_CLASS(CRemConSession) : public CSession2
       
    44 	{
       
    45 public:
       
    46 	/**
       
    47 	Factory method.
       
    48 	@param aServer The server.
       
    49 	@param aBearerManager The bearer manager.
       
    50 	@param aMessage Handle on the client message triggering this session creation.
       
    51 	@param aId The unique ID of the new session.
       
    52 	@return Ownership of a new session.
       
    53 	*/
       
    54 	static CRemConSession* NewL(CRemConServer& aServer,
       
    55 		CBearerManager& aBearerManager,
       
    56 		const RMessage2& aMessage,
       
    57 		TUint aId);
       
    58 
       
    59 	/** Destructor. */
       
    60 	~CRemConSession();
       
    61 
       
    62 public: // called by the server
       
    63 	/** 
       
    64 	@return The number of remotes the current 'send' has gone to successfully.
       
    65 	*/
       
    66 	inline TUint& NumRemotes();
       
    67 
       
    68 	/** 
       
    69 	@return The number of remotes the current 'send' is supposed to be going 
       
    70 	to. NB This is decremented as the sends actually occur.
       
    71 	*/
       
    72 	inline TInt& NumRemotesToTry();
       
    73 
       
    74 	/** 
       
    75 	@return The error the current 'send' will be completed with.
       
    76 	*/
       
    77 	inline TInt& SendError();
       
    78 
       
    79 	/** 
       
    80 	@return Information about the client using this session.
       
    81 	*/
       
    82 	inline TClientInfo& ClientInfo();
       
    83 
       
    84 	/** 
       
    85 	@return Information about the client using this session.
       
    86 	*/
       
    87 	inline const TClientInfo& ClientInfo() const;
       
    88 
       
    89 	/**
       
    90 	@return This session's type.
       
    91 	*/
       
    92 	inline TRemConClientType Type() const;
       
    93 
       
    94 	/**
       
    95 	@return This session's unique identifier.
       
    96 	*/
       
    97 	inline TUint Id() const;
       
    98 
       
    99 	/**
       
   100 	Used by the server to complete a client send request. 
       
   101 	@param aError Error.					
       
   102 	*/
       
   103 	void CompleteSend();
       
   104 	
       
   105 	/**
       
   106 	Used by the server to complete a client send notify request.
       
   107 	*/
       
   108 	void CompleteSendNotify();
       
   109 	
       
   110 	/** 
       
   111 	Checks if this message is supported by the session
       
   112 	@return ETrue if it is, EFalse otherwise
       
   113 	*/
       
   114 	TBool SupportedMessage(const CRemConMessage& aMsg);
       
   115 
       
   116 	/**
       
   117 	Writes aMsg to the client's Receive message (NB RMessage2::Write may fail) 
       
   118 	and completes the client's Receive message with any error.
       
   119 	@return Error.
       
   120 	*/
       
   121 	TInt WriteMessageToClient(const CRemConMessage& aMsg);
       
   122 
       
   123 	/**
       
   124 	Accessor for the currently outstanding client Send message. This is used 
       
   125 	to check the client's capabilities to send over a particular bearer.
       
   126 	@return Handle to client's send message.
       
   127 	*/
       
   128 	inline const RMessage2& CurrentSendMessage() const;
       
   129 
       
   130 	/**
       
   131 	Accessor for the currently outstanding client Receive message.
       
   132 	@return Handle to client's receive message.
       
   133 	*/
       
   134 	inline const RMessage2& CurrentReceiveMessage() const;
       
   135 
       
   136 	inline const TPlayerType& PlayerType() const;
       
   137 	inline const TPlayerSubType& PlayerSubType() const;
       
   138 	
       
   139 	inline const TDesC8& Name() const;
       
   140 	
       
   141 	TInt SupportedInterfaces(RArray<TUid>& aUids);
       
   142 	TInt SupportedBulkInterfaces(RArray<TUid>& aUids);
       
   143 	TInt SupportedOperations(TUid aInterfaceUid, RArray<TUint>& aOperations);
       
   144 
       
   145 	/**
       
   146 	Panics the client's current Send message with the given code.
       
   147 	*/
       
   148 	void PanicSend(TRemConClientPanic aCode);
       
   149 
       
   150 public: // called by the bearer manager
       
   151 	/**
       
   152 	Indicates that a connect request has been completed. The request was not 
       
   153 	necessarily from this session- the session must check that the connected 
       
   154 	address is one it has asked to be connected. If it is, and we have a 
       
   155 	connect request outstanding, the connect request should be completed.
       
   156 	@param aAddr The connected address.
       
   157 	@param aError The error with which the connection attempt was completed.
       
   158 	*/
       
   159 	void CompleteConnect(const TRemConAddress& aAddr, TInt aError);
       
   160 
       
   161 	/**
       
   162 	Indicates that a disconnect request has been completed. The request was 
       
   163 	not necessarily from this session- the session must check that the 
       
   164 	disconnected address is one it has asked to be disconnected. If it is, and 
       
   165 	we have a disconnect request outstanding, the disconnect request should be 
       
   166 	completed.
       
   167 	@param aAddr The disconnected address.
       
   168 	@param aError The error with which the disconnection attempt was 
       
   169 	completed.
       
   170 	*/
       
   171 	void CompleteDisconnect(const TRemConAddress& aAddr, TInt aError);
       
   172 
       
   173 	/**
       
   174 	Indicates that a connection has come up or down. If the session has a 
       
   175 	'connections notification' outstanding, it should be completed. Note that, 
       
   176 	when a connection comes up or down, ConnectionsChanged is called before 
       
   177 	CompleteConnect or DisconnectComplete. These functions are called 
       
   178 	synchronously by the connection-handling code.
       
   179 	*/
       
   180 	void ConnectionsChanged();
       
   181 	
       
   182 public: // called by the active helper
       
   183 	/**
       
   184 	Process pending messages.
       
   185 	*/
       
   186 	void ProcessPendingMsgL();
       
   187 	
       
   188 private:
       
   189 	/**
       
   190 	Constructor.
       
   191 	@param aServer The server.
       
   192 	@param aBearerManager The bearer manager.
       
   193 	@param aId The unique ID of the new session.
       
   194 	*/
       
   195 	CRemConSession(CRemConServer& aServer, 
       
   196 		CBearerManager& aBearerManager,
       
   197 		TUint aId);
       
   198 
       
   199 	/**
       
   200 	2nd-phase construction.
       
   201 	@param aMessage The message received from the client.
       
   202 	*/
       
   203 	void ConstructL(const RMessage2& aMessage);
       
   204 		
       
   205 private: // from CSession2
       
   206 	/**
       
   207 	Called when a message is received from the client.
       
   208 	@param aMessage Message received from the client.
       
   209 	*/
       
   210 	void ServiceL(const RMessage2& aMessage);
       
   211 
       
   212 private: // utility- IPC command handlers
       
   213 	void SetClientType(const RMessage2& aMessage);
       
   214 	void GoConnectionOriented(const RMessage2& aMessage);
       
   215 	void GoConnectionless(const RMessage2& aMessage);
       
   216 	void ConnectBearer(const RMessage2& aMessage);
       
   217 	void ConnectBearerCancel(const RMessage2& aMessage);
       
   218 	void DisconnectBearer(const RMessage2& aMessage);
       
   219 	void DisconnectBearerCancel(const RMessage2& aMessage);
       
   220 	void Send(const RMessage2& aMessage);
       
   221 	void SendNotify(const RMessage2& aMessage);
       
   222 	void SendUnreliable(const RMessage2& aMessage);
       
   223 	void SendCancel(const RMessage2& aMessage);
       
   224 	void Receive(const RMessage2& aMessage);
       
   225 	void ReceiveCancel(const RMessage2& aMessage);
       
   226 	void GetConnectionCount(const RMessage2& aMessage);
       
   227 	void GetConnections(const RMessage2& aMessage);
       
   228 	void NotifyConnectionsChange(const RMessage2& aMessage);
       
   229 	void NotifyConnectionsChangeCancel(const RMessage2& aMessage);
       
   230 	void RegisterInterestedAPIs(const RMessage2& aMessage);
       
   231 	
       
   232 private: // utility
       
   233 	/**
       
   234 	Utility to complete the given message with the given error code.
       
   235 	@param aMessage Message to complete.
       
   236 	@param aError Error to complete with.
       
   237 	*/
       
   238 	void CompleteClient(const RMessage2& aMessage, TInt aError);
       
   239 
       
   240 	void DoSendL(const RMessage2& aMessage);
       
   241 	void DoSendNotifyL(const RMessage2& aMessage);
       
   242 	CRemConMessage* DoCreateUnreliableMessageL(const RMessage2& aMessage);
       
   243 	void DoRegisterInterestedAPIsL(const RMessage2& aMessage);
       
   244 	void DoSetClientTypeL(const RMessage2& aMessage);
       
   245 	void DoSendCancel();
       
   246 	
       
   247 	CRemConInterfaceDetails* FindInterfaceByUid(TUid aUid) const;
       
   248 
       
   249 	void SendToServer(CRemConMessage& aMsg);
       
   250 	
       
   251 	void CheckForPendingMsg() const; 
       
   252 
       
   253 	static TInt SendNextCb(TAny* aThis);
       
   254 
       
   255 	void DoSendNext();
       
   256 	
       
   257 	void EmptySendQueue();
       
   258 
       
   259 	void WriteMessageToClientL(const CRemConMessage& aMsg);
       
   260 	
       
   261 private: // unowned
       
   262 	CRemConServer& iServer;
       
   263 	CBearerManager& iBearerManager;
       
   264 
       
   265 private: // message handles for asynchronous IPC requests
       
   266 	RMessage2 iConnectBearerMsg;
       
   267 	RMessage2 iDisconnectBearerMsg;
       
   268 	RMessage2 iSendMsg;
       
   269 	RMessage2 iReceiveMsg;
       
   270 	RMessage2 iNotifyConnectionsChangeMsg;
       
   271 	// Stores pending connect/disconnect request
       
   272 	// There can be only one pending request at any time
       
   273 	RMessage2 iPendingMsg;
       
   274 	
       
   275 	CMessageQueue* iSendQueue;
       
   276 	
       
   277 private: // owned
       
   278 	// Address of remote device associated with this session (only relevant 
       
   279 	// for controllers). A null remote address indicates a connectionless 
       
   280 	// controller; a non-null UID indicates a connection-oriented controller.
       
   281 	TRemConAddress iRemoteAddress;
       
   282 
       
   283 	TRemConClientType iType;
       
   284 
       
   285 	// The client's process ID, secure ID and caps.
       
   286 	TClientInfo iClientInfo;
       
   287 
       
   288 	// Unique session identifier.
       
   289 	const TUint iId;
       
   290 
       
   291 	// Used to control the completion of the client's send request until we 
       
   292 	// know the correct values of iNumSuccessfulRemotes and iSendError to use.
       
   293 	// Generally 0. 
       
   294 	// 1 when sending a connection-oriented command or a response.
       
   295 	// N when sending a connectionless command (where N is the number of 
       
   296 	// remotes the TSP addressed it to). 
       
   297 	// While processing outgoing commands to multiple remotes, 
       
   298 	// iNumRemotesToTry is decremented each time we finish trying to address a 
       
   299 	// remote. This may be at the connection stage or the actual send stage.
       
   300 	// -1 means that the client's send has been completed already. This is 
       
   301 	// useful due to the potentially recursive processing of multiple 
       
   302 	// connections.
       
   303 	TInt iNumRemotesToTry;
       
   304 	// For completion of the current send request. NB A send may be completed 
       
   305 	// only after numerous asynchronous stages.
       
   306 	TUint iNumRemotes;
       
   307 	TInt iSendError;
       
   308 	
       
   309 	CRemConInterfaceDetailsArray* iInterestedAPIs;
       
   310 	// the player type information
       
   311 	TPlayerTypeInformation iPlayerType;
       
   312 	//the player name 
       
   313 	RBuf8 iPlayerName;
       
   314 
       
   315 	// Helps with session's async connect/disconnect requests
       
   316 	CActiveHelper *iPendingMsgProcessor;
       
   317 	
       
   318 	CAsyncCallBack* iSendNextCallBack;
       
   319 	
       
   320 	enum TRemConSessionSending
       
   321 		{
       
   322 		ENotSending,
       
   323 		ESendingReliable,
       
   324 		ESendingUnreliable
       
   325 		};
       
   326 	
       
   327 	TRemConSessionSending iSending;
       
   328 	
       
   329 	};
       
   330 
       
   331 // Inlines
       
   332 
       
   333 TInt& CRemConSession::NumRemotesToTry()
       
   334 	{
       
   335 	return iNumRemotesToTry;
       
   336 	}
       
   337 
       
   338 TUint& CRemConSession::NumRemotes()
       
   339 	{
       
   340 	return iNumRemotes;
       
   341 	}
       
   342 
       
   343 TInt& CRemConSession::SendError()
       
   344 	{
       
   345 	return iSendError;
       
   346 	}
       
   347 
       
   348 TClientInfo& CRemConSession::ClientInfo()
       
   349 	{
       
   350 	return iClientInfo;
       
   351 	}
       
   352 
       
   353 const TClientInfo& CRemConSession::ClientInfo() const
       
   354 	{
       
   355 	return iClientInfo;
       
   356 	}
       
   357 
       
   358 TRemConClientType CRemConSession::Type() const
       
   359 	{
       
   360 	return iType;
       
   361 	}
       
   362 
       
   363 TUint CRemConSession::Id() const
       
   364 	{
       
   365 	return iId;
       
   366 	}
       
   367 
       
   368 const RMessage2& CRemConSession::CurrentSendMessage() const
       
   369 	{
       
   370 	return iSendMsg;
       
   371 	}
       
   372 
       
   373 const RMessage2& CRemConSession::CurrentReceiveMessage() const
       
   374 	{
       
   375 	return iReceiveMsg;
       
   376 	}
       
   377 
       
   378 const TPlayerType& CRemConSession::PlayerType() const
       
   379 	{
       
   380 	return iPlayerType.iPlayerType;
       
   381 	}
       
   382 
       
   383 const TPlayerSubType& CRemConSession::PlayerSubType() const
       
   384 	{
       
   385 	return iPlayerType.iPlayerSubType;
       
   386 	}
       
   387 
       
   388 const TDesC8& CRemConSession::Name() const
       
   389 	{
       
   390 	return iPlayerName;
       
   391 	}
       
   392 
       
   393 #endif // REMCONSESSION_H
       
   394