remotecontrol/remotecontrolfw/server/inc/server.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 SERVER_H
       
    22 #define SERVER_H
       
    23 
       
    24 #include <e32base.h>
       
    25 #include <e32msgqueue.h>
       
    26 #include <remcon/remcontargetselectorpluginobserver.h>
       
    27 #include <remcon/clientid.h>
       
    28 
       
    29 #include "bulkservermsgqueue.h"
       
    30 #include "connectionstate.h"
       
    31 #include "tspv4stub.h"
       
    32 #include "utils.h"
       
    33 
       
    34 class REComSession;
       
    35 class CBearerManager;	
       
    36 class CConverterManager;
       
    37 class CRemConTargetClientProcess;
       
    38 class CRemConSession;
       
    39 class CRemConTargetSession;
       
    40 class CRemConControllerSession;
       
    41 class CMessageQueue;
       
    42 class CRemConTargetSelectorPlugin;
       
    43 class CRemConMessage;
       
    44 class CRemConConverterPlugin;
       
    45 class CMessageRecipientsList;
       
    46 class TClientInfo;
       
    47 class TRemConAddress;
       
    48 class CConnectionHistory;
       
    49 class CConnections;
       
    50 class MRemConTargetSelectorPluginInterface;
       
    51 class MRemConTargetSelectorPluginInterfaceV2;
       
    52 class MRemConTargetSelectorPluginInterfaceV3;
       
    53 class MRemConTargetSelectorPluginInterfaceV4;
       
    54 class MRemConConverterInterface;
       
    55 
       
    56 // helper classes
       
    57 class CBulkThreadWatcher;
       
    58 
       
    59 /**
       
    60 The server class for Rem Con.
       
    61 */
       
    62 NONSHARABLE_CLASS(CRemConServer) : public CPolicyServer, public MRemConTargetSelectorPluginObserver
       
    63 	{
       
    64 friend class CBulkThreadWatcher; // helper active object
       
    65 public:
       
    66 	/**
       
    67 	RemCon server construction.
       
    68 	@return Ownership of a new RemCon server object
       
    69 	*/
       
    70 	static CRemConServer* NewLC();
       
    71 
       
    72 	~CRemConServer();
       
    73 
       
    74 public: // called by controller session objects 
       
    75 
       
    76 	/** Called by a controller session when created. Cancels the 
       
    77 	shutdown timer in accordance with transient server design. */
       
    78 	TInt ControllerClientOpened(CRemConControllerSession& aSession);
       
    79 		
       
    80 	/** Called by a controller session when it has had its features registered. */
       
    81 	void ControllerClientAvailable();
       
    82 
       
    83 	/** Called by a controller session when it has had its client go connection oriented
       
    84 	Uses the bearer manager to inform bearers as appropriate
       
    85 	aUid is the uid of the bearer we are going connection oriented on.
       
    86 	*/
       
    87 	void ClientGoConnectionOriented(CRemConControllerSession& aSession, TUid aUid);
       
    88 	
       
    89 	/** Called by a controller session when it has had its client go connection less.
       
    90 	 Uses the bearer manager to inform bearers as appropriate.
       
    91 	 aUid is the uid of the bearer we were connection oriented on,
       
    92 	*/
       
    93 	void ClientGoConnectionless(CRemConControllerSession& aSession, TUid aUid);
       
    94 
       
    95 	/** Called by a controller session it is destroyed. Starts the 
       
    96 	shutdown timer if necessary in accordance with transient server design. 
       
    97 	Does not assume that the session successfully registered itself with the 
       
    98 	server to begin with.
       
    99 	aUid is the bearer uid the session was on for connection oriented sessions,
       
   100 	if KNullUid the session was connectionless, 
       
   101 	*/
       
   102 	void ControllerClientClosed(CRemConControllerSession& aSession, TUid aUid);
       
   103 
       
   104 	/**
       
   105 	Sends a command.
       
   106 	Puts the command on the 'pending TSP' queue so the TSP can either address 
       
   107 	it or give it permission to send.
       
   108 	Always takes ownership of aMsg. 
       
   109 	*/
       
   110 	void SendCommand(CRemConMessage& aMsg);
       
   111 
       
   112 	/**
       
   113 	Removes any current message from this controller session from the 'outgoing pending 
       
   114 	TSP' queue. If the message is that currently being dealt with by the TSP, 
       
   115 	then cancels the TSP's operation.
       
   116 	*/
       
   117 	void SendCancel(CRemConControllerSession& aSess);
       
   118 
       
   119 	/**
       
   120 	Tries to complete a Receive request for a controller session.
       
   121 	Called by controller sessions when a Receive request is posted. The 'incoming pending 
       
   122 	delivery' queue is checked for commands waiting to be delivered to 
       
   123 	aSession. The controller session's request is completed with the first such found.
       
   124 	*/
       
   125 	void ReceiveRequest(CRemConControllerSession& aSession);
       
   126 	
       
   127 public:	// Called by target client objects (either CRemConTargetClientProcess or CRemConTargetSession)
       
   128 
       
   129 	/** 
       
   130 	Called by CRemConTargetClientProcess to cancel the servers shutdown timer when a new
       
   131 	target session has been opened.
       
   132 	*/
       
   133 	void CancelShutdownTimer();
       
   134 
       
   135 	/** Called by CRemConTargetClientProcess to notify the server that it is available.
       
   136 	This is done when the client has registered one or more interfaces. */
       
   137 	void TargetClientAvailable(const CRemConTargetClientProcess& aClient);
       
   138 
       
   139 	/** Called by CRemConTargetClientProcess to notify the server that it has registered
       
   140 	additional intefaces. */
       
   141 	void TargetFeaturesUpdated(CRemConTargetClientProcess& aClient);
       
   142 
       
   143 	/** Called by CRemConTargetClientProcess to notify the server that a target session
       
   144 	has closed. */
       
   145 	void TargetSessionClosed(CRemConTargetClientProcess& aClient, CRemConTargetSession& aSession);
       
   146 
       
   147 	/** Called by CRemConTargetClientProcess to notify the server that a client session is closing.
       
   148 	Starts the shutdown timer if necessary in accordance with transient server design. 
       
   149 	Does not assume that the session successfully registered itself with the 
       
   150 	server to begin with.
       
   151 	*/
       
   152 	void TargetClientClosed(CRemConTargetClientProcess& aClient);
       
   153 
       
   154 	/** Called by a client instance when a session is created. Makes an item 
       
   155 	for the session in the record of which points in the connection history 
       
   156 	sessions are interested in. */
       
   157 	TInt RegisterTargetSessionPointerToConnHistory(const CRemConTargetSession& aSession);
       
   158 
       
   159 	/**
       
   160 	Starts the process of sending a response, via the TSP
       
   161 	Completes the client's send message with a bearer-level error.
       
   162 	Always takes ownership of aMsg. 
       
   163 	*/
       
   164 	void SendResponse(CRemConMessage& aMsg, CRemConTargetClientProcess& aClient);
       
   165 
       
   166 	/** Finishes the process of sending a response, after the TSP
       
   167 	has permitted the response
       
   168 	Always takes onwership of aMsg.
       
   169 	*/
       
   170 	void CompleteSendResponse(CRemConMessage& aMsg, CRemConTargetClientProcess& aClient);
       
   171 
       
   172 	/**
       
   173 	Sends a reject back to the bearer.
       
   174 	*/
       
   175 	void SendReject (TRemConAddress aAddr, TUid aInterfaceUid, TUint aOperationId, TUint aTransactionId);
       
   176 
       
   177 	/**
       
   178 	Tries to complete a Receive request for a target client.
       
   179 	Called by clients when a Receive request is posted. The 'incoming pending 
       
   180 	delivery' queue is checked for commands waiting to be delivered to 
       
   181 	the client. A delivery attempt is made for each pending message.
       
   182 	*/
       
   183 	void ReceiveRequest(CRemConTargetClientProcess& aClient);
       
   184 
       
   185 public:	// called by controller and target sessions
       
   186 
       
   187 	/** Returns the current bearer-level connection state of the system. */
       
   188 	CConnections& Connections();
       
   189 
       
   190 	/** Each session has a pointer into the connection history- pointing at 
       
   191 	the record in the history in which the session is interested. This 
       
   192 	function moves the pointer (for the given session) to the last item in the 
       
   193 	history. */
       
   194 	void SetConnectionHistoryPointer(TUint aSessionId);
       
   195 
       
   196 	/** Gets the record in the connection history which the session is 
       
   197 	pointing to. */
       
   198 	const CConnections& Connections(TUint aSessionId) const;
       
   199 
       
   200 	/** Returns ETrue if the given session's currently flagged connection 
       
   201 	history record is the 'Last' connection history record, i.e. the current 
       
   202 	connection set. Returns EFalse otherwise. */
       
   203 	TBool ConnectionHistoryPointerAtLatest(TUint aSessionId) const;
       
   204 
       
   205 	/**
       
   206 	Determines a state of a connection to the given remote address.
       
   207 	@param - aAddr, remote address of a connection
       
   208 	@return - connection state 
       
   209 	*/
       
   210 	TConnectionState ConnectionState(const TRemConAddress& aAddr);
       
   211 
       
   212 	/**
       
   213 	Informs RemCon server that one of the interfaces being used by the calling
       
   214 	session requires the use of the bulk server.
       
   215 	*/
       
   216 	TInt BulkServerRequired();	
       
   217 	
       
   218 public: // called by the bearer manager 
       
   219 
       
   220 	/** This function is called when a ConnectIndicate is handled by the 
       
   221 	bearer manager (in which case aError will be KErrNone) and when 
       
   222 	ConnectConfirm is handled by the bearer manager (in which case aError will 
       
   223 	be the connection error). 
       
   224 	@return Error. If we cannot handle the new connection (if there is one) 
       
   225 	then the bearer must drop the connection. Note that if aError is not 
       
   226 	KErrNone the return value will be meaningless.
       
   227 	*/
       
   228 	TInt HandleConnection(const TRemConAddress& aAddr, TInt aError);
       
   229 
       
   230 	/** This function is called when a connection goes away, either by 
       
   231 	indication (from the remote end) or confirmation (from our end). */
       
   232 	void RemoveConnection(const TRemConAddress& aAddr, TInt aError);
       
   233 
       
   234 	/** 
       
   235 	Handles a new incoming response. 
       
   236 	Finds the (assumed single) command on the 'outgoing sent' queue matching 
       
   237 	it, to find the session which sent _that_. Gives the new response to that 
       
   238 	client session. 
       
   239 	Always takes ownership of aMsg. 
       
   240 	*/
       
   241 	void NewResponse(CRemConMessage& aMsg);
       
   242 	
       
   243 	/** 
       
   244 	Handles a new incoming response for a notify command. 
       
   245 	Finds the (assumed single) command on the 'outgoing sent' queue matching 
       
   246 	it, to find the session which sent _that_. Gives the new response to that 
       
   247 	client session. 
       
   248 	Always takes ownership of aMsg. 
       
   249 	*/
       
   250 	void NewNotifyResponse(CRemConMessage& aMsg);
       
   251 
       
   252 	/** 
       
   253 	Handles a new incoming command.
       
   254 	Puts the message on the 'incoming response pending' queue. If the TSP is 
       
   255 	not busy, asks it to address the message to target client(s). If the TSP 
       
   256 	is busy, then the queue will be checked (and the next message handled) 
       
   257 	when the TSP calls IncomingCommandAddressed. 
       
   258 	Always takes ownership of aMsg.
       
   259 	*/
       
   260 	void NewCommand(CRemConMessage& aMsg);
       
   261 	
       
   262 	/** 
       
   263 	Handles a new incoming notify command.
       
   264 	Puts the message on the 'incoming response pending' queue. If the TSP is 
       
   265 	not busy, asks it to address the message to target client. If the TSP 
       
   266 	is busy, then the queue will be checked (and the next message handled) 
       
   267 	when the TSP calls IncomingNotifyCommandAddressed. 
       
   268 	Always takes ownership of aMsg.
       
   269 	*/
       
   270 	void NewNotifyCommand(CRemConMessage& aMsg);
       
   271 
       
   272 	/** Returns the converter interface which supports the given outer-layer 
       
   273 	API and bearer UIDs, or NULL if it does not exist. */
       
   274 	MRemConConverterInterface* Converter(TUid aInterfaceUid, TUid aBearerUid) const;
       
   275 	
       
   276 	/** Returns the converter interface which supports the given outer-layer 
       
   277 	API and bearer UIDs, or NULL if it does not exist. */
       
   278 	MRemConConverterInterface* Converter(const TDesC8& aInterfaceData, TUid aBearerUid) const;
       
   279 
       
   280 	void CommandExpired(TUint aTransactionId);
       
   281 	
       
   282 	TInt SupportedInterfaces(const TRemConClientId& aId, RArray<TUid>& aUids);
       
   283 	TInt SupportedOperations(const TRemConClientId& aId, TUid aInterfaceUid, RArray<TUint>& aOperations);
       
   284 	TInt ControllerSupportedInterfaces(RArray<TUid>& aSupportedInterfaces);
       
   285 	
       
   286 	void SetRemoteAddressedClient(const TUid& aBearerUid, const TRemConClientId& aId);
       
   287 	
       
   288 	TInt RegisterLocalAddressedClientObserver(const TUid& aBearerUid);
       
   289 	TInt UnregisterLocalAddressedClientObserver(const TUid& aBearerUid);
       
   290 
       
   291 public: // called by bulk server
       
   292 	TRemConClientId ClientIdByProcessId(TProcessId aProcessId);
       
   293 	
       
   294 	void BulkInterfacesForClientL(TRemConClientId aId, RArray<TUid>& aUids);
       
   295 
       
   296 private:
       
   297 	/** Constructor. */
       
   298 	CRemConServer();
       
   299 
       
   300 	/** 2nd-phase construction. */
       
   301 	void ConstructL();
       
   302 	
       
   303 private: // from CPolicyServer
       
   304 	/**
       
   305 	Called by the base class to create a new session.
       
   306 	@param aVersion Version of client
       
   307 	@param aMessage Client's IPC message
       
   308 	@return A new session to be used for the client. If this could not be made, 
       
   309 	this function should leave.
       
   310 	*/
       
   311 	CSession2* NewSessionL(const TVersion &aVersion, const RMessage2& aMessage) const;
       
   312 
       
   313 private: // from MRemConTargetSelectorPluginObserver
       
   314 	void MrctspoDoOutgoingCommandAddressed(TInt aError);
       
   315 	void MrctspoDoOutgoingCommandPermitted(TBool aIsPermitted);
       
   316 	void MrctspoDoOutgoingNotifyCommandPermitted(TBool aIsPermitted);
       
   317 	void MrctspoDoIncomingCommandAddressed(TInt aError);
       
   318 	TInt MrctspoDoGetConnections(TSglQue<TRemConAddress>& aConnections);
       
   319 	void MrctspoDoOutgoingResponsePermitted(TBool aIsPermitted);
       
   320 	void MrctspoDoIncomingNotifyAddressed(TClientInfo* aClientInfo, TInt aError);
       
   321 	void MrctspoDoReAddressNotifies();
       
   322 	void MrctspoDoOutgoingNotifyCommandAddressed(TRemConAddress* aConnection, TInt aError);
       
   323 	void MrctspoDoIncomingCommandPermitted(TBool aIsPermitted);
       
   324 	void MrctspoDoIncomingNotifyPermitted(TBool aIsPermitted);
       
   325 	TInt MrctspoSetLocalAddressedClient(const TUid& aBearerUid, const TClientInfo& aClientInfo);
       
   326 
       
   327 private: // utility
       
   328 	CRemConControllerSession* CreateControllerSessionL(const RMessage2& aMessage);
       
   329 	CRemConTargetSession* CreateTargetSessionL(const RMessage2& aMessage);
       
   330 
       
   331 	/** Extracts a client's process ID and secure ID from a given RMessage2 and stores
       
   332 	in a given TClientInfo. */
       
   333 	void ClientProcessAndSecureIdL(TClientInfo& aClientInfo, const RMessage2& aMessage) const;
       
   334 
       
   335 	void RemoveSessionFromConnHistory(const CRemConSession& aSession);
       
   336 
       
   337 	/** Removes connection history records which are no longer interesting and 
       
   338 	updates the indices in iSession2ConnHistory accordingly. */
       
   339 	void UpdateConnectionHistoryAndPointers();
       
   340 
       
   341 	CRemConControllerSession* ControllerSession(TUint aSessionId) const;
       
   342 	CRemConTargetClientProcess* TargetClient(TUint aClientId) const;
       
   343 	CRemConTargetClientProcess* TargetClient(TProcessId aProcessId) const;
       
   344 	
       
   345 	void StartShutdownTimerIfNoClientsOrBulkThread();
       
   346 	void TryToDropClientProcess(TUint aClientIndex);
       
   347 	void LoadTspL();
       
   348 	
       
   349 	TBool FindDuplicateNotify(CRemConMessage& aMsg);
       
   350 	
       
   351 #ifdef __FLOG_ACTIVE
       
   352 	void LogControllerSessions() const;
       
   353 	void LogTargetSessions() const;
       
   354 	void LogRemotes() const;
       
   355 	void LogConnectionHistoryAndInterest() const;
       
   356 	void LogOutgoingCmdPendingTsp() const;
       
   357 	void LogOutgoingNotifyCmdPendingTsp() const;
       
   358 	void LogOutgoingRspPendingTsp() const;
       
   359 	void LogOutgoingPendingSend() const;
       
   360 	void LogOutgoingSent() const;
       
   361 	void LogIncomingCmdPendingAddress() const;
       
   362 	void LogIncomingNotifyCmdPendingAddress() const;
       
   363 	void LogIncomingNotifyCmdPendingReAddress() const;
       
   364 	void LogIncomingPendingDelivery() const;
       
   365 	void LogIncomingDelivered() const;
       
   366 #endif // __FLOG_ACTIVE
       
   367 	
       
   368 	CMessageQueue& OutgoingCmdPendingTsp();
       
   369 	CMessageQueue& OutgoingNotifyCmdPendingTsp();
       
   370 	CMessageQueue& OutgoingRspPendingTsp();
       
   371 	CMessageQueue& OutgoingRspPendingSend();
       
   372 	CMessageQueue& OutgoingPendingSend();
       
   373 	CMessageQueue& OutgoingSent();
       
   374 	
       
   375 	CMessageQueue& IncomingCmdPendingAddress();
       
   376 	CMessageQueue& IncomingNotifyCmdPendingAddress();
       
   377 	CMessageQueue& IncomingNotifyCmdPendingReAddress();
       
   378 	CMessageQueue& IncomingPendingDelivery();
       
   379 	CMessageQueue& IncomingDelivered();
       
   380 
       
   381 	/** 
       
   382 	Utility for sending a single outgoing command to a remote.
       
   383 	Takes a copy of aMsg and sets its Addr to aConn. If aConn exists as a 
       
   384 	bearer-level connection then it tries to send the message. If the send 
       
   385 	fails, the new message is destroyed and the function leaves. If the send 
       
   386 	succeeds, the new message is put on OutgoingSent. 
       
   387 	If aConn does not exist as a bearer-level connection, the new message is 
       
   388 	put on OutgoingPendingSend and the bearer is requested to bring up the 
       
   389 	connection.
       
   390 	Whatever happens, ownership of the new message is retained. Ownership of 
       
   391 	aMsg stays with the caller.
       
   392 	@param aSync If aConn exists as a bearer-level connection, this is set 
       
   393 	to ETrue, otherwise it is set to EFalse. It effectively indicates whether 
       
   394 	a send attempt was made synchronously (ETrue) or if we'll have to wait for 
       
   395 	a bearer-level connection to come up (EFalse). aSync is guaranteed to be 
       
   396 	set correctly whether the function leaves or not.
       
   397 	*/
       
   398 	void SendCmdToRemoteL(const CRemConMessage& aMsg, const TRemConAddress& aConn, TBool& aSync);
       
   399 
       
   400 	/** 
       
   401 	Utility for delivering a single incoming command to a client session.
       
   402 	Takes a copy of aMsg, sets its SessionId, and delivers it to aSess, 
       
   403 	putting it on the correct queue. 
       
   404 	Does not take ownership of aMsg.
       
   405 	*/
       
   406 	void DeliverCmdToClientL(const CRemConMessage& aMsg, CRemConTargetClientProcess& aClient);
       
   407 
       
   408 	/** 
       
   409 	Utility for delivering a single message to a controller client session.
       
   410 	If the session aSess has an outstanding Receive request, completes the 
       
   411 	request with aMsg. Otherwise, puts aMsg in the 'incoming pending delivery' 
       
   412 	queue. 
       
   413 	Always takes ownership of aMsg.
       
   414 	@return KErrNone if the message was successfully delivered or put on the
       
   415 	incoming pending delivered queue, otherwise one of the system wide error codes
       
   416 	Ownership of aMsg will be taken regardless of the error.
       
   417 	*/
       
   418 	TInt DeliverMessageToClient(CRemConMessage& aMsg, CRemConControllerSession& aSess);
       
   419 
       
   420 	/** 
       
   421 	Utility for delivering a single message to a target client.
       
   422 	If the client aClient has an outstanding Receive request, completes the 
       
   423 	request with aMsg and puts aMsg the 'incoming delivered' queue (since it
       
   424 	shall be a command). Otherwise, puts aMsg in the 'incoming pending delivery' 
       
   425 	queue. 
       
   426 	Always takes ownership of aMsg.
       
   427 	@return KErrNone if the message was successfully delivered or put on the
       
   428 	incoming pending delivered queue, otherwise one of the system wide error codes
       
   429 	Ownership of aMsg will be taken regardless of the error.
       
   430 	*/
       
   431 	TInt DeliverMessageToClient(CRemConMessage& aMsg, CRemConTargetClientProcess& aClient);
       
   432 
       
   433 	/** Gives the head outgoing command to the TSP for (a) addressing to 
       
   434 	remote target(s), if its address is null, or (b) permission to send, if it 
       
   435 	has a remote address. */
       
   436 	void TspOutgoingCommand();
       
   437 	
       
   438 	void TspOutgoingNotifyCommand();
       
   439 	
       
   440 	/** Gives the head incoming command to the TSP for addressing to target 
       
   441 	client(s). */
       
   442 	void AddressIncomingCommand();
       
   443 	
       
   444 	/** Gives the head incoming notify command to the TSP for addressing to target 
       
   445 	client. */
       
   446 	void AddressIncomingNotifyCommand();
       
   447 
       
   448 	/** Gives the head incoming notify command to the TSP for readdressing to target 
       
   449 	client. */
       
   450 	void ReAddressIncomingNotifyCommand();
       
   451 
       
   452 	
       
   453 	/** Gives the head outgoing response to the TSP for permission to send */
       
   454 	void PermitOutgoingResponse();
       
   455 	
       
   456 	TClientInfo* TargetClientIdToClientInfo(TRemConClientId aId);
       
   457 	
       
   458 	void InitialiseBulkServerThreadL();
       
   459 
       
   460 private: // called by the shutdown timer
       
   461 	/** 
       
   462 	Called by the shutdown timer when it fires. Terminates the server thread. 
       
   463 	@param aThis This. 
       
   464 	@return KErrNone.
       
   465 	*/
       
   466 	static TInt TimerFired(TAny* aThis);
       
   467 
       
   468 private: // owned
       
   469 	// Holds the history of the connection states of the system.
       
   470 	CConnectionHistory* iConnectionHistory;
       
   471 
       
   472 	// NB This isn't really being used as a CPeriodic, but (a) it will do the 
       
   473 	// job, and (b) it saves us writing our own concrete timer (there aren't 
       
   474 	// any other more suitable concrete timer classes).
       
   475 	CPeriodic* iShutdownTimer;
       
   476 
       
   477 	// Shutdown delay (when there are no sessions) = 1 second- there's no 
       
   478 	// point hanging around.
       
   479 	static const TUint KShutdownDelay = 1 * 1000 * 1000;
       
   480 	
       
   481 	// Not to be deleted, only closed (see ECOM API documentation).
       
   482 	REComSession* iEcom; 
       
   483 
       
   484 	CBearerManager* iBearerManager;
       
   485 	CConverterManager* iConverterManager;
       
   486 
       
   487 	// Unique identifier seed for sessions and clients.
       
   488 	// Controller sessions, target clients and target sessions all need a unique ID.
       
   489 	TUint iSessionOrClientId;
       
   490 
       
   491 	RPointerArray<CRemConControllerSession> iControllerSessions;
       
   492 	RPointerArray<CRemConTargetClientProcess> iTargetClients;
       
   493 	mutable RNestableLock iTargetClientsLock; 
       
   494 
       
   495 	// In the following discussion, mark carefully the difference between a 
       
   496 	// QUEUE of items awaiting serialised access to a resource, and a LOG of 
       
   497 	// things which have happened which we need to remember.
       
   498 	// There are nine collections of messages in the server:
       
   499 	// 1/ OutgoingCmdPendingTsp
       
   500 	// This is a QUEUE of commands (a) from our connectionless controller 
       
   501 	// clients, waiting to be addressed by the TSP, and (b) from our 
       
   502 	// connection-oriented controller clients, waiting to be 'permitted' by 
       
   503 	// the TSP. On sending, commands move off this queue to OutgoingPendingSend
       
   504 	// 2/ OutgoingRspPendingTsp
       
   505 	// This is a QUEUE of responses (a) from our clients waiting to be 
       
   506 	// 'permitted' by the TSP. On sending, commands move off this queue to...
       
   507 	// 3/ OutgoingPendingSend
       
   508 	// This is a QUEUE of messages, waiting for the relevant 
       
   509 	// bearer connection to exist so they can be sent. On sending, commands 
       
   510 	// move off this queue to...
       
   511 	// 4/ OutgoingSent
       
   512 	// This is a LOG of commands sent by our controller clients. Items here 
       
   513 	// have been given to bearers and are awaiting responses from remotes. We 
       
   514 	// remember these commands in order to match responses to the controller 
       
   515 	// session which sent the originating command.
       
   516 	// 5/ IncomingCmdPendingAddress
       
   517 	// This is a QUEUE of incoming commands (i.e. from remotes). Items here 
       
   518 	// are waiting to be given to the TSP for addressing. On being addressed 
       
   519 	// they move to IncomingPendingDelivery.
       
   520 	// 6/ IncomingNotifyCmdPendingAddress
       
   521 	// This is a QUEUE of incoming Notify commands (i.e. from remotes). Items here 
       
   522 	// are waiting to be given to the TSP for addressing. On being addressed 
       
   523 	// they move to Incoming PendingDelivery
       
   524 	// 7/ IncomingNotifyCmdPendingReAddress
       
   525 	// This is a QUEUE of incmoing Notify commands (i.e. from remotes). Items here 
       
   526 	// are waiting to be given to the TSP for readdressing, after the TSP called
       
   527 	// ReAddressNotifies. They are copied from IncomingDelivered, then the equivalent
       
   528 	// command is removed from IncomingDelivered after the TSP has readdressed, and
       
   529 	// moved to IncomingPendingDelivery
       
   530 	// 8/ IncomingPendingDelivery
       
   531 	// This is a QUEUE of incoming messages (commands and responses) waiting 
       
   532 	// to be given to our clients, i.e. for the client to post a Receive 
       
   533 	// request. (This is so that messages don't get dropped just because a 
       
   534 	// client hasn't reposted Receive quickly enough.) On being delivered, 
       
   535 	// responses are destroyed, but commands move to...
       
   536 	// 9/ IncomingDelivered
       
   537 	// This is a LOG of delivered commands. We remember them in order to 
       
   538 	// address responses to the correct remote.
       
   539 	CMessageQueue* iOutgoingCmdPendingTsp;
       
   540 	CMessageQueue* iOutgoingNotifyCmdPendingTsp;
       
   541 	CMessageQueue* iOutgoingRspPendingTsp;
       
   542 	CMessageQueue* iOutgoingRspPendingSend;
       
   543 	CMessageQueue* iOutgoingPendingSend;
       
   544 	CMessageQueue* iOutgoingSent;
       
   545 	
       
   546 	CMessageQueue* iIncomingCmdPendingAddress;
       
   547 	CMessageQueue* iIncomingNotifyCmdPendingAddress;
       
   548 	CMessageQueue* iIncomingNotifyCmdPendingReAddress;
       
   549 	CMessageQueue* iIncomingPendingDelivery;
       
   550 	CMessageQueue* iIncomingDelivered;
       
   551 
       
   552 	// NB IncomingPendingDelivery and IncomingDelivered would be more logical 
       
   553 	// as members of the session class, as we know which session these 
       
   554 	// messages are associated with. They are here in the server with the 
       
   555 	// other queues in order to make the flow of messages through the whole 
       
   556 	// system clearer and therefore easier to maintain.
       
   557 
       
   558 	// The target selector plugin, which controls the flow of commands through 
       
   559 	// the server.
       
   560 	CRemConTargetSelectorPlugin* iTsp;
       
   561 	// This is the object supplied by the TSP which implements the TSP API. 
       
   562 	// This is the mandatory base value and is guaranteed to exist once the 
       
   563 	// TSP has been load.
       
   564 	MRemConTargetSelectorPluginInterface* iTspIf;
       
   565 
       
   566 	// This is the object supplied by the TSP which implements the TSP V2 API. 
       
   567 	// The TSP may not support this interface so RemCon must handle this value
       
   568 	// being NULL.
       
   569 	MRemConTargetSelectorPluginInterfaceV2* iTspIf2;
       
   570 	
       
   571 	// This is the object supplied by the TSP which implements the TSP V3 API.
       
   572 	// The TSP may not support this interface, so RemCon must handle this 
       
   573 	// value being NULL
       
   574 	MRemConTargetSelectorPluginInterfaceV3* iTspIf3;
       
   575 
       
   576 	// This is the object supplied by the TSP which implements the TSP V4 API.
       
   577 	// If the TSP does not implement it itself this points to a stub object
       
   578 	// implementing default behaviour, so it is guaranteed to exist once the TSP
       
   579 	// has been loaded.
       
   580 	MRemConTargetSelectorPluginInterfaceV4* iTspIf4;
       
   581 	
       
   582 	// This is the object supplied by the TSP which implements the TSP V5 API.
       
   583 	// The TSP may not support this interface, so RemCon must handle this 
       
   584 	// value being NULL
       
   585 	MRemConTargetSelectorPluginInterfaceV5* iTspIf5;
       
   586 	
       
   587 	// Collections we pass to the TSP for it to indicate addressing 
       
   588 	// information back to us.
       
   589 	TSglQue<TRemConAddress> iTspConnections;
       
   590 	TSglQue<TClientInfo> iTspIncomingCmdClients;
       
   591 	TSglQue<TClientInfo> iTspIncomingNotifyCmdClients;
       
   592 
       
   593 	// List of which clients each message was delivered to	
       
   594 	CMessageRecipientsList* iMessageRecipientsList;
       
   595 	
       
   596 	// Flags to control serialised access to the three parts of the TSP API.
       
   597 	TBool iTspHandlingOutgoingCommand;
       
   598 	TBool iTspHandlingOutgoingNotifyCommand;
       
   599 	TBool iTspAddressingIncomingCommand;
       
   600 	TBool iTspAddressingIncomingNotifyCommand;
       
   601 	TBool iTspReAddressingIncomingNotifyCommands;
       
   602 	TBool iTspHandlingOutgoingResponse;
       
   603 
       
   604 	// Flags to control when a command is expired while being handled in TSP, so RemCon
       
   605 	// knows to remove them when the TSP is finished
       
   606 	TBool iTspDropIncomingCommand;
       
   607 	TBool iTspDropIncomingNotifyCommand;
       
   608 	
       
   609 	/** We have an array of these records, one for each session. At any point 
       
   610 	in time, each session's record's iIndex is the index of the connection 
       
   611 	history record in which that session is currently interested. */
       
   612 	struct TSessionPointerToConnectionHistory
       
   613 		{
       
   614 		/** The session ID. */
       
   615 		TUint iSessionId;
       
   616 
       
   617 		/** The index of the connection history record. */
       
   618 		TUint iIndex;
       
   619 		};
       
   620 	RArray<TSessionPointerToConnectionHistory> iSession2ConnHistory;
       
   621 	
       
   622 	TTspV4Stub iTspIf4Stub;
       
   623 
       
   624 	TBool iBulkThreadOpen;
       
   625 	RThread iBulkServerThread;
       
   626 	RMsgQueue<TBulkServerMsg> iBulkServerMsgQueue;
       
   627 	CBulkThreadWatcher*	iBulkThreadWatcher;
       
   628 	};
       
   629 
       
   630 // Inlines
       
   631 
       
   632 NONSHARABLE_CLASS(CBulkThreadWatcher)
       
   633 	: public CActive
       
   634 	{
       
   635 public:
       
   636 	CBulkThreadWatcher(CRemConServer& aServer);
       
   637 	~CBulkThreadWatcher();
       
   638 	
       
   639 	void StartL();
       
   640 	
       
   641 private: // from CActive
       
   642 	void RunL();
       
   643 	void DoCancel();
       
   644 	
       
   645 private: // unowned
       
   646 	CRemConServer&	iServer;
       
   647 	};
       
   648 
       
   649 #endif // SERVER_H