accessoryservices/remotecontrolfw/server/inc/session.h
changeset 70 653a8b91b95e
parent 0 4e1aa6a622a0
equal deleted inserted replaced
64:61992147389a 70:653a8b91b95e
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2004-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    24 #include <e32base.h>
    24 #include <e32base.h>
    25 #include <remconserverpanic.h>
    25 #include <remconserverpanic.h>
    26 #include <remconaddress.h>
    26 #include <remconaddress.h>
    27 #include <remcon/clientinfo.h>
    27 #include <remcon/clientinfo.h>
    28 #include <remcon/clienttype.h>
    28 #include <remcon/clienttype.h>
       
    29 #include <remcon/messagetype.h>
    29 #include <remcon/playertype.h>
    30 #include <remcon/playertype.h>
    30 #include <remcon/clientid.h>
    31 #include <remcon/clientid.h>
    31 
    32 
    32 class CRemConServer;
    33 class CRemConServer;
    33 class CBearerManager;
    34 class CBearerManager;
    34 class CRemConMessage;
    35 class CRemConMessage;
    35 class CActiveHelper;
       
    36 class CMessageQueue;
    36 class CMessageQueue;
    37 class CRemConInterfaceDetailsArray;
    37 class CRemConInterfaceDetailsArray;
    38 class CRemConInterfaceDetails;
    38 class CRemConInterfaceDetails;
    39 
    39 
    40 /**
    40 /**
    41 Rem Con session.
    41 Rem Con session.
    42 */
    42 */
    43 NONSHARABLE_CLASS(CRemConSession) : public CSession2
    43 NONSHARABLE_CLASS(CRemConSession) : public CSession2
    44 	{
    44 	{
    45 public:
    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();
    46 	~CRemConSession();
    61 
    47 
    62 public: // called by the server
    48 public: // called by the server
    63 	/** 
    49 	/** 
    64 	@return The number of remotes the current 'send' has gone to successfully.
    50 	@return The number of remotes the current 'send' has gone to successfully.
    85 	@return Information about the client using this session.
    71 	@return Information about the client using this session.
    86 	*/
    72 	*/
    87 	inline const TClientInfo& ClientInfo() const;
    73 	inline const TClientInfo& ClientInfo() const;
    88 
    74 
    89 	/**
    75 	/**
    90 	@return This session's type.
       
    91 	*/
       
    92 	inline TRemConClientType Type() const;
       
    93 
       
    94 	/**
       
    95 	@return This session's unique identifier.
    76 	@return This session's unique identifier.
    96 	*/
    77 	*/
    97 	inline TUint Id() const;
    78 	inline TUint Id() const;
    98 
    79 
    99 	/**
    80 	/**
   109 	
    90 	
   110 	/** 
    91 	/** 
   111 	Checks if this message is supported by the session
    92 	Checks if this message is supported by the session
   112 	@return ETrue if it is, EFalse otherwise
    93 	@return ETrue if it is, EFalse otherwise
   113 	*/
    94 	*/
   114 	TBool SupportedMessage(const CRemConMessage& aMsg);
    95 	virtual TBool SupportedMessage(const CRemConMessage& aMsg) const = 0;
   115 
    96 
   116 	/**
    97 	/**
   117 	Writes aMsg to the client's Receive message (NB RMessage2::Write may fail) 
    98 	Writes aMsg to the client's Receive message (NB RMessage2::Write may fail) 
   118 	and completes the client's Receive message with any error.
    99 	and completes the client's Receive message with any error.
   119 	@return Error.
   100 	@return Error.
   130 	/**
   111 	/**
   131 	Accessor for the currently outstanding client Receive message.
   112 	Accessor for the currently outstanding client Receive message.
   132 	@return Handle to client's receive message.
   113 	@return Handle to client's receive message.
   133 	*/
   114 	*/
   134 	inline const RMessage2& CurrentReceiveMessage() const;
   115 	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 	
   116 	
   141 	TInt SupportedInterfaces(RArray<TUid>& aUids);
   117 	TInt SupportedInterfaces(RArray<TUid>& aUids);
       
   118 	TInt AppendSupportedInterfaces(RArray<TUid>& aUids);
   142 	TInt SupportedBulkInterfaces(RArray<TUid>& aUids);
   119 	TInt SupportedBulkInterfaces(RArray<TUid>& aUids);
       
   120 	TInt AppendSupportedBulkInterfaces(RArray<TUid>& aUids);
   143 	TInt SupportedOperations(TUid aInterfaceUid, RArray<TUint>& aOperations);
   121 	TInt SupportedOperations(TUid aInterfaceUid, RArray<TUint>& aOperations);
   144 
   122 
   145 	/**
   123 	/**
   146 	Panics the client's current Send message with the given code.
   124 	Panics the client's current Send message with the given code.
   147 	*/
   125 	*/
   148 	void PanicSend(TRemConClientPanic aCode);
   126 	void PanicSend(TRemConClientPanic aCode);
   149 
   127 	
   150 public: // called by the bearer manager
   128 	/**
   151 	/**
   129 	Checks whether this session is fully initialised and available for use
   152 	Indicates that a connect request has been completed. The request was not 
   130 	by bearers.
   153 	necessarily from this session- the session must check that the connected 
   131 	@return ETrue if session can be used by bearers, EFalse otherwise
   154 	address is one it has asked to be connected. If it is, and we have a 
   132 	*/
   155 	connect request outstanding, the connect request should be completed.
   133 	inline TBool ClientAvailable() const;
   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 
   134 
   173 	/**
   135 	/**
   174 	Indicates that a connection has come up or down. If the session has a 
   136 	Indicates that a connection has come up or down. If the session has a 
   175 	'connections notification' outstanding, it should be completed. Note that, 
   137 	'connections notification' outstanding, it should be completed. Note that, 
   176 	when a connection comes up or down, ConnectionsChanged is called before 
   138 	when a connection comes up or down, ConnectionsChanged is called before 
   177 	CompleteConnect or DisconnectComplete. These functions are called 
   139 	CompleteConnect or DisconnectComplete. These functions are called 
   178 	synchronously by the connection-handling code.
   140 	synchronously by the connection-handling code.
   179 	*/
   141 	*/
   180 	void ConnectionsChanged();
   142 	void ConnectionsChanged();
   181 	
   143 	
   182 public: // called by the active helper
   144 protected:
   183 	/**
   145     /**
   184 	Process pending messages.
   146     Constructor.
   185 	*/
   147     @param aServer The server.
   186 	void ProcessPendingMsgL();
   148     @param aBearerManager The bearer manager.
   187 	
   149     @param aId The unique ID of the new session.
   188 private:
   150     */
   189 	/**
   151     CRemConSession(CRemConServer& aServer, 
   190 	Constructor.
   152         CBearerManager& aBearerManager,
   191 	@param aServer The server.
   153         TUint aId);
   192 	@param aBearerManager The bearer manager.
   154     
   193 	@param aId The unique ID of the new session.
   155     /**
   194 	*/
   156     2nd-phase construction.
   195 	CRemConSession(CRemConServer& aServer, 
   157     @param aMessage The message received from the client.
   196 		CBearerManager& aBearerManager,
   158     */
   197 		TUint aId);
   159     void BaseConstructL(const TClientInfo& aClientInfo);
   198 
   160 
   199 	/**
   161 	
   200 	2nd-phase construction.
   162 protected: 		
   201 	@param aMessage The message received from the client.
   163 
   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 	/**
   164 	/**
   234 	Utility to complete the given message with the given error code.
   165 	Utility to complete the given message with the given error code.
   235 	@param aMessage Message to complete.
   166 	@param aMessage Message to complete.
   236 	@param aError Error to complete with.
   167 	@param aError Error to complete with.
   237 	*/
   168 	*/
   238 	void CompleteClient(const RMessage2& aMessage, TInt aError);
   169 	void CompleteClient(const RMessage2& aMessage, TInt aError);
   239 
   170 
       
   171 	CRemConInterfaceDetailsArray* ExtractInterestedAPIsL(const RMessage2& aMessage);
       
   172 	
       
   173 	/**
       
   174 	Gets the information needed to send from the RMessage.
       
   175 	
       
   176 	@param aMessage The message containing the info.
       
   177 	@param aInterfaceUid The uid of the interface to send on
       
   178 	@param aOperationId The operation id to send
       
   179 	@param aMessageSubType The sub type of hte message
       
   180 	@param aSendDes The operation data to send.  Ownership is passed
       
   181 					to the caller and aSendDes is placed on the cleanup
       
   182 					stack when this function completes successfully.
       
   183 	@leave If the data was not successfully read. Note: if the message is invalid
       
   184 	       this function will not leave, but rather panic the message and return
       
   185 	       EFalse. This function will only leave if there's a system error, such
       
   186 	       as out of memory.
       
   187 	@return ETrue if the message information was successfully retrieved,
       
   188 			or EFalse if the message is invalid, in which case it got panicked.
       
   189 			If this function returns EFalse, aSendDes is not left on the cleanup stack.
       
   190 	 */
       
   191 	TBool DoGetSendInfoLC(const RMessage2& aMessage, 
       
   192 			TUid& aInterfaceUid,
       
   193 			TUint& aOperationId,
       
   194 			TRemConMessageSubType& aMessageSubType,
       
   195 			RBuf8& aSendDes);
       
   196 			
       
   197 	
       
   198 protected: // from CSession2
       
   199 	/**
       
   200 	Called when a message is received from the client.
       
   201 	
       
   202 	Also used from the session, where a session has stored
       
   203 	a message for later	processing.
       
   204 	
       
   205 	@param aMessage Message received from the client.
       
   206 	*/
       
   207 	void ServiceL(const RMessage2& aMessage);
       
   208 
       
   209 private: // utility- IPC command handlers
       
   210 	virtual void SetPlayerType(const RMessage2& aMessage)=0;
       
   211 	virtual void SendUnreliable(const RMessage2& aMessage) = 0;
       
   212 	virtual void SendCancel(const RMessage2& aMessage);
       
   213 	virtual void Receive(const RMessage2& aMessage);
       
   214 	virtual void ReceiveCancel(const RMessage2& aMessage);
       
   215 	virtual void GetConnectionCount(const RMessage2& aMessage);
       
   216 	virtual void GetConnections(const RMessage2& aMessage);
       
   217 	virtual void NotifyConnectionsChange(const RMessage2& aMessage);
       
   218 	virtual void NotifyConnectionsChangeCancel(const RMessage2& aMessage);
       
   219 	virtual void RegisterInterestedAPIs(const RMessage2& aMessage) = 0;
       
   220 	virtual void GoConnectionOriented(const RMessage2& aMessage);
       
   221 	virtual void GoConnectionless(const RMessage2& aMessage);
       
   222 	virtual void ConnectBearer(const RMessage2& aMessage);
       
   223 	virtual void ConnectBearerCancel(const RMessage2& aMessage);
       
   224 	virtual void DisconnectBearer(const RMessage2& aMessage);
       
   225 	virtual void DisconnectBearerCancel(const RMessage2& aMessage);
       
   226 	virtual void SendNotify(const RMessage2& aMessage);
       
   227 	void Send(const RMessage2& aMessage);
       
   228 
       
   229 private: // utility
       
   230 	virtual CRemConMessage* DoPrepareSendMessageL(const RMessage2& aMessage)=0;
       
   231 	virtual void DoSendCancel()=0;
       
   232 	virtual void DoReceive()=0;
       
   233 	void WriteMessageToClientL(const CRemConMessage& aMsg);
       
   234 	virtual void SendToServer(CRemConMessage& aMsg)=0;
       
   235 	static TInt SendNextCb(TAny* aThis);
       
   236 	void DoSendNext();
       
   237 
       
   238 protected:
   240 	void DoSendL(const RMessage2& aMessage);
   239 	void DoSendL(const RMessage2& aMessage);
   241 	void DoSendNotifyL(const RMessage2& aMessage);
   240 	void GetPlayerTypeAndNameL(const RMessage2& aMessage, TPlayerTypeInformation& aPlayerType, RBuf8& aPlayerName);
   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;
   241 	CRemConInterfaceDetails* FindInterfaceByUid(TUid aUid) const;
   248 
   242 	
   249 	void SendToServer(CRemConMessage& aMsg);
   243 protected: // unowned
   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;
   244 	CRemConServer& iServer;
   263 	CBearerManager& iBearerManager;
   245 	CBearerManager& iBearerManager;
   264 
   246 
   265 private: // message handles for asynchronous IPC requests
   247 protected: // message handles for asynchronous IPC requests
   266 	RMessage2 iConnectBearerMsg;
       
   267 	RMessage2 iDisconnectBearerMsg;
       
   268 	RMessage2 iSendMsg;
   248 	RMessage2 iSendMsg;
   269 	RMessage2 iReceiveMsg;
   249 	RMessage2 iReceiveMsg;
   270 	RMessage2 iNotifyConnectionsChangeMsg;
   250 	RMessage2 iNotifyConnectionsChangeMsg;
   271 	// Stores pending connect/disconnect request
   251 
   272 	// There can be only one pending request at any time
       
   273 	RMessage2 iPendingMsg;
       
   274 	
       
   275 	CMessageQueue* iSendQueue;
   252 	CMessageQueue* iSendQueue;
   276 	
   253 	
   277 private: // owned
   254 protected: // 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.
   255 	// The client's process ID, secure ID and caps.
   286 	TClientInfo iClientInfo;
   256 	TClientInfo iClientInfo;
   287 
   257 
   288 	// Unique session identifier.
   258 	// Unique session identifier.
   289 	const TUint iId;
   259 	const TUint iId;
   295 	// N when sending a connectionless command (where N is the number of 
   265 	// N when sending a connectionless command (where N is the number of 
   296 	// remotes the TSP addressed it to). 
   266 	// remotes the TSP addressed it to). 
   297 	// While processing outgoing commands to multiple remotes, 
   267 	// While processing outgoing commands to multiple remotes, 
   298 	// iNumRemotesToTry is decremented each time we finish trying to address a 
   268 	// 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.
   269 	// 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 
   270 	// On return to 0, the client is completed with either the result of the send
   301 	// useful due to the potentially recursive processing of multiple 
   271 	// or KErrCancel.
   302 	// connections.
       
   303 	TInt iNumRemotesToTry;
   272 	TInt iNumRemotesToTry;
   304 	// For completion of the current send request. NB A send may be completed 
   273 	// For completion of the current send request. NB A send may be completed 
   305 	// only after numerous asynchronous stages.
   274 	// only after numerous asynchronous stages.
   306 	TUint iNumRemotes;
   275 	TUint iNumRemotes;
   307 	TInt iSendError;
   276 	TInt iSendError;
   308 	
   277 	
   309 	CRemConInterfaceDetailsArray* iInterestedAPIs;
   278 	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 	
   279 	
   318 	CAsyncCallBack* iSendNextCallBack;
   280 	CAsyncCallBack* iSendNextCallBack;
   319 	
   281 	
   320 	enum TRemConSessionSending
   282 	enum TRemConSessionSending
   321 		{
   283 		{
   323 		ESendingReliable,
   285 		ESendingReliable,
   324 		ESendingUnreliable
   286 		ESendingUnreliable
   325 		};
   287 		};
   326 	
   288 	
   327 	TRemConSessionSending iSending;
   289 	TRemConSessionSending iSending;
   328 	
       
   329 	};
   290 	};
   330 
   291 
   331 // Inlines
   292 // Inlines
   332 
   293 
   333 TInt& CRemConSession::NumRemotesToTry()
   294 TInt& CRemConSession::NumRemotesToTry()
   353 const TClientInfo& CRemConSession::ClientInfo() const
   314 const TClientInfo& CRemConSession::ClientInfo() const
   354 	{
   315 	{
   355 	return iClientInfo;
   316 	return iClientInfo;
   356 	}
   317 	}
   357 
   318 
   358 TRemConClientType CRemConSession::Type() const
       
   359 	{
       
   360 	return iType;
       
   361 	}
       
   362 
       
   363 TUint CRemConSession::Id() const
   319 TUint CRemConSession::Id() const
   364 	{
   320 	{
   365 	return iId;
   321 	return iId;
   366 	}
   322 	}
   367 
   323 
   373 const RMessage2& CRemConSession::CurrentReceiveMessage() const
   329 const RMessage2& CRemConSession::CurrentReceiveMessage() const
   374 	{
   330 	{
   375 	return iReceiveMsg;
   331 	return iReceiveMsg;
   376 	}
   332 	}
   377 
   333 
   378 const TPlayerType& CRemConSession::PlayerType() const
   334 TBool CRemConSession::ClientAvailable() const
   379 	{
   335 	{
   380 	return iPlayerType.iPlayerType;
   336 	// Client is available as soon as it has registered the APIs
   381 	}
   337 	// it is interested in.
   382 
   338 	return iInterestedAPIs ? ETrue : EFalse;
   383 const TPlayerSubType& CRemConSession::PlayerSubType() const
       
   384 	{
       
   385 	return iPlayerType.iPlayerSubType;
       
   386 	}
       
   387 
       
   388 const TDesC8& CRemConSession::Name() const
       
   389 	{
       
   390 	return iPlayerName;
       
   391 	}
   339 	}
   392 
   340 
   393 #endif // REMCONSESSION_H
   341 #endif // REMCONSESSION_H
   394 
   342