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