| 1 | package de.ugoe.cs.eventbench.windows;
|
|---|
| 2 |
|
|---|
| 3 | import java.util.LinkedList;
|
|---|
| 4 | import java.util.List;
|
|---|
| 5 |
|
|---|
| 6 | import de.ugoe.cs.eventbench.data.Event;
|
|---|
| 7 | import de.ugoe.cs.eventbench.windows.data.WindowsEvent;
|
|---|
| 8 | import de.ugoe.cs.eventbench.windows.data.WindowsMessage;
|
|---|
| 9 | import de.ugoe.cs.util.console.Console;
|
|---|
| 10 |
|
|---|
| 11 | /**
|
|---|
| 12 | * <p>
|
|---|
| 13 | * Responsible to split sequences into subsequences, such that each subsequences
|
|---|
| 14 | * contains exactly one event.
|
|---|
| 15 | * </p>
|
|---|
| 16 | *
|
|---|
| 17 | * @author Steffen Herbold
|
|---|
| 18 | * @version 1.0
|
|---|
| 19 | */
|
|---|
| 20 | public class SequenceSplitter {
|
|---|
| 21 |
|
|---|
| 22 | /**
|
|---|
| 23 | * <p>
|
|---|
| 24 | * Contains the current subsequence.
|
|---|
| 25 | * </p>
|
|---|
| 26 | */
|
|---|
| 27 | private List<WindowsMessage> currentSequence;
|
|---|
| 28 |
|
|---|
| 29 | /**
|
|---|
| 30 | * <p>
|
|---|
| 31 | * Number of messages in the current sequences, that signal that a key or
|
|---|
| 32 | * mouse button has been pressed down to which not yet a message has been
|
|---|
| 33 | * found, that signals that the button has been released.
|
|---|
| 34 | * </p>
|
|---|
| 35 | */
|
|---|
| 36 | private int openDowns;
|
|---|
| 37 |
|
|---|
| 38 | /**
|
|---|
| 39 | * <p>
|
|---|
| 40 | * Internal flag that signals if {@link #currentSequence} needs to be
|
|---|
| 41 | * initialized.
|
|---|
| 42 | * </p>
|
|---|
| 43 | */
|
|---|
| 44 | private boolean initMessages;
|
|---|
| 45 |
|
|---|
| 46 | /**
|
|---|
| 47 | * <p>
|
|---|
| 48 | * The {@link EventGenerator} used to convert the subsequences into
|
|---|
| 49 | * {@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<WindowsEvent> actionSequence;
|
|---|
| 60 |
|
|---|
| 61 | /**
|
|---|
| 62 | * <p>
|
|---|
| 63 | * Type of the previous message.
|
|---|
| 64 | * </p>
|
|---|
| 65 | */
|
|---|
| 66 | private int prevMsg = 0;
|
|---|
| 67 |
|
|---|
| 68 | /**
|
|---|
| 69 | * <p>
|
|---|
| 70 | * Constructor. Creates a new SequenceSplitter.
|
|---|
| 71 | * </p>
|
|---|
| 72 | */
|
|---|
| 73 | public SequenceSplitter() {
|
|---|
| 74 | currentSequence = new LinkedList<WindowsMessage>();
|
|---|
| 75 | openDowns = 0;
|
|---|
| 76 | initMessages = true;
|
|---|
| 77 | tokenGenerator = new EventGenerator();
|
|---|
| 78 | actionSequence = new LinkedList<WindowsEvent>();
|
|---|
| 79 | prevMsg = 0;
|
|---|
| 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 | WindowsEvent currentAction = tokenGenerator
|
|---|
| 94 | .generateEvent(currentSequence);
|
|---|
| 95 | if (currentAction != null) {
|
|---|
| 96 | actionSequence.add(currentAction);
|
|---|
| 97 | }
|
|---|
| 98 | if (isKeyMessage(msg.getType()) && openDowns > 0) {
|
|---|
| 99 | Console.traceln("Key message found with open down mouse messages - will probabably result in a faulty sequence.");
|
|---|
| 100 | }
|
|---|
| 101 | } else {
|
|---|
| 102 | initMessages = false;
|
|---|
| 103 | }
|
|---|
| 104 | currentSequence = new LinkedList<WindowsMessage>();
|
|---|
| 105 | }
|
|---|
| 106 | if (isUpMessage(msg.getType())) {
|
|---|
| 107 | if (openDowns > 0) {
|
|---|
| 108 | openDowns--;
|
|---|
| 109 | }
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | // this fix checks if there are two consecutive mouse-down messages.
|
|---|
| 113 | // This sometimes occurs due to incorrect filtering in the monitoring
|
|---|
| 114 | // dll.
|
|---|
| 115 | if (!(prevMsg == MessageDefs.WM_LBUTTONDOWN && prevMsg == msg.getType())) {
|
|---|
| 116 | currentSequence.add(msg);
|
|---|
| 117 | } else {
|
|---|
| 118 | openDowns--;
|
|---|
| 119 | }
|
|---|
| 120 | prevMsg = msg.getType();
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | /**
|
|---|
| 124 | * <p>
|
|---|
| 125 | * Returns the event sequence generated from the message that have been
|
|---|
| 126 | * added.
|
|---|
| 127 | * </p>
|
|---|
| 128 | *
|
|---|
| 129 | * @return generated event sequence
|
|---|
| 130 | */
|
|---|
| 131 | public List<WindowsEvent> getSequence() {
|
|---|
| 132 | return actionSequence;
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | /**
|
|---|
| 136 | * <p>
|
|---|
| 137 | * Called when a session in the log file is finished, i.e., a closing
|
|---|
| 138 | * session-node is found.
|
|---|
| 139 | * </p>
|
|---|
| 140 | */
|
|---|
| 141 | public void endSession() {
|
|---|
| 142 | WindowsEvent currentAction = tokenGenerator
|
|---|
| 143 | .generateEvent(currentSequence);
|
|---|
| 144 | if (currentAction != null) {
|
|---|
| 145 | actionSequence.add(currentAction);
|
|---|
| 146 | }
|
|---|
| 147 | }
|
|---|
| 148 |
|
|---|
| 149 | /**
|
|---|
| 150 | * <p>
|
|---|
| 151 | * Checks if the message starts a new subsequence and returns the result.
|
|---|
| 152 | * </p>
|
|---|
| 153 | *
|
|---|
| 154 | * @param msg
|
|---|
| 155 | * message that is checked
|
|---|
| 156 | * @return true, if a new subsequence begins
|
|---|
| 157 | */
|
|---|
| 158 | private boolean startOfSequence(WindowsMessage msg) {
|
|---|
| 159 | boolean isStart = false;
|
|---|
| 160 | int msgType = msg.getType();
|
|---|
| 161 | if (isKeyMessage(msgType)) {
|
|---|
| 162 | isStart = true;
|
|---|
| 163 | }
|
|---|
| 164 | if (isDownMessage(msgType)) {
|
|---|
| 165 | openDowns++;
|
|---|
| 166 | if (openDowns == 1) {
|
|---|
| 167 | isStart = true;
|
|---|
| 168 | }
|
|---|
| 169 | }
|
|---|
| 170 | if (isDblclkMessage(msgType)) {
|
|---|
| 171 | openDowns++;
|
|---|
| 172 | }
|
|---|
| 173 | return isStart;
|
|---|
| 174 | }
|
|---|
| 175 |
|
|---|
| 176 | /**
|
|---|
| 177 | * <p>
|
|---|
| 178 | * Checks if the type of a message is generated is a keyboard interaction.
|
|---|
| 179 | * </p>
|
|---|
| 180 | *
|
|---|
| 181 | * @param msgType
|
|---|
| 182 | * type of the message
|
|---|
| 183 | * @return true if it is a keyboard interaction; false otherwise
|
|---|
| 184 | */
|
|---|
| 185 | private boolean isKeyMessage(int msgType) {
|
|---|
| 186 | boolean isKeyMsg = false;
|
|---|
| 187 | switch (msgType) {
|
|---|
| 188 | case MessageDefs.WM_KEYDOWN:
|
|---|
| 189 | case MessageDefs.WM_KEYUP:
|
|---|
| 190 | case MessageDefs.WM_SYSKEYDOWN:
|
|---|
| 191 | case MessageDefs.WM_SYSKEYUP:
|
|---|
| 192 | isKeyMsg = true;
|
|---|
| 193 | break;
|
|---|
| 194 | default:
|
|---|
| 195 | break;
|
|---|
| 196 | }
|
|---|
| 197 | return isKeyMsg;
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | /**
|
|---|
| 201 | * <p>
|
|---|
| 202 | * Checks if the type of a message indicates that the mouse has been pressed
|
|---|
| 203 | * down.
|
|---|
| 204 | * </p>
|
|---|
| 205 | *
|
|---|
| 206 | * @param msgType
|
|---|
| 207 | * type of the message
|
|---|
| 208 | * @return true if it is mouse-down message; false otherwise
|
|---|
| 209 | */
|
|---|
| 210 | private boolean isDownMessage(int msgType) {
|
|---|
| 211 | boolean isDownMsg = false;
|
|---|
| 212 | switch (msgType) {
|
|---|
| 213 | case MessageDefs.WM_LBUTTONDOWN:
|
|---|
| 214 | case MessageDefs.WM_RBUTTONDOWN:
|
|---|
| 215 | case MessageDefs.WM_MBUTTONDOWN:
|
|---|
| 216 | case MessageDefs.WM_XBUTTONDOWN:
|
|---|
| 217 | case MessageDefs.WM_NCLBUTTONDOWN:
|
|---|
| 218 | case MessageDefs.WM_NCRBUTTONDOWN:
|
|---|
| 219 | case MessageDefs.WM_NCMBUTTONDOWN:
|
|---|
| 220 | case MessageDefs.WM_NCXBUTTONDOWN:
|
|---|
| 221 | isDownMsg = true;
|
|---|
| 222 | break;
|
|---|
| 223 | default:
|
|---|
| 224 | break;
|
|---|
| 225 | }
|
|---|
| 226 | return isDownMsg;
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | /**
|
|---|
| 230 | * <p>
|
|---|
| 231 | * Checks if the type of a message indicates that a double click has been
|
|---|
| 232 | * performed.
|
|---|
| 233 | * </p>
|
|---|
| 234 | *
|
|---|
| 235 | * @param msgType
|
|---|
| 236 | * type of the message
|
|---|
| 237 | * @return true if it is a double click message; false otherwise
|
|---|
| 238 | */
|
|---|
| 239 | private boolean isDblclkMessage(int msgType) {
|
|---|
| 240 | boolean isDblclkMsg = false;
|
|---|
| 241 | switch (msgType) {
|
|---|
| 242 | case MessageDefs.WM_LBUTTONDBLCLK:
|
|---|
| 243 | case MessageDefs.WM_RBUTTONDBLCLK:
|
|---|
| 244 | case MessageDefs.WM_MBUTTONDBLCLK:
|
|---|
| 245 | case MessageDefs.WM_XBUTTONDBLCLK:
|
|---|
| 246 | case MessageDefs.WM_NCLBUTTONDBLCLK:
|
|---|
| 247 | case MessageDefs.WM_NCRBUTTONDBLCLK:
|
|---|
| 248 | case MessageDefs.WM_NCMBUTTONDBLCLK:
|
|---|
| 249 | case MessageDefs.WM_NCXBUTTONDBLCLK:
|
|---|
| 250 | isDblclkMsg = true;
|
|---|
| 251 | break;
|
|---|
| 252 | default:
|
|---|
| 253 | break;
|
|---|
| 254 | }
|
|---|
| 255 | return isDblclkMsg;
|
|---|
| 256 | }
|
|---|
| 257 |
|
|---|
| 258 | /**
|
|---|
| 259 | * <p>
|
|---|
| 260 | * Checks if the type of a message indicates that the mouse has been
|
|---|
| 261 | * released.
|
|---|
| 262 | * </p>
|
|---|
| 263 | *
|
|---|
| 264 | * @param msgType
|
|---|
| 265 | * type of the message
|
|---|
| 266 | * @return true if it is mouse-up message; false otherwise
|
|---|
| 267 | */
|
|---|
| 268 | private boolean isUpMessage(int msgType) {
|
|---|
| 269 | boolean isUpMsg = false;
|
|---|
| 270 | switch (msgType) {
|
|---|
| 271 | case MessageDefs.WM_LBUTTONUP:
|
|---|
| 272 | case MessageDefs.WM_RBUTTONUP:
|
|---|
| 273 | case MessageDefs.WM_MBUTTONUP:
|
|---|
| 274 | case MessageDefs.WM_XBUTTONUP:
|
|---|
| 275 | case MessageDefs.WM_NCLBUTTONUP:
|
|---|
| 276 | case MessageDefs.WM_NCRBUTTONUP:
|
|---|
| 277 | case MessageDefs.WM_NCMBUTTONUP:
|
|---|
| 278 | case MessageDefs.WM_NCXBUTTONUP:
|
|---|
| 279 | isUpMsg = true;
|
|---|
| 280 | break;
|
|---|
| 281 | default:
|
|---|
| 282 | break;
|
|---|
| 283 | }
|
|---|
| 284 | return isUpMsg;
|
|---|
| 285 | }
|
|---|
| 286 |
|
|---|
| 287 | }
|
|---|