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