|
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 "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.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 @file |
|
24 */ |
|
25 |
|
26 #ifndef __PACKETLOGGER_H__ |
|
27 #define __PACKETLOGGER_H__ |
|
28 |
|
29 //this file defines the __FLOG_ACTIVE flag |
|
30 #include <comms-infras/commsdebugutility.h> |
|
31 |
|
32 #if defined __FLOG_ACTIVE |
|
33 |
|
34 #include <e32base.h> |
|
35 #include <es_mbuf.h> |
|
36 class RFileLogger; |
|
37 |
|
38 /** |
|
39 * Class containing methods for dumping ip |
|
40 * packets of different formats. |
|
41 * The output is written to the log file |
|
42 * produced by comms debug utility. |
|
43 * The supported output formats are listed with the |
|
44 * TDumpType enum. |
|
45 * This class cannot be derived from. |
|
46 * This class should be active only if __FLOG_ACTIVE |
|
47 * flag is defined. To ensure that use the macros |
|
48 * defined below. A sample usage would be: |
|
49 * @code |
|
50 * __PACKETLOG_DECLARATION_MEMBER |
|
51 * __PACKETLOG_NEWL(aTag, aFileName, aDumpType, aLinkType); |
|
52 * ... |
|
53 * __PACKETLOG_WRITE_PACKET(aPacket, aDirection); |
|
54 * ... |
|
55 * __PACKETLOG_DELETE; |
|
56 * @endcode |
|
57 * If the __FLOG_ACTIVE flag is not set, the macros map |
|
58 * to nothing. |
|
59 */ |
|
60 class CPacketLogger : public CBase |
|
61 { |
|
62 public: |
|
63 /** Output dump formats supported by this class */ |
|
64 enum TDumpType |
|
65 { |
|
66 /** Produced dump will be in tcp dump format */ |
|
67 ETcpDump, |
|
68 /** Produced dump will be in ppp dump format */ |
|
69 EPppDump |
|
70 }; |
|
71 |
|
72 public: |
|
73 IMPORT_C static CPacketLogger* NewL(const TDesC8& aTag, const TDesC8& aFileName, const TDumpType aDumpType, const TInt aLinkType); |
|
74 IMPORT_C ~CPacketLogger(); |
|
75 IMPORT_C void WritePacket(const RMBufChain& aPacket, const TUint8 aDirection); |
|
76 IMPORT_C void WritePacket(const TDesC8& aPacket, const TUint8 aDirection); |
|
77 IMPORT_C void WriteText(const TDesC8& aText); |
|
78 |
|
79 private: |
|
80 void ConstructL(const TDesC8& aTag, const TDesC8& aFileName, const TDumpType aDumpType, const TInt aLinkType); |
|
81 CPacketLogger(); |
|
82 |
|
83 private: |
|
84 void WriteTcpDumpHeader(const TInt aLinkType); |
|
85 void TcpDumpPacket(const TDesC8& aPacket); |
|
86 |
|
87 void WritePppDumpHeader(); |
|
88 void PppDumpPacket(const TDesC8& aPacket, const TUint8 aDirection); |
|
89 |
|
90 private: |
|
91 /** Specifies the output format for the dumps */ |
|
92 TDumpType iDumpType; |
|
93 /** Marks the start time when the last packet was received for dumping */ |
|
94 TInt64 iTimeLastPacket; |
|
95 /** The time between system ticks, in microseconds. */ |
|
96 TInt64 iTickPeriod; |
|
97 /** Counter for the number of packets successfully dumped */ |
|
98 TUint32 iPacketCounter; |
|
99 /** Internal buffer to optimize memory allocation for WritePacket(const RMBufChain& aPacket, const TUint8 aDirection)*/ |
|
100 HBufC8* iHBuf; |
|
101 /** Used for directing output to comms debug utility */ |
|
102 __FLOG_DECLARATION_MEMBER; |
|
103 }; |
|
104 |
|
105 #define __PACKETLOG_DECLARATION_MEMBER CPacketLogger* __packetLogger__ |
|
106 |
|
107 #define __PACKETLOG_NEWL(aTag, aFileName, aDumpType, aDumpFormat) __packetLogger__ = CPacketLogger::NewL(aTag, aFileName, aDumpType, aDumpFormat) |
|
108 |
|
109 #define __PACKETLOG_DELETE delete __packetLogger__; __packetLogger__ = NULL |
|
110 |
|
111 #define __PACKETLOG_WRITE_PACKET(aPacket, aDirection) __packetLogger__->WritePacket(aPacket, aDirection) |
|
112 |
|
113 #define __PACKETLOG_LOG(aText) __packetLogger__->WriteText(aText) |
|
114 |
|
115 #else //__FLOG_ACTIVE |
|
116 |
|
117 #define __PACKETLOG_DECLARATION_MEMBER TInt32 __noLogger__ |
|
118 |
|
119 #define __PACKETLOG_NEWL(aTag, aFileName, aDumpType, aDumpFormat) |
|
120 |
|
121 #define __PACKETLOG_DELETE |
|
122 |
|
123 #define __PACKETLOG_WRITE_PACKET(aPacket, aDirection) |
|
124 |
|
125 #define __PACKETLOG_LOG(aText) __packetLogger__->WriteText(aText) |
|
126 |
|
127 #endif //__FLOG_ACTIVE |
|
128 |
|
129 #endif // __PACKETLOGGER_H__ |