1 | /** |
---|
2 | * @file GenericCapture.h |
---|
3 | * This header file defines the GenericCapture class. |
---|
4 | * @author Tomas Urban |
---|
5 | * @version 0.2 |
---|
6 | * @date 21/07/2009 |
---|
7 | */ |
---|
8 | #ifndef GENERIC_CAPTURE_H |
---|
9 | #define GENERIC_CAPTURE_H |
---|
10 | |
---|
11 | #include "Messages/CapturedData.h" |
---|
12 | #include "CaptureDispatch.h" |
---|
13 | |
---|
14 | |
---|
15 | /** |
---|
16 | * Abstract class describing a capturing device. It defines the common interface and several |
---|
17 | * useful methods. However, the capturing code itself must be implemented in child classes |
---|
18 | * according to the means used for capture (strategy design pattern). |
---|
19 | */ |
---|
20 | class GenericCapture |
---|
21 | { |
---|
22 | private: |
---|
23 | CaptureDispatch * m_pDispatch; |
---|
24 | struct timeval m_offset; |
---|
25 | struct timeval m_startPoint; |
---|
26 | struct timeval m_timestamp; |
---|
27 | void UpdateTimestamp(); |
---|
28 | protected: |
---|
29 | GenericCapture(); |
---|
30 | /** |
---|
31 | * This method is used for processing the captured data, passing it to an associated |
---|
32 | * CaptureDispatch object. |
---|
33 | * @param pData Data to process |
---|
34 | */ |
---|
35 | void ProcessCapturedData(CapturedData * pData); |
---|
36 | /** |
---|
37 | * Sets the capture start point timestamp which is used in time-based filtering |
---|
38 | * @param timestamp Timestamp of the beginning of capture |
---|
39 | */ |
---|
40 | void SetStartPoint(struct timeval timestamp); |
---|
41 | public: |
---|
42 | virtual ~GenericCapture(void); |
---|
43 | /** |
---|
44 | * Sets the object used for delivering captured data to the final recipient. |
---|
45 | */ |
---|
46 | void InitDispatch(CaptureDispatch * pDispatch) { m_pDispatch = pDispatch; } |
---|
47 | /** |
---|
48 | * Initializes capturing object. The parameter contains additional initialization |
---|
49 | * data. The format of the data is device specific. |
---|
50 | * @param sParams Start-up parameters of the device |
---|
51 | * @return Operation success |
---|
52 | */ |
---|
53 | virtual ECaptureInitResult OpenDevice(const std::string sParams) = 0; |
---|
54 | /** |
---|
55 | * Sets the path to an associated capture file. This call is used only by devices |
---|
56 | * capable of saving traffic into a file. In the default case, the method |
---|
57 | * doesn't cause any traffic to be saved. |
---|
58 | * @param sFile Name of the target file or empty string if the traffic should not |
---|
59 | * be saved. |
---|
60 | * @return \c true if the operation succeeds, \c false otherwise. |
---|
61 | */ |
---|
62 | virtual bool SetCaptureFile(const std::string sFile); |
---|
63 | /** |
---|
64 | * Contains device-specific clean-up code. |
---|
65 | */ |
---|
66 | virtual void CloseDevice() = 0; |
---|
67 | /** |
---|
68 | * Sets up the capture filter. If the string is empty, no filtering should be applied. |
---|
69 | * The format of the filtering parameter is device specific. |
---|
70 | * @param sFilter Filtering data |
---|
71 | * @return \c true if the operation was successful, \c false otherwise (e.g. in case |
---|
72 | * of invalid filter format) |
---|
73 | **/ |
---|
74 | virtual bool SetFilter(const std::string sFilter) = 0; |
---|
75 | /** |
---|
76 | * Starts or resumes data capture on the device |
---|
77 | * @return \c true if the operation was successful, \c false otherwise |
---|
78 | */ |
---|
79 | virtual bool StartCapture() = 0; |
---|
80 | /** |
---|
81 | * Stops or suspends data capture on the device |
---|
82 | * @return \c true if the operation was successful, \c false otherwise |
---|
83 | */ |
---|
84 | virtual bool StopCapture() = 0; |
---|
85 | /** |
---|
86 | * Returns the type of the capturing device. |
---|
87 | * @return Capture type |
---|
88 | */ |
---|
89 | virtual ECaptureType GetCaptureType() = 0; |
---|
90 | /** |
---|
91 | * Returns the offset of the time-based capturing filter. If the returned value is equal |
---|
92 | * to zero, no time-based filter is applied. |
---|
93 | * @return Offset used for time-based filtering |
---|
94 | */ |
---|
95 | struct timeval GetStartOffset() const { return m_offset; } |
---|
96 | /** |
---|
97 | * Sets the offset of the time-based capturing filter. If the timestamp value is equal |
---|
98 | * to zero, no time-based filter is applied. Otherwise the capturing device automatically |
---|
99 | * discards captured messages whose timestamp is smaller than the specified offset. The |
---|
100 | * offset is related to the first captured message. |
---|
101 | * @param offset Offset used for time-based filtering |
---|
102 | */ |
---|
103 | void SetStartOffset(struct timeval offset); |
---|
104 | }; |
---|
105 | |
---|
106 | #endif |
---|
107 | |
---|