Browse Source

Add raw support in debug plugin.

Closes #207
pull/342/head
Chris Smith 9 years ago
parent
commit
d0d0a2302b

+ 121
- 0
debug/src/com/dmdirc/addons/debug/RawWindow.java View File

@@ -0,0 +1,121 @@
1
+/*
2
+ * Copyright (c) 2006-2015 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.debug;
24
+
25
+import com.dmdirc.FrameContainer;
26
+import com.dmdirc.commandparser.CommandType;
27
+import com.dmdirc.commandparser.parsers.ServerCommandParser;
28
+import com.dmdirc.events.ServerConnectingEvent;
29
+import com.dmdirc.interfaces.CommandController;
30
+import com.dmdirc.interfaces.Connection;
31
+import com.dmdirc.parser.common.CallbackManager;
32
+import com.dmdirc.parser.interfaces.Parser;
33
+import com.dmdirc.parser.interfaces.callbacks.DataInListener;
34
+import com.dmdirc.parser.interfaces.callbacks.DataOutListener;
35
+import com.dmdirc.ui.core.components.WindowComponent;
36
+import com.dmdirc.ui.input.TabCompleterFactory;
37
+import com.dmdirc.ui.messages.BackBufferFactory;
38
+import com.dmdirc.ui.messages.sink.MessageSinkManager;
39
+
40
+import java.util.Arrays;
41
+import java.util.Date;
42
+import java.util.Optional;
43
+
44
+import net.engio.mbassy.listener.Handler;
45
+
46
+/**
47
+ * Shows the raw lines to and from a connection.
48
+ */
49
+public class RawWindow extends FrameContainer {
50
+
51
+    private final Connection connection;
52
+
53
+    public RawWindow(
54
+            final Connection connection,
55
+            final CommandController commandController,
56
+            final MessageSinkManager messageSinkManager,
57
+            final TabCompleterFactory tabCompleterFactory,
58
+            final BackBufferFactory backBufferFactory) {
59
+        super(connection.getWindowModel(), "raw", "Raw", "(Raw log)",
60
+                connection.getWindowModel().getConfigManager(),
61
+                backBufferFactory,
62
+                new ServerCommandParser(
63
+                        connection.getWindowModel().getConfigManager(),
64
+                        commandController,
65
+                        connection.getWindowModel().getEventBus()),
66
+                tabCompleterFactory.getTabCompleter(connection.getWindowModel().getTabCompleter(),
67
+                        connection.getWindowModel().getConfigManager(),
68
+                        CommandType.TYPE_QUERY, CommandType.TYPE_CHAT),
69
+                messageSinkManager,
70
+                connection.getWindowModel().getEventBus(),
71
+                Arrays.asList(WindowComponent.TEXTAREA.getIdentifier(),
72
+                        WindowComponent.INPUTFIELD.getIdentifier()));
73
+        this.connection = connection;
74
+        initBackBuffer();
75
+
76
+        connection.getWindowModel().getEventBus().subscribe(this);
77
+        connection.getParser().map(Parser::getCallbackManager).ifPresent(this::addCallbacks);
78
+    }
79
+
80
+    @Override
81
+    public Optional<Connection> getConnection() {
82
+        return Optional.of(connection);
83
+    }
84
+
85
+    @Override
86
+    public void close() {
87
+        connection.getParser().map(Parser::getCallbackManager).ifPresent(this::removeCallbacks);
88
+        connection.getWindowModel().getEventBus().unsubscribe(this);
89
+        super.close();
90
+    }
91
+
92
+    @Override
93
+    public int getMaxLineLength() {
94
+        return -1;
95
+    }
96
+
97
+    @Handler
98
+    public void handleServerConnecting(final ServerConnectingEvent connectingEvent) {
99
+        connection.getParser().map(Parser::getCallbackManager).ifPresent(this::addCallbacks);
100
+    }
101
+
102
+    private void addCallbacks(final CallbackManager callbackManager) {
103
+        callbackManager.addCallback(DataInListener.class, this::handleDataIn);
104
+        callbackManager.addCallback(DataOutListener.class, this::handleDataOut);
105
+    }
106
+
107
+    private void removeCallbacks(final CallbackManager callbackManager) {
108
+        callbackManager.delCallback(DataInListener.class, (DataInListener) this::handleDataIn);
109
+        callbackManager.delCallback(DataOutListener.class, (DataOutListener) this::handleDataOut);
110
+    }
111
+
112
+    private void handleDataIn(final Parser parser, final Date date, final String line) {
113
+        addLine("rawIn", date, line);
114
+    }
115
+
116
+    private void handleDataOut(final Parser parser, final Date date, final String line,
117
+            final boolean fromParser) {
118
+        addLine("rawOut", date, line);
119
+    }
120
+
121
+}

