remotecontrol/remotecontrolfw/server/inc/targetclientprocess.h
changeset 51 20ac952a623c
equal deleted inserted replaced
48:22de2e391156 51:20ac952a623c
       
     1 // Copyright (c) 2010 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 // Server-side representation of a target client, which may have multiple 
       
    15 // sessions associated with it.
       
    16 // 
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 #ifndef TARGETCLIENTPROCESS_H
       
    24 #define TARGETCLIENTPROCESS_H
       
    25 
       
    26 #include <e32base.h>
       
    27 #include <remcon/clientinfo.h>
       
    28 #include <remcon/clientid.h>
       
    29 #include <remcon/playertype.h>
       
    30 
       
    31 #include "messagesendobserver.h"
       
    32 
       
    33 
       
    34 /**
       
    35 The maximum number of target sessions permitted for a single client process
       
    36 */
       
    37 const TUint KMaxNumberTargetSessions = 2;
       
    38 
       
    39 class CRemConServer;
       
    40 class CBearerManager;
       
    41 class CRemConTargetSession;
       
    42 class CRemConInterfaceDetails;
       
    43 class CRemConMessage;
       
    44 
       
    45 /**
       
    46 Represents a target client process and manages that clients sessions.
       
    47 */
       
    48 NONSHARABLE_CLASS(CRemConTargetClientProcess) : public CBase, public MRemConMessageSendObserver
       
    49 	{
       
    50 public:
       
    51 	static CRemConTargetClientProcess* NewLC(TClientInfo& aClientInfo, TRemConClientId aClientId, CRemConServer& aServer, CBearerManager& aBearerManager);
       
    52 	~CRemConTargetClientProcess();
       
    53 
       
    54 	/**
       
    55 	Returns the unique client ID for this client.
       
    56 	@return The client ID.
       
    57 	*/
       
    58 	inline TRemConClientId Id() const;
       
    59 
       
    60 	/**
       
    61 	Returns a description of the client represented by this CRemConTargetClientProcess instance.
       
    62 	@return A TClientInfo instance describing the client.
       
    63 	*/
       
    64 	inline TClientInfo& ClientInfo();
       
    65 	inline const TClientInfo& ClientInfo() const;
       
    66 
       
    67 	/**
       
    68 	Indicates whether or not this CRemConTargetClientProcess represents a client described by a given TClientInfo instance.
       
    69 	@param aClientInfo The TClientInfo instance describing the client.
       
    70 	@return ETrue if the client described by aClientInfo is that represented by this CRemConTargetClientProcess instance.
       
    71 	*/
       
    72 	inline TBool IsClient(const TClientInfo& aClientInfo) const;
       
    73 
       
    74 	/**
       
    75 	Indicates whether or not this client has been registered as available with the server.
       
    76 	@return ETrue if this client has been marked as available.
       
    77 	*/
       
    78 	inline TBool ClientAvailable() const;
       
    79 
       
    80 	/**
       
    81 	Creates a new target session for the client with a given unique session ID.
       
    82 	If the client already has KMaxNumberTargetSessions sessions open, then this will leave with KErrOverflow.
       
    83 	@param aSessionId The session ID for the new session.
       
    84 	*/
       
    85 	CRemConTargetSession* NewSessionL(TUint aSessionId);
       
    86 
       
    87 	/**
       
    88 	Called by CRemConTargetSession to provide notification of the opening of a new session.
       
    89 	@param aSession The CRemConTargetSession that is opening.
       
    90 	@return KErrNone on success, otherwise one of the other system-wide error codes.
       
    91 	*/
       
    92 	TInt TargetSessionOpened(CRemConTargetSession& aSession);
       
    93 
       
    94 	/**
       
    95 	Called by CRemConTargetSession to provide notificaton of session closure.
       
    96 	@param aSession The CRemConTargetSession that is closing.
       
    97 	*/
       
    98 	void TargetSessionClosed(CRemConTargetSession& aSession);
       
    99 
       
   100 	/**
       
   101 	Returns the number of target sessions currently open on this client.
       
   102 	@return The number of open target sessions.
       
   103 	*/
       
   104 	inline TInt TargetSessionCount() const;
       
   105 
       
   106 	/**
       
   107 	Sets the player information for this client.
       
   108 	This information can only be set once for the client.
       
   109 	@param aPlayerType The player type.
       
   110 	@param aPlayerName The player name.
       
   111 	*/
       
   112 	void SetPlayerInformationL(const TPlayerTypeInformation& aPlayerType, const TDesC8& aPlayerName);
       
   113 
       
   114 	/**
       
   115 	Indicates whether or not player information has been set for this client.
       
   116 	@return ETrue if player information has been set.
       
   117 	*/
       
   118 	inline TBool HasPlayerInformation() const;
       
   119 
       
   120 	/**
       
   121 	Returns the player type set for this client.
       
   122 	This is only valid if HasPlayerInformation() returns ETrue.
       
   123 	@return The player type.
       
   124 	*/
       
   125 	inline TPlayerType PlayerType() const;
       
   126 
       
   127 	/**
       
   128 	Returns the player subtype set for this client.
       
   129 	This is only valid if HasPlayerInformation() returns ETrue.
       
   130 	@return The player subtype.
       
   131 	*/
       
   132 	inline TPlayerSubType PlayerSubType() const;
       
   133 
       
   134 	/**
       
   135 	Returns the player name set for this client.
       
   136 	This is only valid if HasPlayerInformation() returns ETrue.
       
   137 	@return The player name.
       
   138 	*/
       
   139 	inline const TDesC8& Name() const;
       
   140 
       
   141 	/**
       
   142 	Indicates whether or not the given player information matches that set for this client.
       
   143 	This is only valid if HasPlayerInformation() returns ETrue.
       
   144 	@return ETrue if the player information matches.
       
   145 	*/
       
   146 	inline TBool PlayerInformationMatches(const TPlayerTypeInformation& aPlayerType, const TDesC8& aPlayerName) const;
       
   147 
       
   148 	/**
       
   149 	Called by CRemConTargetSession to provide notification that the session has registered a new interface.
       
   150 	@param aSession The CRemConTargetSession that has registered the new interface.
       
   151 	*/
       
   152 	void InterfacesRegistered();
       
   153 
       
   154 	/**
       
   155 	Determines whether or not an interface of the same type as that given has already been registered
       
   156 	in a session owned by this client, other than the given session.
       
   157 	@param aSession The target session to exclude from the interface search.
       
   158 	@param aInterface The interface type to test for.
       
   159 	@return Whether or not a registered interface of this type exists for the client.
       
   160 	**/
       
   161 	TBool IsInterfaceTypeRegisteredByAnotherSession(CRemConTargetSession& aSession, TUid aInterfaceUid) const;
       
   162 	
       
   163 	/**
       
   164 	Called by CRemConServer when a message has been received for this client.
       
   165 	The client will attempt to deliver the message to the appropriate session. If no session
       
   166 	supports the message, KErrArgument is returned. Otherwise, if the supporting session is
       
   167 	not ready to receive the message, KErrNotReady is returned. Any other error code is returned
       
   168 	by the session as it processes the message.
       
   169 	@param aMessage The message for this client.
       
   170 	@return KErrArgument if no session supports this message, KErrNotReady if the message cannot be handled yet, or an error
       
   171 	code returned by the session as it processes the message.
       
   172 	*/
       
   173 	TInt ReceiveMessage(CRemConMessage& aMessage);
       
   174 
       
   175 	/**
       
   176 	Indicates that a connection has come up or down.
       
   177 	This notifies each session held by this client.
       
   178 	*/
       
   179 	void ConnectionsChanged();
       
   180 
       
   181 	/**
       
   182 	Provides a list of interfaces supported by this client.
       
   183 	@param aUids An RArray to hold the UIDs of the supported interfaces.
       
   184 	@return KErrNone on success, otherwise one of the system-wide error codes.
       
   185 	*/
       
   186 	TInt SupportedInterfaces(RArray<TUid>& aUids);
       
   187 
       
   188 	/**
       
   189 	Provides a list of interfaces supported by this client that require the bulk server.
       
   190 	@param aUids An RArray to hold the UIDs of the interfaces.
       
   191 	@return KErrNone on success, otherwise one of the system-wide error codes.
       
   192 	*/
       
   193 	TInt SupportedBulkInterfaces(RArray<TUid>& aUids);
       
   194 
       
   195 	/**
       
   196 	Provides a list of operations supported by a particular interface.
       
   197 	@param aInterfaceUid The UID of the interface of interest.
       
   198 	@param aOperations An RArray to hold the supported operations.
       
   199 	@return KErrNone on success, otherwise one of the system-wide error codes.
       
   200 	*/
       
   201 	TInt SupportedOperations(TUid aInterfaceUid, RArray<TUint>& aOperations);
       
   202 
       
   203 public:	// From MRenConMessageSendObserver
       
   204 	void MrcmsoMessageSendResult(const CRemConMessage& aMessage, TInt aError);	// Not supported
       
   205 	void MrcmsoMessageSendOneOrMoreAttempt(const CRemConMessage& aMessage, TUint aNumRemotes);
       
   206 	void MrcmsoMessageSendOneOrMoreIncremental(const CRemConMessage& aMessage, TUint aNumRemotes);
       
   207 	void MrcmsoMessageSendOneOrMoreAttemptFailed(const CRemConMessage& aMessage, TInt aError);
       
   208 	void MrcmsoMessageSendOneOrMoreResult(const CRemConMessage& aMessage, TInt aError);
       
   209 	void MrcmsoMessageSendOneOrMoreAbandoned(const CRemConMessage& aMessage);
       
   210 
       
   211 private:
       
   212 	CRemConTargetClientProcess(TClientInfo& aClientInfo, TRemConClientId aClientId, CRemConServer& aServer, CBearerManager& aBearerManager);
       
   213 
       
   214 	/**
       
   215 	Returns the target session that supports a given RemCon message.
       
   216 	Since no two sessions may register the same interface, there is a maximum of one possible session that could support the message.
       
   217 	@param aMessage The RemCon message.
       
   218 	@return The supporting CRemConTargetSession instance or NULL if no supporting session could be found.
       
   219 	*/
       
   220 	CRemConTargetSession* FindSessionForMessage(const CRemConMessage& aMessage);
       
   221 
       
   222 	/**
       
   223 	Returns an index to a target session held by this client that supports a particular interface.
       
   224 	@param aInterface The UID of the interface of interest.
       
   225 	@return If found, the index of the relevent target session. Otherwise, KErrNotFound or one of the other system-wide error codes.
       
   226 	*/
       
   227 	TInt FindSessionForInterface(TUid aInterface) const;
       
   228 
       
   229 	/**
       
   230 	Utility method to complete a given RemCon message for a particular target session.
       
   231 	@param aMessage The RemCon message
       
   232 	@param aSession The target session
       
   233 	*/
       
   234 	void CompleteMessageForSession(const CRemConMessage& aMessage, CRemConTargetSession& aSession);
       
   235 
       
   236 private:
       
   237 	// Client information
       
   238 	TClientInfo iClientInfo;
       
   239 	TRemConClientId iClientId;
       
   240 	TBool iClientAvailable;
       
   241 
       
   242 	CRemConServer& iServer;
       
   243 	CBearerManager& iBearerManager;
       
   244 
       
   245 	// Player information
       
   246 	TPlayerTypeInformation iPlayerType;
       
   247 	RBuf8 iPlayerName;
       
   248 	TBool iPlayerInfoSet;
       
   249 
       
   250 	// Target sessions for this client
       
   251 	RPointerArray<CRemConTargetSession> iTargetSessions;
       
   252 	
       
   253 	};
       
   254 
       
   255 #include "targetclientprocess.inl"
       
   256 
       
   257 #endif // TARGETCLIENTPROCESS_H