tcpiputils/dnd/inc/node.h
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     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 // node.h - structures to hold node information
       
    15 //
       
    16 
       
    17 #ifndef __NODE_H__
       
    18 #define __NODE_H__
       
    19 
       
    20 /**
       
    21 @file node.h
       
    22 DNS Cache (internal part of the DNS cache implementation)
       
    23 @internalComponent	Domain Name Resolver
       
    24 */
       
    25 #include "record.h"
       
    26 
       
    27 class CDndEngine;
       
    28 class CDndNode;
       
    29 
       
    30 // Implement a node list ONLY for CDndNode, not for anyone else
       
    31 class TDndNodeList : public TDblQue<CDndNode>
       
    32 	{
       
    33 	friend class CDndNode;
       
    34 	// only to initialize the offset in the TDblQue head
       
    35 	TDndNodeList();
       
    36 
       
    37 	CDndNode *Find(const TNodeLabel &aLabel);	//< Find the node by label
       
    38 	void AddNode(CDndNode &aNode);				//< Add node to the list
       
    39 	void DeleteNode(CDndNode *const aNode);		//< Delete node from the list
       
    40 	void Print(CDndEngine &aControl);			//< Prints out the contents of the node-list (DEBUG only)
       
    41 	};
       
    42 
       
    43 
       
    44 class CDndNode : public CBase
       
    45 	{
       
    46 	friend class TDndNodeList;
       
    47 	friend class CDndRecord;
       
    48 	// constructors and destructor
       
    49 protected:
       
    50 	CDndNode(CDndNode *const aParent, const TInt aLevel, const TNodeLabel &aLabel);
       
    51 	~CDndNode();
       
    52 public:
       
    53 	// Locate (and create path) to a node identified by a domain name, and find (or create) a record matching the type and class
       
    54 	CDndRecord *FindL(
       
    55 		const TDesC8 &aName,
       
    56 		const TBool aFlag,
       
    57 		const EDnsQType aType,
       
    58 		const EDnsQClass aClass,
       
    59 		TDndRecordLRU &aLRU,
       
    60 		const TTime &aReqTime);
       
    61 
       
    62 	// Prints out the contents of this node and all its descendants
       
    63 	void Print(CDndEngine &aControl);
       
    64 
       
    65 protected:
       
    66 	// Return TRUE, if node has no children and no records
       
    67 	inline TBool IsEmpty() const { return iRecordList.IsEmpty() && iChildren.IsEmpty(); }
       
    68 private:	
       
    69 	static const TInt iOffset;		//< For the linked list
       
    70 
       
    71 	// Unconditionally delete a record from the node
       
    72 	void DeleteRecord(CDndRecord *const aRecord);
       
    73 	// Delete node path, if it has no records and no child nodes
       
    74 	void Cleanup();
       
    75 	// Delete a child from the node (which, must be a child of this node!)
       
    76 	void DeleteNode(CDndNode *const aNode);
       
    77 
       
    78 	CDndNode *const iParent;	//< Back link to the parent node (except at root = NULL)
       
    79 	const TInt iLevel;			//< Depth of the node in the tree
       
    80 	const TNodeLabel iLabel;	//< Label of the node.
       
    81 	TDblQueLink iDlink;			//< Siblings chain (nodes on same level)		
       
    82 	TDndRecordList iRecordList;	//< List of Records with this node's name.
       
    83 	TDndNodeList iChildren;		//< Children are implemented as a linked list of nodes
       
    84 	};
       
    85 
       
    86 #endif