epoc32/include/networking/packetlogger.h
branchSymbian3
changeset 4 837f303aceeb
parent 3 e1b950c65cb4
equal deleted inserted replaced
3:e1b950c65cb4 4:837f303aceeb
     1 /**
       
     2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 * Networking packet logging utility
       
    16 * 
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 /**
       
    25  @file
       
    26 */
       
    27 
       
    28 #ifndef __PACKETLOGGER_H__
       
    29 #define __PACKETLOGGER_H__
       
    30 
       
    31 //this file defines the __FLOG_ACTIVE flag
       
    32 #include <comms-infras/commsdebugutility.h>
       
    33 
       
    34 #if defined __FLOG_ACTIVE
       
    35 
       
    36 #include <e32base.h>
       
    37 #include <es_mbuf.h>
       
    38 class RFileLogger;
       
    39 
       
    40 /**
       
    41  * Class containing methods for dumping ip
       
    42  * packets of different formats.
       
    43  * The output is written to the log file 
       
    44  * produced by comms debug utility.
       
    45  * The supported output formats are listed with the 
       
    46  * TDumpType enum.
       
    47  * This class cannot be derived from.
       
    48  * This class should be active only if __FLOG_ACTIVE
       
    49  * flag is defined. To ensure that use the macros
       
    50  * defined below. A sample usage would be:
       
    51  * @code
       
    52  *   __PACKETLOG_DECLARATION_MEMBER
       
    53  *   __PACKETLOG_NEWL(aTag, aFileName, aDumpType, aLinkType);
       
    54  *   ...
       
    55  *   __PACKETLOG_WRITE_PACKET(aPacket, aDirection);
       
    56  *   ...
       
    57  *   __PACKETLOG_DELETE;
       
    58  * @endcode
       
    59  * If the __FLOG_ACTIVE flag is not set, the macros map
       
    60  * to nothing.
       
    61  */
       
    62 class CPacketLogger : public CBase
       
    63 	{
       
    64 public:
       
    65 	/** Output dump formats supported by this class */
       
    66 	enum TDumpType
       
    67 		{
       
    68 		/** Produced dump will be in tcp dump format */
       
    69 		ETcpDump,
       
    70 		/** Produced dump will be in ppp dump format */
       
    71 		EPppDump
       
    72 		};
       
    73 
       
    74 public:
       
    75 	IMPORT_C static CPacketLogger* NewL(const TDesC8& aTag, const TDesC8& aFileName, const TDumpType aDumpType, const TInt aLinkType);
       
    76 	IMPORT_C ~CPacketLogger();
       
    77 	IMPORT_C void WritePacket(const RMBufChain& aPacket, const TUint8 aDirection);
       
    78 	IMPORT_C void WritePacket(const TDesC8& aPacket, const TUint8 aDirection);
       
    79 	IMPORT_C void WriteText(const TDesC8& aText);
       
    80 
       
    81 private:
       
    82 	void ConstructL(const TDesC8& aTag, const TDesC8& aFileName, const TDumpType aDumpType, const TInt aLinkType);
       
    83 	CPacketLogger();
       
    84 
       
    85 private:
       
    86 	void WriteTcpDumpHeader(const TInt aLinkType);
       
    87 	void TcpDumpPacket(const TDesC8& aPacket);
       
    88 	
       
    89 	void WritePppDumpHeader();
       
    90 	void PppDumpPacket(const TDesC8& aPacket, const TUint8 aDirection);
       
    91 
       
    92 private:
       
    93 	/** Specifies the output format for the dumps */
       
    94 	TDumpType iDumpType;
       
    95 	/** Marks the start time when the last packet was received for dumping */
       
    96 	TInt64 iTimeLastPacket;
       
    97 	/** The time between system ticks, in microseconds. */
       
    98 	TInt64 iTickPeriod;
       
    99 	/** Counter for the number of packets successfully dumped */
       
   100 	TUint32 iPacketCounter;
       
   101 	/** Internal buffer to optimize memory allocation for WritePacket(const RMBufChain& aPacket, const TUint8 aDirection)*/
       
   102 	HBufC8* iHBuf;
       
   103 	/** Used for directing output to comms debug utility */
       
   104 	__FLOG_DECLARATION_MEMBER;
       
   105 	};
       
   106 
       
   107 #define __PACKETLOG_DECLARATION_MEMBER	   CPacketLogger* __packetLogger__
       
   108 
       
   109 #define __PACKETLOG_NEWL(aTag, aFileName, aDumpType, aDumpFormat) __packetLogger__ = CPacketLogger::NewL(aTag, aFileName, aDumpType, aDumpFormat)
       
   110 
       
   111 #define __PACKETLOG_DELETE  delete __packetLogger__; __packetLogger__ = NULL
       
   112 
       
   113 #define __PACKETLOG_WRITE_PACKET(aPacket, aDirection) __packetLogger__->WritePacket(aPacket, aDirection)
       
   114 
       
   115 #define __PACKETLOG_LOG(aText) __packetLogger__->WriteText(aText)
       
   116 
       
   117 #else //__FLOG_ACTIVE
       
   118 
       
   119 #define __PACKETLOG_DECLARATION_MEMBER   TInt32 __noLogger__
       
   120 
       
   121 #define __PACKETLOG_NEWL(aTag, aFileName, aDumpType, aDumpFormat)
       
   122 
       
   123 #define __PACKETLOG_DELETE
       
   124 
       
   125 #define __PACKETLOG_WRITE_PACKET(aPacket, aDirection)
       
   126 
       
   127 #define __PACKETLOG_LOG(aText) __packetLogger__->WriteText(aText)
       
   128 
       
   129 #endif //__FLOG_ACTIVE
       
   130 
       
   131 #endif // __PACKETLOGGER_H__