|
@@ -0,0 +1,133 @@
|
|
1
|
+/*
|
|
2
|
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
|
|
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.parserdebug;
|
|
24
|
+
|
|
25
|
+import com.dmdirc.FrameContainer;
|
|
26
|
+import com.dmdirc.commandparser.CommandArguments;
|
|
27
|
+import com.dmdirc.commandparser.CommandInfo;
|
|
28
|
+import com.dmdirc.commandparser.CommandManager;
|
|
29
|
+import com.dmdirc.commandparser.CommandType;
|
|
30
|
+import com.dmdirc.commandparser.commands.Command;
|
|
31
|
+import com.dmdirc.commandparser.commands.CommandOptions;
|
|
32
|
+import com.dmdirc.commandparser.commands.context.CommandContext;
|
|
33
|
+import com.dmdirc.commandparser.commands.context.ServerCommandContext;
|
|
34
|
+import com.dmdirc.parser.interfaces.Parser;
|
|
35
|
+import com.dmdirc.parser.interfaces.callbacks.DebugInfoListener;
|
|
36
|
+
|
|
37
|
+/**
|
|
38
|
+ * The ParserDebug Command allows controlling of which parsers spam debug info.
|
|
39
|
+ *
|
|
40
|
+ * @author Shane "Dataforce" Mc Cormack
|
|
41
|
+ */
|
|
42
|
+@CommandOptions(allowOffline=false)
|
|
43
|
+public final class ParserDebugCommand extends Command implements CommandInfo {
|
|
44
|
+ /** My Plugin */
|
|
45
|
+ final DebugPlugin myPlugin;
|
|
46
|
+
|
|
47
|
+ /**
|
|
48
|
+ * Creates a new instance of ParserDebugCommand.
|
|
49
|
+ *
|
|
50
|
+ * @param plugin Plugin that owns this command
|
|
51
|
+ */
|
|
52
|
+ public ParserDebugCommand(final DebugPlugin plugin) {
|
|
53
|
+ super();
|
|
54
|
+ myPlugin = plugin;
|
|
55
|
+ CommandManager.registerCommand(this);
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+ /** {@inheritDoc} */
|
|
59
|
+ @Override
|
|
60
|
+ public CommandType getType() {
|
|
61
|
+ return CommandType.TYPE_SERVER;
|
|
62
|
+ }
|
|
63
|
+
|
|
64
|
+ /**
|
|
65
|
+ * Executes this command.
|
|
66
|
+ *
|
|
67
|
+ * @param origin The framecontainer in which this command was issued
|
|
68
|
+ * @param commandArgs The user supplied arguments
|
|
69
|
+ * @param context The Context of this command execution
|
|
70
|
+ */
|
|
71
|
+ @Override
|
|
72
|
+ public void execute(final FrameContainer<?> origin, final CommandArguments commandArgs, final CommandContext context) {
|
|
73
|
+ final String[] args = commandArgs.getArguments();
|
|
74
|
+ final boolean isSilent = commandArgs.isSilent();
|
|
75
|
+
|
|
76
|
+ Parser parser = ((ServerCommandContext) context).getServer().getParser();
|
|
77
|
+
|
|
78
|
+ if (parser == null) {
|
|
79
|
+ sendLine(origin, isSilent, FORMAT_ERROR, "Unable to get a parser for this window.");
|
|
80
|
+ return;
|
|
81
|
+ }
|
|
82
|
+ if (myPlugin.registeredParsers.containsKey(parser)) {
|
|
83
|
+ try {
|
|
84
|
+ parser.getCallbackManager().delCallback(DebugInfoListener.class, myPlugin);
|
|
85
|
+ DebugWindow window = myPlugin.registeredParsers.get(parser);
|
|
86
|
+ window.addLine("======================", true);
|
|
87
|
+ window.addLine("No Longer Monitoring: "+parser+" (User Requested)", true);
|
|
88
|
+ window.addLine("======================", true);
|
|
89
|
+ myPlugin.registeredParsers.remove(parser);
|
|
90
|
+ sendLine(origin, isSilent, FORMAT_OUTPUT, "Removing callback ok");
|
|
91
|
+ } catch (Exception e) {
|
|
92
|
+ sendLine(origin, isSilent, FORMAT_ERROR, "Removing callback failed");
|
|
93
|
+ }
|
|
94
|
+ } else {
|
|
95
|
+ try {
|
|
96
|
+ parser.getCallbackManager().addCallback(DebugInfoListener.class, myPlugin);
|
|
97
|
+ DebugWindow window = new DebugWindow(myPlugin, "Parser Debug", parser, origin.getServer());
|
|
98
|
+ myPlugin.registeredParsers.put(parser, window);
|
|
99
|
+ sendLine(origin, isSilent, FORMAT_OUTPUT, "Adding callback ok");
|
|
100
|
+ window.addLine("======================", true);
|
|
101
|
+ window.addLine("Started Monitoring: "+parser, true);
|
|
102
|
+ window.addLine("======================", true);
|
|
103
|
+ } catch (Exception e) {
|
|
104
|
+ sendLine(origin, isSilent, FORMAT_ERROR, "Adding callback failed");
|
|
105
|
+ }
|
|
106
|
+ }
|
|
107
|
+ }
|
|
108
|
+
|
|
109
|
+ /**
|
|
110
|
+ * Returns this command's name.
|
|
111
|
+ *
|
|
112
|
+ * @return The name of this command
|
|
113
|
+ */
|
|
114
|
+ @Override
|
|
115
|
+ public String getName() { return "parserdebug"; }
|
|
116
|
+
|
|
117
|
+ /**
|
|
118
|
+ * Returns whether or not this command should be shown in help messages.
|
|
119
|
+ *
|
|
120
|
+ * @return True iff the command should be shown, false otherwise
|
|
121
|
+ */
|
|
122
|
+ @Override
|
|
123
|
+ public boolean showInHelp() { return true; }
|
|
124
|
+
|
|
125
|
+ /**
|
|
126
|
+ * Returns a string representing the help message for this command.
|
|
127
|
+ *
|
|
128
|
+ * @return the help message for this command
|
|
129
|
+ */
|
|
130
|
+ @Override
|
|
131
|
+ public String getHelp() { return "parserdebug - Enables/Disables hooks for onDebugInfo for the parser that owns this window"; }
|
|
132
|
+}
|
|
133
|
+
|