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