remotecontrol/remotecontrolfw/server/inc/bearermanager.h
changeset 51 20ac952a623c
equal deleted inserted replaced
48:22de2e391156 51:20ac952a623c
       
     1 // Copyright (c) 2004-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 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @internalComponent
       
    19 */
       
    20 
       
    21 #ifndef BEARERMANAGER_H
       
    22 #define BEARERMANAGER_H
       
    23 
       
    24 #include <e32base.h>
       
    25 #include <remcon/remconbearerobserver.h>
       
    26 #include <remcon/playertype.h>
       
    27 
       
    28 class CRemConBearerPlugin;
       
    29 class CRemConServer;
       
    30 class CRemConMessage;
       
    31 class TBearerSecurity;
       
    32 class MRemConBearerBulkInterface;
       
    33 class MRemConBearerInterface;
       
    34 class MRemConBearerInterfaceV2;
       
    35 class MRemConBearerInterfaceV3;
       
    36 
       
    37 /**
       
    38 Bearer manager.
       
    39 Owns bearer plugin instances, allows access to them, and observes them.
       
    40 APIs are provided to bring up and down connections on specific 
       
    41 TRemConAddresses. 
       
    42 The bearer manager keeps track of connections which we are in the process or 
       
    43 bringing up or down (i.e. by request). For connection and disconnection 
       
    44 _indications_, it defers to the connection history system to check that, for 
       
    45 example, a disconnect indication refers to a connection we actually already 
       
    46 knew about.
       
    47 */
       
    48 NONSHARABLE_CLASS(CBearerManager) : public CBase, public MRemConBearerObserver
       
    49 	{
       
    50 public:
       
    51 	/** 
       
    52 	Bearer manager construction.
       
    53 	@return Ownership of a new CBearerManager object
       
    54 	*/
       
    55 	static CBearerManager* NewL(CRemConServer& aServer);
       
    56 
       
    57 	/** Destructor. */
       
    58 	~CBearerManager();
       
    59 	
       
    60 	
       
    61 public:
       
    62 	struct TBulkInterfaceInfo
       
    63 		{
       
    64 		MRemConBearerBulkInterface* iIf;
       
    65 		
       
    66 		TUid iIfUid;
       
    67 		TUid iBearerUid;
       
    68 		};
       
    69 
       
    70 public:
       
    71 	/** Send a message over a specific connection and return the result 
       
    72 	immediately. */
       
    73 	TInt Send(CRemConMessage& aMsg);
       
    74 	
       
    75 	/** called by the server when a target client has registered its available
       
    76 	interfaces and is ready to be used by a remote. */
       
    77 	void TargetClientAvailable(TRemConClientId aId, const TPlayerType& aClientType, const TPlayerSubType& aClientSubType, const TDesC8& aName);
       
    78 	
       
    79 	/** called by the server when a target client has updated its available interfaces*/
       
    80 	void TargetFeaturesUpdated(TRemConClientId aId, const TPlayerType& aPlayerType, const TPlayerSubType& aPlayerSubType, const TDesC8& aName);
       
    81 	
       
    82 	/** Called by the server when a controller client has registered its 
       
    83 	available interfaces.  
       
    84 	*/
       
    85 	void ControllerClientAvailable();
       
    86 	
       
    87 	/** called by the server when a client is going connection oriented.
       
    88 	Informs each bearer in turn, if required, when controller count goes 1->0 */
       
    89 	void ClientConnectionOriented(TUid aUid);
       
    90 	
       
    91 	/** called by the server when a client is going connection oriented.
       
    92 	Informs each bearer in turn, if required, when controller count goes 0->1 */
       
    93 	void ClientConnectionless(TUid aOldUid);
       
    94 
       
    95 	/** called by the server when a client has closed (only if controller or target)
       
    96 	calls back to server to see whether it needs to inform each bearer in turn */
       
    97 	void ClientClosed(TBool aController, TUid aOldUid, TRemConClientId aClientId);
       
    98 	
       
    99 	/** Called by the server to get the security policies of the bearers. */
       
   100 	TSglQue<TBearerSecurity>& BearerSecurityPolicies();
       
   101 
       
   102 	/** Tries to bring up a connection on an address. 
       
   103 	@return KErrNone- a bearer-level connect has been issued (or was already 
       
   104 	outstanding) and will be confirmed in due course. Other than KErrNone- we 
       
   105 	could not remember the address (no connection will be made). */
       
   106 	TInt Connect(const TRemConAddress& aAddr);
       
   107 
       
   108 	/** Tries to tear down a connection on an address. 
       
   109 	@return KErrNone- a bearer-level disconnect has been issued (or was 
       
   110 	already outstanding) and will be confirmed in due course. Other than 
       
   111 	KErrNone- we could not remember the address (no disconnection will be 
       
   112 	performed). */
       
   113 	TInt Disconnect(const TRemConAddress& aAddr);
       
   114 
       
   115 	/** @return ETrue- the bearer with the given UID exists in the system, 
       
   116 	EFalse otherwise. */
       
   117 	TBool BearerExists(TUid aBearerUid) const;
       
   118 
       
   119 	/** Does a security check of the given client message against the given 
       
   120 	bearer's security policy. 
       
   121 	@return The result of TSecurityPolicy::CheckPolicy with the given message.
       
   122 	*/
       
   123 	TBool CheckPolicy(TUid aBearerUid, const RMessage2& aMessage);
       
   124 
       
   125 	/** 
       
   126 	Checks if a bearer is in the connecting state to the given remote address 
       
   127 	@param aAddr - remote address 
       
   128 	@return  - ETrue if it is the connecting state
       
   129 	*/
       
   130 	TBool IsConnecting(const TRemConAddress& aAddr) const;
       
   131 	
       
   132 	/** 
       
   133 	Checks if a bearer is in the disconnecting state from the given remote address 
       
   134 	@param aAddr - remote address
       
   135 	@return ETrue - if it is in the disconnecting state
       
   136 	*/
       
   137 	TBool IsDisconnecting(const TRemConAddress& aAddr) const;
       
   138 	
       
   139 	TInt SetLocalAddressedClient(const TUid& aBearerUid, TRemConClientId aClientInfo);
       
   140 	
       
   141 	/**
       
   142 	This function is called from the context of the bulk server thread and is used to retrieve the
       
   143 	bulk interfaces (that are managed in a separate class).
       
   144 	No locking is provided so it is expected that the GetInterface implementation is re-entrant with
       
   145 	respect to distribution of requests.
       
   146 	@param aBulkInterfaces The array to populate with bulk interface information.
       
   147 	*/
       
   148 	void BulkInterfacesL(RArray<TBulkInterfaceInfo>& aBulkInterfaces) const;
       
   149 	
       
   150 private:
       
   151 	/** Constructor. */
       
   152 	CBearerManager(CRemConServer& aServer);
       
   153 
       
   154 	/** 2nd-phase construction. */
       
   155 	void ConstructL();
       
   156 
       
   157 private: // from MRemConBearerObserver
       
   158 	TInt MrcboDoNewResponse(const TRemConAddress& aAddr);
       
   159 	TInt MrcboDoNewNotifyResponse(const TRemConAddress& aAddr);
       
   160 	TInt MrcboDoNewCommand(const TRemConAddress& aAddr);
       
   161 	TInt MrcboDoNewNotifyCommand(const TRemConAddress& aAddr);
       
   162 	TInt MrcboDoConnectIndicate(const TRemConAddress& aAddr);
       
   163 	void MrcboDoDisconnectIndicate(const TRemConAddress& aAddr);
       
   164 	TInt MrcboDoNewCommand(const TRemConAddress& aAddr, const TRemConClientId& aClient);
       
   165 	TInt MrcboDoNewNotifyCommand(const TRemConAddress& aAddr, const TRemConClientId& aClient);
       
   166 	void MrcboDoSetRemoteAddressedClient(const TUid& aBearerUid, const TRemConClientId& aId);
       
   167 
       
   168 
       
   169 	/** Called in response to a connection request by us. */
       
   170 	TInt MrcboDoConnectConfirm(const TRemConAddress& aAddr, TInt aError);
       
   171 
       
   172 	/** Called in response to a disconnection request by us. */
       
   173 	void MrcboDoDisconnectConfirm(const TRemConAddress& aAddr, TInt aError);
       
   174 
       
   175 	TUint MrcboDoNewTransactionId();
       
   176 
       
   177 	TInt MrcboDoInterfaceToBearer(TUid aBearerUid,
       
   178 		TUid aInterfaceUid, 
       
   179 		TUint aOperationId,
       
   180 		const TDesC8& aData,
       
   181 		TRemConMessageType aMsgType, 
       
   182 		TDes8& aBearerData) const;
       
   183 	TInt MrcboDoBearerToInterface(TUid aBearerUid,
       
   184 		const TDesC8& aInterfaceData, 
       
   185 		const TDesC8& aBearerData,
       
   186 		TUid& aInterfaceUid, 
       
   187 		TUint& aOperationId,
       
   188 		TRemConMessageType& aMsgType, 
       
   189 		TDes8& aData) const;
       
   190 	
       
   191 	void MrcboDoCommandExpired(TUint aTransactionId);
       
   192 	TInt MrcboDoSupportedInterfaces(const TRemConClientId& aId, RArray<TUid>& aUids);
       
   193 	TInt MrcboDoSupportedOperations(const TRemConClientId& aId, TUid aInterfaceUid, RArray<TUint>& aOperations);
       
   194 	
       
   195 	TInt MrcboDoRegisterLocalAddressedClientObserver(const TUid& aBearerUid);
       
   196 	TInt MrcboDoUnregisterLocalAddressedClientObserver(const TUid& aBearerUid);
       
   197 	
       
   198 private: // utility
       
   199 	/** Called during (2-phase) construction to instantiate all the bearer 
       
   200 	plugins, from ROM only. */
       
   201 	void LoadAllBearersL();
       
   202 
       
   203 #ifdef __FLOG_ACTIVE
       
   204 	void LogBearers() const;
       
   205 #endif
       
   206 	
       
   207 	void NewResponseL(const TRemConAddress& aAddr);
       
   208 	void NewNotifyResponseL(const TRemConAddress& aAddr);
       
   209 	void NewCommandL(const TRemConAddress& aAddr, const TRemConClientId& aClient);
       
   210 	void NewNotifyCommandL(const TRemConAddress& aAddr, const TRemConClientId& aClient);
       
   211 
       
   212 	MRemConBearerInterface* BearerIf(TUid aUid) const;
       
   213 	MRemConBearerInterfaceV2* BearerIfV2(TUid aUid) const;
       
   214 	MRemConBearerInterfaceV3* BearerIfV3(TUid aUid) const;
       
   215 
       
   216 private: // unowned
       
   217 	// Struct wrapping a pointer to a bearer interface object with the UID 
       
   218 	// identifying that interface and the UID identifying the bearer supplying 
       
   219 	// the interface.
       
   220 	struct TInterfaceInfo
       
   221 		{
       
   222 		MRemConBearerInterface* iIf;
       
   223 		MRemConBearerInterfaceV2* iIfV2;
       
   224 		MRemConBearerInterfaceV3* iIfV3;
       
   225 		
       
   226 		TUid iIfUid;
       
   227 		TUid iBearerUid;
       
   228 		TInt iControllerCount;
       
   229 		TInt iTargetCount;
       
   230 		};
       
   231 
       
   232 	RArray<TInterfaceInfo>	iBearerIfs;
       
   233 
       
   234 private: // owned
       
   235 	RPointerArray<CRemConBearerPlugin> iBearers;
       
   236 	TUint iRunningTransactionId;
       
   237 
       
   238 	/** All the security policies of the bearers in the system. These are 
       
   239 	given to the TSP for reference when it is addressing outgoing commands. */ 
       
   240 	TSglQue<TBearerSecurity> iBearerSecurityPolicies;
       
   241 
       
   242 	/** Array of addresses we currently have a ConnectRequest outstanding on. 
       
   243 	*/
       
   244 	RArray<TRemConAddress> iCurrentlyBeingConnected;
       
   245 
       
   246 	/** Array of addresses we currently have a DisconnectRequest outstanding 
       
   247 	on. */
       
   248 	RArray<TRemConAddress> iCurrentlyBeingDisconnected;
       
   249 	
       
   250 private: // unowned
       
   251 	CRemConServer& iServer;
       
   252 	};
       
   253 
       
   254 #endif // BEARERMANAGER_H