| 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 | * Constructor. Creates a new SequenceSplitter.
|
|---|
| 64 | * </p>
|
|---|
| 65 | */
|
|---|
| 66 | public SequenceSplitter() {
|
|---|
| 67 | currentSequence = new LinkedList<WindowsMessage>();
|
|---|
| 68 | openDowns = 0;
|
|---|
| 69 | initMessages = true;
|
|---|
| 70 | tokenGenerator = new EventGenerator();
|
|---|
| 71 | actionSequence = new LinkedList<WindowsEvent>();
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | /**
|
|---|
| 75 | * <p>
|
|---|
| 76 | * Called by the {@link MFCLogParser} every time a message is parsed.
|
|---|
| 77 | * </p>
|
|---|
| 78 | *
|
|---|
| 79 | * @param msg
|
|---|
| 80 | * message to be added
|
|---|
| 81 | */
|
|---|
| 82 | public void addMessage(WindowsMessage msg) {
|
|---|
| 83 | if (startOfSequence(msg)) {
|
|---|
| 84 | if (!initMessages) {
|
|---|
| 85 | WindowsEvent currentAction = tokenGenerator
|
|---|
| 86 | .generateEvent(currentSequence);
|
|---|
| 87 | if (currentAction != null) {
|
|---|
| 88 | actionSequence.add(currentAction);
|
|---|
| 89 | }
|
|---|
| 90 | if (isKeyMessage(msg.getType()) && openDowns > 0) {
|
|---|
| 91 | Console.traceln("Key message found with open down mouse messages - will probabably result in a faulty sequence.");
|
|---|
| 92 | }
|
|---|
| 93 | } else {
|
|---|
| 94 | initMessages = false;
|
|---|
| 95 | }
|
|---|
| 96 | currentSequence = new LinkedList<WindowsMessage>();
|
|---|
| 97 | }
|
|---|
| 98 | if (isUpMessage(msg.getType())) {
|
|---|
| 99 | if (openDowns > 0) {
|
|---|
| 100 | openDowns--;
|
|---|
| 101 | }
|
|---|
| 102 | }
|
|---|
| 103 | currentSequence.add(msg);
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | /**
|
|---|
| 107 | * <p>
|
|---|
| 108 | * Returns the event sequence generated from the message that have been
|
|---|
| 109 | * added.
|
|---|
| 110 | * </p>
|
|---|
| 111 | *
|
|---|
| 112 | * @return generated event sequence
|
|---|
| 113 | */
|
|---|
| 114 | public List<WindowsEvent> getSequence() {
|
|---|
| 115 | return actionSequence;
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | /**
|
|---|
| 119 | * <p>
|
|---|
| 120 | * Called when a session in the log file is finished, i.e., a closing
|
|---|
| 121 | * session-node is found.
|
|---|
| 122 | * </p>
|
|---|
| 123 | */
|
|---|
| 124 | public void endSession() {
|
|---|
| 125 | WindowsEvent currentAction = tokenGenerator
|
|---|
| 126 | .generateEvent(currentSequence);
|
|---|
| 127 | if (currentAction != null) {
|
|---|
| 128 | actionSequence.add(currentAction);
|
|---|
| 129 | }
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | /**
|
|---|
| 133 | * <p>
|
|---|
| 134 | * Checks if the message starts a new subsequence and returns the result.
|
|---|
| 135 | * </p>
|
|---|
| 136 | *
|
|---|
| 137 | * @param msg
|
|---|
| 138 | * message that is checked
|
|---|
| 139 | * @return true, if a new subsequence begins
|
|---|
| 140 | */
|
|---|
| 141 | private boolean startOfSequence(WindowsMessage msg) {
|
|---|
| 142 | boolean isStart = false;
|
|---|
| 143 | int msgType = msg.getType();
|
|---|
| 144 | if (isKeyMessage(msgType)) {
|
|---|
| 145 | isStart = true;
|
|---|
| 146 | }
|
|---|
| 147 | if (isDownMessage(msgType)) {
|
|---|
| 148 | openDowns++;
|
|---|
| 149 | if (openDowns == 1) {
|
|---|
| 150 | isStart = true;
|
|---|
| 151 | }
|
|---|
| 152 | }
|
|---|
| 153 | if (isDblclkMessage(msgType)) {
|
|---|
| 154 | openDowns++;
|
|---|
| 155 | }
|
|---|
| 156 | return isStart;
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | /**
|
|---|
| 160 | * <p>
|
|---|
| 161 | * Checks if the type of a message is generated is a keyboard interaction.
|
|---|
| 162 | * </p>
|
|---|
| 163 | *
|
|---|
| 164 | * @param msgType
|
|---|
| 165 | * type of the message
|
|---|
| 166 | * @return true if it is a keyboard interaction; false otherwise
|
|---|
| 167 | */
|
|---|
| 168 | private boolean isKeyMessage(int msgType) {
|
|---|
| 169 | boolean isKeyMsg = false;
|
|---|
| 170 | switch (msgType) {
|
|---|
| 171 | case MessageDefs.WM_KEYDOWN:
|
|---|
| 172 | case MessageDefs.WM_KEYUP:
|
|---|
| 173 | case MessageDefs.WM_SYSKEYDOWN:
|
|---|
| 174 | case MessageDefs.WM_SYSKEYUP:
|
|---|
| 175 | isKeyMsg = true;
|
|---|
| 176 | break;
|
|---|
| 177 | default:
|
|---|
| 178 | break;
|
|---|
| 179 | }
|
|---|
| 180 | return isKeyMsg;
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 | /**
|
|---|
| 184 | * <p>
|
|---|
| 185 | * Checks if the type of a message indicates that the mouse has been pressed
|
|---|
| 186 | * down.
|
|---|
| 187 | * </p>
|
|---|
| 188 | *
|
|---|
| 189 | * @param msgType
|
|---|
| 190 | * type of the message
|
|---|
| 191 | * @return true if it is mouse-down message; false otherwise
|
|---|
| 192 | */
|
|---|
| 193 | private boolean isDownMessage(int msgType) {
|
|---|
| 194 | boolean isDownMsg = false;
|
|---|
| 195 | switch (msgType) {
|
|---|
| 196 | case MessageDefs.WM_LBUTTONDOWN:
|
|---|
| 197 | case MessageDefs.WM_RBUTTONDOWN:
|
|---|
| 198 | case MessageDefs.WM_MBUTTONDOWN:
|
|---|
| 199 | case MessageDefs.WM_XBUTTONDOWN:
|
|---|
| 200 | case MessageDefs.WM_NCLBUTTONDOWN:
|
|---|
| 201 | case MessageDefs.WM_NCRBUTTONDOWN:
|
|---|
| 202 | case MessageDefs.WM_NCMBUTTONDOWN:
|
|---|
| 203 | case MessageDefs.WM_NCXBUTTONDOWN:
|
|---|
| 204 | isDownMsg = true;
|
|---|
| 205 | break;
|
|---|
| 206 | default:
|
|---|
| 207 | break;
|
|---|
| 208 | }
|
|---|
| 209 | return isDownMsg;
|
|---|
| 210 | }
|
|---|
| 211 |
|
|---|
| 212 | /**
|
|---|
| 213 | * <p>
|
|---|
| 214 | * Checks if the type of a message indicates that a double click has been
|
|---|
| 215 | * performed.
|
|---|
| 216 | * </p>
|
|---|
| 217 | *
|
|---|
| 218 | * @param msgType
|
|---|
| 219 | * type of the message
|
|---|
| 220 | * @return true if it is a double click message; false otherwise
|
|---|
| 221 | */
|
|---|
| 222 | private boolean isDblclkMessage(int msgType) {
|
|---|
| 223 | boolean isDblclkMsg = false;
|
|---|
| 224 | switch (msgType) {
|
|---|
| 225 | case MessageDefs.WM_LBUTTONDBLCLK:
|
|---|
| 226 | case MessageDefs.WM_RBUTTONDBLCLK:
|
|---|
| 227 | case MessageDefs.WM_MBUTTONDBLCLK:
|
|---|
| 228 | case MessageDefs.WM_XBUTTONDBLCLK:
|
|---|
| 229 | case MessageDefs.WM_NCLBUTTONDBLCLK:
|
|---|
| 230 | case MessageDefs.WM_NCRBUTTONDBLCLK:
|
|---|
| 231 | case MessageDefs.WM_NCMBUTTONDBLCLK:
|
|---|
| 232 | case MessageDefs.WM_NCXBUTTONDBLCLK:
|
|---|
| 233 | isDblclkMsg = true;
|
|---|
| 234 | break;
|
|---|
| 235 | default:
|
|---|
| 236 | break;
|
|---|
| 237 | }
|
|---|
| 238 | return isDblclkMsg;
|
|---|
| 239 | }
|
|---|
| 240 |
|
|---|
| 241 | /**
|
|---|
| 242 | * <p>
|
|---|
| 243 | * Checks if the type of a message indicates that the mouse has been
|
|---|
| 244 | * released.
|
|---|
| 245 | * </p>
|
|---|
| 246 | *
|
|---|
| 247 | * @param msgType
|
|---|
| 248 | * type of the message
|
|---|
| 249 | * @return true if it is mouse-up message; false otherwise
|
|---|
| 250 | */
|
|---|
| 251 | private boolean isUpMessage(int msgType) {
|
|---|
| 252 | boolean isUpMsg = false;
|
|---|
| 253 | switch (msgType) {
|
|---|
| 254 | case MessageDefs.WM_LBUTTONUP:
|
|---|
| 255 | case MessageDefs.WM_RBUTTONUP:
|
|---|
| 256 | case MessageDefs.WM_MBUTTONUP:
|
|---|
| 257 | case MessageDefs.WM_XBUTTONUP:
|
|---|
| 258 | case MessageDefs.WM_NCLBUTTONUP:
|
|---|
| 259 | case MessageDefs.WM_NCRBUTTONUP:
|
|---|
| 260 | case MessageDefs.WM_NCMBUTTONUP:
|
|---|
| 261 | case MessageDefs.WM_NCXBUTTONUP:
|
|---|
| 262 | isUpMsg = true;
|
|---|
| 263 | break;
|
|---|
| 264 | default:
|
|---|
| 265 | break;
|
|---|
| 266 | }
|
|---|
| 267 | return isUpMsg;
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 | }
|
|---|