1 | package de.ugoe.cs.quest.plugin.mfc;
|
---|
2 |
|
---|
3 | import java.util.LinkedList;
|
---|
4 | import java.util.List;
|
---|
5 | import java.util.logging.Level;
|
---|
6 |
|
---|
7 | import de.ugoe.cs.quest.eventcore.Event;
|
---|
8 | import de.ugoe.cs.quest.plugin.mfc.eventcore.WindowsMessage;
|
---|
9 | import de.ugoe.cs.quest.plugin.mfc.eventcore.WindowsMessageType;
|
---|
10 | import de.ugoe.cs.quest.plugin.mfc.guimodel.WindowTree;
|
---|
11 | import de.ugoe.cs.util.console.Console;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * <p>
|
---|
15 | * Responsible to split sequences into subsequences, such that each subsequences contains exactly
|
---|
16 | * one event.
|
---|
17 | * </p>
|
---|
18 | *
|
---|
19 | * @author Steffen Herbold
|
---|
20 | * @version 1.0
|
---|
21 | */
|
---|
22 | public class SequenceSplitter {
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * <p>
|
---|
26 | * Contains the current subsequence.
|
---|
27 | * </p>
|
---|
28 | */
|
---|
29 | private List<WindowsMessage> currentSequence;
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * <p>
|
---|
33 | * Number of messages in the current sequences, that signal that a key or mouse button has been
|
---|
34 | * pressed down to which not yet a message has been found, that signals that the button has been
|
---|
35 | * released.
|
---|
36 | * </p>
|
---|
37 | */
|
---|
38 | private int openDowns;
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * <p>
|
---|
42 | * Internal flag that signals if {@link #currentSequence} needs to be initialized.
|
---|
43 | * </p>
|
---|
44 | */
|
---|
45 | private boolean initMessages;
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * <p>
|
---|
49 | * The {@link EventGenerator} used to convert the subsequences into {@link Event}s
|
---|
50 | * </p>
|
---|
51 | */
|
---|
52 | private EventGenerator tokenGenerator;
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * <p>
|
---|
56 | * The event sequence generated.
|
---|
57 | * </p>
|
---|
58 | */
|
---|
59 | private List<Event> actionSequence;
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * <p>
|
---|
63 | * Type of the previous message.
|
---|
64 | * </p>
|
---|
65 | */
|
---|
66 | private WindowsMessageType prevMsg;
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * <p>
|
---|
70 | * Constructor. Creates a new SequenceSplitter.
|
---|
71 | * </p>
|
---|
72 | */
|
---|
73 | public SequenceSplitter(WindowTree windowTree) {
|
---|
74 | currentSequence = new LinkedList<WindowsMessage>();
|
---|
75 | openDowns = 0;
|
---|
76 | initMessages = true;
|
---|
77 | tokenGenerator = new EventGenerator(windowTree);
|
---|
78 | actionSequence = new LinkedList<Event>();
|
---|
79 | prevMsg = null;
|
---|
80 | }
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * <p>
|
---|
84 | * Called by the {@link MFCLogParser} every time a message is parsed.
|
---|
85 | * </p>
|
---|
86 | *
|
---|
87 | * @param msg
|
---|
88 | * message to be added
|
---|
89 | */
|
---|
90 | public void addMessage(WindowsMessage msg) {
|
---|
91 | if (startOfSequence(msg)) {
|
---|
92 | if (!initMessages) {
|
---|
93 | Event currentAction = tokenGenerator.generateEvent(currentSequence);
|
---|
94 | if (currentAction != null) {
|
---|
95 | actionSequence.add(currentAction);
|
---|
96 | }
|
---|
97 | if (msg.getType().isKeyMessage() && openDowns > 0) {
|
---|
98 | Console.traceln(Level.SEVERE, "Key message found with open down mouse " +
|
---|
99 | "messages - will probabably result in a faulty sequence.");
|
---|
100 | }
|
---|
101 | }
|
---|
102 | else {
|
---|
103 | initMessages = false;
|
---|
104 | }
|
---|
105 | currentSequence = new LinkedList<WindowsMessage>();
|
---|
106 | }
|
---|
107 | if (msg.getType().isUpMessage()) {
|
---|
108 | if (openDowns > 0) {
|
---|
109 | openDowns--;
|
---|
110 | }
|
---|
111 | }
|
---|
112 |
|
---|
113 | // this fix checks if there are two consecutive mouse-down messages.
|
---|
114 | // This sometimes occurs due to incorrect filtering in the monitoring
|
---|
115 | // dll.
|
---|
116 | if (!(prevMsg == WindowsMessageType.WM_LBUTTONDOWN && prevMsg == msg.getType())) {
|
---|
117 | currentSequence.add(msg);
|
---|
118 | }
|
---|
119 | else {
|
---|
120 | openDowns--;
|
---|
121 | }
|
---|
122 | prevMsg = msg.getType();
|
---|
123 | }
|
---|
124 |
|
---|
125 | /**
|
---|
126 | * <p>
|
---|
127 | * Returns the event sequence generated from the message that have been added.
|
---|
128 | * </p>
|
---|
129 | *
|
---|
130 | * @return generated event sequence
|
---|
131 | */
|
---|
132 | public List<Event> getSequence() {
|
---|
133 | return actionSequence;
|
---|
134 | }
|
---|
135 |
|
---|
136 | /**
|
---|
137 | * <p>
|
---|
138 | * Called when a session in the log file is finished, i.e., a closing session-node is found.
|
---|
139 | * </p>
|
---|
140 | */
|
---|
141 | public void endSession() {
|
---|
142 | Event currentAction = tokenGenerator.generateEvent(currentSequence);
|
---|
143 | if (currentAction != null) {
|
---|
144 | actionSequence.add(currentAction);
|
---|
145 | }
|
---|
146 | }
|
---|
147 |
|
---|
148 | /**
|
---|
149 | * <p>
|
---|
150 | * Checks if the message starts a new subsequence and returns the result.
|
---|
151 | * </p>
|
---|
152 | *
|
---|
153 | * @param msg
|
---|
154 | * message that is checked
|
---|
155 | * @return true, if a new subsequence begins
|
---|
156 | */
|
---|
157 | private boolean startOfSequence(WindowsMessage msg) {
|
---|
158 | boolean isStart = false;
|
---|
159 | WindowsMessageType msgType = msg.getType();
|
---|
160 | if (msgType.isKeyMessage()) {
|
---|
161 | isStart = true;
|
---|
162 | }
|
---|
163 | if (msgType.isDownMessage()) {
|
---|
164 | openDowns++;
|
---|
165 | if (openDowns == 1) {
|
---|
166 | isStart = true;
|
---|
167 | }
|
---|
168 | }
|
---|
169 | if (msgType.isDblclkMessage()) {
|
---|
170 | openDowns++;
|
---|
171 | }
|
---|
172 | return isStart;
|
---|
173 | }
|
---|
174 |
|
---|
175 | }
|
---|