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