accessoryservices/remotecontrolfw/server/inc/connectionhistory.h
changeset 0 4e1aa6a622a0
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 CONNECTIONHISTORY_H
       
    22 #define CONNECTIONHISTORY_H
       
    23 
       
    24 #include <e32base.h>
       
    25 
       
    26 class CConnections;
       
    27 class TRemConAddress;
       
    28 
       
    29 /**
       
    30 Encapsulates the history of the connection statuses. 
       
    31 Each item in the history is a CConnections. So, at any point in time, the 
       
    32 CConnections given by Last will represent the currently extant connections in 
       
    33 the system. 
       
    34 Note that this class allows the client to remove older items from the history 
       
    35 as they become uninteresting.
       
    36 Provides APIs to extend or grow the history when connections or disconnections 
       
    37 occur. In each case a new CConnections is made, based on Last, reflecting the 
       
    38 new change. 
       
    39 As an implementation detail, the disconnection API uses memory pre-allocated 
       
    40 at connection time to make sure that it cannot fail, as required (ultimately) 
       
    41 by the Bearer API.
       
    42 */
       
    43 NONSHARABLE_CLASS(CConnectionHistory) : public CBase
       
    44 	{
       
    45 public:
       
    46 	/**
       
    47 	Makes a new connection history- a holder for the connection statuses as 
       
    48 	they evolve over time. Seeds itself with the initial state of the system 
       
    49 	(no connections).
       
    50 	@return Ownership of a new CConnectionHistory object.
       
    51 	*/
       
    52 	static CConnectionHistory* NewL();
       
    53 
       
    54 	/** Destructor. */
       
    55 	~CConnectionHistory();
       
    56 
       
    57 public:
       
    58 	/**
       
    59 	Destroys the first item in the connection history. Used when no session is 
       
    60 	interested in it any more. Debug-asserts that the history is empty neither 
       
    61 	before nor after the call.
       
    62 	*/
       
    63 	void DestroyFirst();
       
    64 
       
    65 	/**
       
    66 	Gets the number of items in the history. This is always >= 1.
       
    67 	*/
       
    68 	TUint Count() const;
       
    69 
       
    70 	/**
       
    71 	Accessor for a point in the connection history. If aIndex is out of range, 
       
    72 	panics.
       
    73 	@param aIndex Index of the desired point in the connection history.
       
    74 	@return A specific set of connections.
       
    75 	*/
       
    76 	const CConnections& operator[](TUint aIndex);
       
    77 
       
    78 	/**
       
    79 	Used to access the last item in the history, i.e. the current set of 
       
    80 	connections.
       
    81 	*/
       
    82 	CConnections& Last();
       
    83 
       
    84 	/**
       
    85 	Used when a connection is made. Pre-allocates memory so that any 
       
    86 	subsequent disconnection is guaranteed to work, and makes a new 'last' 
       
    87 	item on the history expressing the current state of the system (i.e. the 
       
    88 	previous state of the system, plus the change expressed by this call).
       
    89 	@param aAddr The new remote.
       
    90 	*/
       
    91 	TInt NewConnection(const TRemConAddress& aAddr);
       
    92 
       
    93 	/**
       
    94 	Used when a connection comes down. Uses the pre-allocated memory to make a 
       
    95 	new latest item in the history expressing the current state of the system 
       
    96 	(i.e. the previous state of the system, minus the connection which just 
       
    97 	went away).
       
    98 	@param aAddr The disappearing remote.
       
    99 	*/
       
   100 	void Disconnection(const TRemConAddress& aAddr);
       
   101 
       
   102 	/**
       
   103 	Logs the connection history. Note that this might not be the complete 
       
   104 	connection history, as earlier items are dropped as they become 
       
   105 	uninteresting. */
       
   106 	void LogConnectionHistory() const;
       
   107 
       
   108 private: // utility
       
   109 	void NewConnectionL(const TRemConAddress& aAddr);
       
   110 #ifdef __FLOG_ACTIVE
       
   111 	void LogCollectionPool() const;
       
   112 	void LogAddressPool() const;
       
   113 #endif // __FLOG_ACTIVE
       
   114 
       
   115 private:
       
   116 	/** Constructor. */
       
   117 	CConnectionHistory();
       
   118 
       
   119 	/** 2nd-phase construction. */
       
   120 	void ConstructL();
       
   121 		
       
   122 private: // owned
       
   123 	/** The history. */
       
   124 	TSglQue<CConnections> iHistory;
       
   125 
       
   126 	/** Pre-allocated pool of CConnections, to be used when a disconnection 
       
   127 	occurs. */
       
   128 	TSglQue<CConnections> iConnectionsPool;
       
   129 
       
   130 	/** Pre-allocated pool of TRemConAddresses, to be used when a 
       
   131 	disconnection occurs. */
       
   132 	TSglQue<TRemConAddress> iAddressPool;
       
   133 	};
       
   134 
       
   135 #endif // CONNECTIONSTATUSHISTORY_H