|
1 /* |
|
2 * Copyright (c) 2007 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: Tracks data transmitted through a network connection. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef C_IRDATATRANSFERTRACKER_H |
|
20 #define C_IRDATATRANSFERTRACKER_H |
|
21 |
|
22 #include <mhttpfilter.h> |
|
23 |
|
24 #include "irdatatransferobserver.h" |
|
25 |
|
26 |
|
27 /** |
|
28 * Tracks data transmitted through a network connection. |
|
29 * |
|
30 * Data sent or received over HTTP sessions are logged with the implemented HTTP filter. |
|
31 * For raw sockets, the implementation requires that the user of the socket notifies |
|
32 * him of data transfer explicitly. |
|
33 */ |
|
34 NONSHARABLE_CLASS( CIRDataTransferTracker ): public CBase, |
|
35 public MIRDataTransferTracker, |
|
36 public MHTTPFilter |
|
37 { |
|
38 public: |
|
39 |
|
40 /** |
|
41 * Two-phased constructor. |
|
42 * |
|
43 * @return The created object. Transfers ownership. |
|
44 */ |
|
45 static CIRDataTransferTracker* NewL( ); |
|
46 |
|
47 /** |
|
48 * Destructor. |
|
49 */ |
|
50 ~CIRDataTransferTracker(); |
|
51 |
|
52 // from base class MIRDataTransferTracker |
|
53 |
|
54 void SetObserver( MIRDataTransferObserver* ); |
|
55 const TIRDataTransferPckg& TransferredData() const; |
|
56 void BindL( RHTTPSession , TIRTransferCategory ); |
|
57 void RawDataTransferredL( TInt , TInt , TIRTransferCategory ); |
|
58 |
|
59 // from base class MHTTPFilter |
|
60 |
|
61 void MHFRunL( RHTTPTransaction aTransaction, const THTTPEvent& aEvent ); |
|
62 |
|
63 private: |
|
64 |
|
65 /** |
|
66 * Constructor. |
|
67 */ |
|
68 CIRDataTransferTracker(); |
|
69 |
|
70 /** |
|
71 * Second-phase constructor. |
|
72 */ |
|
73 void ConstructL() const; |
|
74 |
|
75 /** |
|
76 * Calculates the header field sizes in bytes from the specified headers. |
|
77 * |
|
78 * @param aTransaction HTTP transaction for the headers. |
|
79 * @param aHeaders Headers to calculate the size from. |
|
80 |
|
81 * @return Size of the headers in bytes. |
|
82 */ |
|
83 TInt HeaderSize( const RHTTPTransaction aTransaction, RHTTPHeaders aHeaders ); |
|
84 |
|
85 /** |
|
86 * Parses the header sizes (both request and response) of the supplied HTTP transaction, |
|
87 * logging it under the specified category. |
|
88 * |
|
89 * @param aTransaction Transaction to parse the headers from. |
|
90 * @param aCategory Transfer category to record the data under. |
|
91 */ |
|
92 void ParseHeaderSizeL( const RHTTPTransaction aTransaction, TIRTransferCategory aCategory ); |
|
93 |
|
94 /** |
|
95 * Parses the body size of the supplied HTTP transaction, logging it under the specified category. |
|
96 * |
|
97 * @param aTransaction Transaction to parse the headers from. |
|
98 * @param aCategory Transfer category to record the data under. |
|
99 */ |
|
100 void ParseBodySizeL( const RHTTPTransaction aTransaction, TIRTransferCategory aCategory ); |
|
101 |
|
102 /** |
|
103 * Processes raw data sent and/or received via the connection. |
|
104 * |
|
105 * @param aBytesSent The number of bytes that were sent. |
|
106 * @param aBytesReceived The number of bytes that were received. |
|
107 * @param aCategory Transfer category to record the data under. |
|
108 */ |
|
109 void ProcessDataL( TInt aBytesSent, TInt aBytesReceived, TIRTransferCategory aCategory ); |
|
110 |
|
111 /** |
|
112 * Dispatches the notification of the data transfer conditionally. |
|
113 * |
|
114 * If the threshold between the last notification's data transfer amount and the current |
|
115 * data transfer amount is not exceeded, then no notification is dispatched. |
|
116 */ |
|
117 void DispatchNotificationL(); |
|
118 |
|
119 private: |
|
120 |
|
121 /** |
|
122 * Data transfer observer. |
|
123 * Not owned. |
|
124 */ |
|
125 MIRDataTransferObserver* iObserver; |
|
126 |
|
127 /** |
|
128 * Persistent storage for the data amounts transferred. |
|
129 */ |
|
130 MIRDataTransferTracker::TIRDataTransferPckg iPckg; |
|
131 |
|
132 /** |
|
133 * The amount of bytes transferred since last notification was dispatched. |
|
134 */ |
|
135 TInt iBytesSinceLastNotification; |
|
136 |
|
137 /** |
|
138 * The flag to determine Byte Counter crossed first threshold |
|
139 */ |
|
140 TBool bThresholdCrossed; |
|
141 }; |
|
142 |
|
143 #endif // C_IRDATATRANSFERTRACKER_H |