remotecontrol/remotecontrolfw/server/inc/connections.h
changeset 51 20ac952a623c
equal deleted inserted replaced
48:22de2e391156 51:20ac952a623c
       
     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 CONNECTIONS_H
       
    22 #define CONNECTIONS_H
       
    23 
       
    24 #include <e32base.h>
       
    25 #include <remconaddress.h>
       
    26 
       
    27 /**
       
    28 Encapsulates a snapshot of all the connections (remotes) in RemCon at one 
       
    29 point in time.
       
    30 */
       
    31 NONSHARABLE_CLASS(CConnections) : public CBase
       
    32 	{
       
    33 public:
       
    34 	/** Link between elements of this type in a TSglQue. */
       
    35 	TSglQueLink iLink;
       
    36 
       
    37 public:
       
    38 	/**
       
    39 	@return Ownership of a new CConnections object.
       
    40 	*/
       
    41 	static CConnections* NewL();
       
    42 	
       
    43 	/**
       
    44 	@return Ownership of a new CConnections object, with its own (owned) 
       
    45 	copies of the data in aItem.
       
    46 	*/
       
    47 	static CConnections* CopyL(CConnections& aItem);
       
    48 	
       
    49 	/**
       
    50 	Destructor.
       
    51 	*/
       
    52 	~CConnections();
       
    53 
       
    54 public:
       
    55 	/**
       
    56 	Accessor for a member iterator over the queue. The iterator is provided 
       
    57 	set to the first item in the queue. The iterator is 'safe' (will not be 
       
    58 	otherwise interfered with) until SetToFirst or the destructor is called. 
       
    59 	@return Iterator.
       
    60 	*/
       
    61 	TSglQueIter<TRemConAddress>& SetToFirst() const;
       
    62 
       
    63 	/**
       
    64 	@return The number of remote connections.
       
    65 	*/
       
    66 	inline TUint Count() const;
       
    67 
       
    68 	/**
       
    69 	Adds a remote connection to the current set. Panics if a duplicate is 
       
    70 	already present.
       
    71 	@param aAddr The new connection.
       
    72 	*/
       
    73 	void Append(TRemConAddress& aAddr);
       
    74 
       
    75 	/**
       
    76 	Removes a remote connection to the current set. Panics if the connection 
       
    77 	is not already present.
       
    78 	Does not delete the address. This is a very special utility function- the 
       
    79 	client is expected to be assuming ownership of the address. This function 
       
    80 	effectively removes ownership of the address from this CConnections.
       
    81 	@param aAddr The connection to remove.
       
    82 	*/
       
    83 	void Remove(TRemConAddress& aAddr);
       
    84 
       
    85 	/**
       
    86 	@return ETrue if the given address is present in this set of connections, 
       
    87 	EFalse otherwise.
       
    88 	*/
       
    89 	TBool Find(const TRemConAddress& aAddr) const;
       
    90 
       
    91 	/** Logs the connections. */
       
    92 	void LogConnections() const;
       
    93 
       
    94 private:
       
    95 	/** Constructor. */
       
    96 	CConnections();
       
    97 		
       
    98 private: // owned
       
    99 	TSglQue<TRemConAddress> iConnections;
       
   100 	TSglQueIter<TRemConAddress> iIter;
       
   101 	};
       
   102 
       
   103 // Inlines
       
   104 
       
   105 TUint CConnections::Count() const
       
   106 	{
       
   107 	TUint count = 0;
       
   108 
       
   109 	TSglQueIter<TRemConAddress> iter(const_cast<CConnections*>(this)->iConnections);
       
   110 	while ( iter++ )
       
   111 		{
       
   112 		++count;
       
   113 		}
       
   114 
       
   115 	return count;
       
   116 	}
       
   117 
       
   118 #endif // CONNECTIONS_H