1 | /** |
---|
2 | * @file TrafficCaptureMessageFactory.cpp |
---|
3 | * @author Tomas Urban |
---|
4 | * @version 0.2 |
---|
5 | * @date 23/07/2009 |
---|
6 | */ |
---|
7 | #include "TrafficCaptureMessageFactory.h" |
---|
8 | #include "CommonTrafficCaptureMessages.h" |
---|
9 | #include "CapturedData.h" |
---|
10 | #include "Logger/Logger.h" |
---|
11 | |
---|
12 | TrafficCaptureMessageFactory::TrafficCaptureMessageFactory(void) |
---|
13 | { |
---|
14 | } |
---|
15 | |
---|
16 | TrafficCaptureMessageFactory::~TrafficCaptureMessageFactory(void) |
---|
17 | { |
---|
18 | } |
---|
19 | |
---|
20 | TrafficCaptureMessage * TrafficCaptureMessageFactory::CreateMessage(unsigned short nId, const char * pPayload, |
---|
21 | unsigned int nPayloadLength) |
---|
22 | { |
---|
23 | TrafficCaptureMessage * pInstance = 0; |
---|
24 | std::string s; |
---|
25 | switch(nId) |
---|
26 | { |
---|
27 | case CAPTURED_PACKET_IND: |
---|
28 | s = "CapturedData"; |
---|
29 | pInstance = new CapturedData(); |
---|
30 | break; |
---|
31 | case SET_FILTER_REQ: |
---|
32 | s = "SetFilterRequest"; |
---|
33 | pInstance = new SetFilterRequest(); |
---|
34 | break; |
---|
35 | case START_CAPTURE_REQ: |
---|
36 | s = "StartCaptureRequest"; |
---|
37 | pInstance = new StartCaptureRequest(); |
---|
38 | break; |
---|
39 | case START_CAPTURE_REP: |
---|
40 | s = "StartCaptureReply"; |
---|
41 | pInstance = new StartCaptureReply(); |
---|
42 | break; |
---|
43 | case STOP_CAPTURE_REQ: |
---|
44 | s = "StopCaptureRequest"; |
---|
45 | pInstance = new StopCaptureRequest(); |
---|
46 | break; |
---|
47 | case STOP_CAPTURE_REP: |
---|
48 | s = "StopCaptureReply"; |
---|
49 | pInstance = new StopCaptureReply(); |
---|
50 | break; |
---|
51 | case OPEN_DEVICE_REQ: |
---|
52 | s = "OpenDeviceRequest"; |
---|
53 | pInstance = new OpenDeviceRequest(); |
---|
54 | break; |
---|
55 | case OPEN_DEVICE_REP: |
---|
56 | s = "OpenDeviceReply"; |
---|
57 | pInstance = new OpenDeviceReply(); |
---|
58 | break; |
---|
59 | case SET_FILTER_REP: |
---|
60 | s = "SetFilterReply"; |
---|
61 | pInstance = new SetFilterReply(); |
---|
62 | break; |
---|
63 | case MERGE_FILES_REQ: |
---|
64 | s = "MergePcapFilesRequest"; |
---|
65 | pInstance = new MergePcapFilesRequest(); |
---|
66 | break; |
---|
67 | case MERGE_FILES_REP: |
---|
68 | s = "MergePcapFilesReply"; |
---|
69 | pInstance = new MergePcapFilesReply(); |
---|
70 | break; |
---|
71 | } |
---|
72 | if (pInstance) |
---|
73 | { |
---|
74 | std::string sMsg = "Message instance created: "; |
---|
75 | sMsg += s; |
---|
76 | Logger::Instance().LogDebug(sMsg); |
---|
77 | Logger::Instance().LogDebug("Deserializing message..."); |
---|
78 | if (!pInstance->DecodePayload(pPayload, nPayloadLength)) |
---|
79 | { |
---|
80 | Logger::Instance().LogDebug("Message deserialization failed"); |
---|
81 | delete pInstance; |
---|
82 | pInstance = 0; |
---|
83 | } |
---|
84 | else |
---|
85 | Logger::Instance().LogDebug("Deserializing completed successfully"); |
---|
86 | } |
---|
87 | else |
---|
88 | Logger::Instance().LogDebug("Message instantiation failed: unknown message"); |
---|
89 | return pInstance; |
---|
90 | } |
---|
91 | |
---|
92 | void TrafficCaptureMessageFactory::DisposeMessage(TrafficCaptureMessage * pInstance) |
---|
93 | { |
---|
94 | delete pInstance; |
---|
95 | } |
---|