+ 65
- 0
debug/src/com/dmdirc/addons/debug/RawWindowFactory.java View File

@@ -0,0 +1,65 @@
1
+/*
2
+ * Copyright (c) 2006-2015 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.debug;
24
+
25
+import com.dmdirc.interfaces.CommandController;
26
+import com.dmdirc.interfaces.Connection;
27
+import com.dmdirc.ui.WindowManager;
28
+import com.dmdirc.ui.input.TabCompleterFactory;
29
+import com.dmdirc.ui.messages.BackBufferFactory;
30
+import com.dmdirc.ui.messages.sink.MessageSinkManager;
31
+
32
+import javax.inject.Inject;
33
+import javax.inject.Singleton;
34
+
35
+/**
36
+ * Factory for raw windows.
37
+ */
38
+@Singleton
39
+public class RawWindowFactory {
40
+
41
+    private final TabCompleterFactory tabCompleterFactory;
42
+    private final CommandController commandController;
43
+    private final MessageSinkManager messageSinkManager;
44
+    private final BackBufferFactory backBufferFactory;
45
+    private final WindowManager windowManager;
46
+
47
+    @Inject
48
+    public RawWindowFactory(final TabCompleterFactory tabCompleterFactory,
49
+            final CommandController commandController, final MessageSinkManager messageSinkManager,
50
+            final BackBufferFactory backBufferFactory, final WindowManager windowManager) {
51
+        this.tabCompleterFactory = tabCompleterFactory;
52
+        this.commandController = commandController;
53
+        this.messageSinkManager = messageSinkManager;
54
+        this.backBufferFactory = backBufferFactory;
55
+        this.windowManager = windowManager;
56
+    }
57
+
58
+    public RawWindow getRawWindow(final Connection connection) {
59
+        final RawWindow rawWindow = new RawWindow(connection, commandController,
60
+                messageSinkManager, tabCompleterFactory,  backBufferFactory);
61
+        windowManager.addWindow(connection.getWindowModel(), rawWindow);
62
+        return rawWindow;
63
+    }
64
+
65
+}

+ 6
- 4
debug/src/com/dmdirc/addons/debug/commands/ShowRaw.java View File

@@ -25,6 +25,7 @@ package com.dmdirc.addons.debug.commands;
25 25
 import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.addons.debug.Debug;
27 27
 import com.dmdirc.addons.debug.DebugCommand;
28
+import com.dmdirc.addons.debug.RawWindowFactory;
28 29
 import com.dmdirc.commandparser.CommandArguments;
29 30
 import com.dmdirc.commandparser.commands.context.CommandContext;
30 31
 import com.dmdirc.interfaces.Connection;
@@ -40,14 +41,15 @@ import javax.inject.Provider;
40 41
  */
41 42
 public class ShowRaw extends DebugCommand {
42 43
 
44
+    private final RawWindowFactory windowFactory;
45
+
43 46
     /**
44 47
      * Creates a new instance of the command.
45
-     *
46
-     * @param commandProvider The provider to use to access the main debug command.
47 48
      */
48 49
     @Inject
49
-    public ShowRaw(final Provider<Debug> commandProvider) {
50
+    public ShowRaw(final Provider<Debug> commandProvider, final RawWindowFactory windowFactory) {
50 51
         super(commandProvider);
52
+        this.windowFactory = windowFactory;
51 53
     }
52 54
 
53 55
     @Override
@@ -65,7 +67,7 @@ public class ShowRaw extends DebugCommand {
65 67
             final CommandArguments args, final CommandContext context) {
66 68
         final Optional<Connection> connection = origin.getConnection();
67 69
         if (connection.isPresent()) {
68
-            //connection.get().addRaw();
70
+            windowFactory.getRawWindow(connection.get());
69 71
         } else {
70 72
             sendLine(origin, args.isSilent(), FORMAT_ERROR,
71 73
                     "Cannot show raw window here.");

Loading…
Cancel
Save