aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2012-11-22 04:05:09 +0000
committerJustin Clark-Casey (justincc)2012-11-22 04:05:09 +0000
commit5c48d7a378ff066f59b9cee02f2803ebe1616481 (patch)
tree82af06819d5bb9d184890b5395e831b4e47c91d7 /OpenSim
parentrefactor: Factor out copy/pasted server uptime report code (diff)
downloadopensim-SC-5c48d7a378ff066f59b9cee02f2803ebe1616481.zip
opensim-SC-5c48d7a378ff066f59b9cee02f2803ebe1616481.tar.gz
opensim-SC-5c48d7a378ff066f59b9cee02f2803ebe1616481.tar.bz2
opensim-SC-5c48d7a378ff066f59b9cee02f2803ebe1616481.tar.xz
factor out common HandleShow code for "show uptime"
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Console/CommandConsole.cs2
-rwxr-xr-xOpenSim/Framework/Console/ConsoleBase.cs10
-rw-r--r--OpenSim/Framework/Console/MockConsole.cs7
-rw-r--r--OpenSim/Framework/ICommandConsole.cs5
-rw-r--r--OpenSim/Framework/IConsole.cs2
-rw-r--r--OpenSim/Framework/Servers/BaseOpenSimServer.cs39
-rw-r--r--OpenSim/Framework/Servers/ServerBase.cs50
-rw-r--r--OpenSim/Region/Application/OpenSimBase.cs2
-rw-r--r--OpenSim/Server/Base/ServicesServerBase.cs18
9 files changed, 72 insertions, 63 deletions
diff --git a/OpenSim/Framework/Console/CommandConsole.cs b/OpenSim/Framework/Console/CommandConsole.cs
index bd23d1c..d1e29b4 100644
--- a/OpenSim/Framework/Console/CommandConsole.cs
+++ b/OpenSim/Framework/Console/CommandConsole.cs
@@ -711,7 +711,7 @@ namespace OpenSim.Framework.Console
711 /// </summary> 711 /// </summary>
712 public void Prompt() 712 public void Prompt()
713 { 713 {
714 string line = ReadLine(m_defaultPrompt + "# ", true, true); 714 string line = ReadLine(DefaultPrompt + "# ", true, true);
715 715
716 if (line != String.Empty) 716 if (line != String.Empty)
717 Output("Invalid command"); 717 Output("Invalid command");
diff --git a/OpenSim/Framework/Console/ConsoleBase.cs b/OpenSim/Framework/Console/ConsoleBase.cs
index 4b375d9..2d8e723 100755
--- a/OpenSim/Framework/Console/ConsoleBase.cs
+++ b/OpenSim/Framework/Console/ConsoleBase.cs
@@ -43,15 +43,7 @@ namespace OpenSim.Framework.Console
43 43
44 public object ConsoleScene { get; set; } 44 public object ConsoleScene { get; set; }
45 45
46 /// <summary> 46 public string DefaultPrompt { get; set; }
47 /// The default prompt text.
48 /// </summary>
49 public string DefaultPrompt
50 {
51 set { m_defaultPrompt = value; }
52 get { return m_defaultPrompt; }
53 }
54 protected string m_defaultPrompt;
55 47
56 public ConsoleBase(string defaultPrompt) 48 public ConsoleBase(string defaultPrompt)
57 { 49 {
diff --git a/OpenSim/Framework/Console/MockConsole.cs b/OpenSim/Framework/Console/MockConsole.cs
index b489f93..8ba58e4 100644
--- a/OpenSim/Framework/Console/MockConsole.cs
+++ b/OpenSim/Framework/Console/MockConsole.cs
@@ -46,13 +46,18 @@ namespace OpenSim.Framework.Console
46 46
47 public ICommands Commands { get { return m_commands; } } 47 public ICommands Commands { get { return m_commands; } }
48 48
49 public string DefaultPrompt { get; set; }
50
49 public void Prompt() {} 51 public void Prompt() {}
50 52
51 public void RunCommand(string cmd) {} 53 public void RunCommand(string cmd) {}
52 54
53 public string ReadLine(string p, bool isCommand, bool e) { return ""; } 55 public string ReadLine(string p, bool isCommand, bool e) { return ""; }
54 56
55 public object ConsoleScene { get { return null; } } 57 public object ConsoleScene {
58 get { return null; }
59 set {}
60 }
56 61
57 public void Output(string text, string level) {} 62 public void Output(string text, string level) {}
58 public void Output(string text) {} 63 public void Output(string text) {}
diff --git a/OpenSim/Framework/ICommandConsole.cs b/OpenSim/Framework/ICommandConsole.cs
index 8cd20da..a6573f8 100644
--- a/OpenSim/Framework/ICommandConsole.cs
+++ b/OpenSim/Framework/ICommandConsole.cs
@@ -83,6 +83,11 @@ namespace OpenSim.Framework
83 ICommands Commands { get; } 83 ICommands Commands { get; }
84 84
85 /// <summary> 85 /// <summary>
86 /// The default prompt text.
87 /// </summary>
88 string DefaultPrompt { get; set; }
89
90 /// <summary>
86 /// Display a command prompt on the console and wait for user input 91 /// Display a command prompt on the console and wait for user input
87 /// </summary> 92 /// </summary>
88 void Prompt(); 93 void Prompt();
diff --git a/OpenSim/Framework/IConsole.cs b/OpenSim/Framework/IConsole.cs
index 33024b2..79560d8 100644
--- a/OpenSim/Framework/IConsole.cs
+++ b/OpenSim/Framework/IConsole.cs
@@ -32,7 +32,7 @@ namespace OpenSim.Framework
32{ 32{
33 public interface IConsole 33 public interface IConsole
34 { 34 {
35 object ConsoleScene { get; } 35 object ConsoleScene { get; set; }
36 36
37 void Output(string text, string level); 37 void Output(string text, string level);
38 void Output(string text); 38 void Output(string text);
diff --git a/OpenSim/Framework/Servers/BaseOpenSimServer.cs b/OpenSim/Framework/Servers/BaseOpenSimServer.cs
index 6346279..4f9ac08 100644
--- a/OpenSim/Framework/Servers/BaseOpenSimServer.cs
+++ b/OpenSim/Framework/Servers/BaseOpenSimServer.cs
@@ -62,7 +62,6 @@ namespace OpenSim.Framework.Servers
62 /// </summary> 62 /// </summary>
63 private Timer m_periodicDiagnosticsTimer = new Timer(60 * 60 * 1000); 63 private Timer m_periodicDiagnosticsTimer = new Timer(60 * 60 * 1000);
64 64
65 protected CommandConsole m_console;
66 protected OpenSimAppender m_consoleAppender; 65 protected OpenSimAppender m_consoleAppender;
67 protected IAppender m_logFileAppender = null; 66 protected IAppender m_logFileAppender = null;
68 67
@@ -139,7 +138,8 @@ namespace OpenSim.Framework.Servers
139 } 138 }
140 else 139 else
141 { 140 {
142 m_consoleAppender.Console = m_console; 141 // FIXME: This should be done through an interface rather than casting.
142 m_consoleAppender.Console = (ConsoleBase)m_console;
143 143
144 // If there is no threshold set then the threshold is effectively everything. 144 // If there is no threshold set then the threshold is effectively everything.
145 if (null == m_consoleAppender.Threshold) 145 if (null == m_consoleAppender.Threshold)
@@ -367,8 +367,10 @@ namespace OpenSim.Framework.Servers
367 } 367 }
368 } 368 }
369 369
370 public virtual void HandleShow(string module, string[] cmd) 370 public override void HandleShow(string module, string[] cmd)
371 { 371 {
372 base.HandleShow(module, cmd);
373
372 List<string> args = new List<string>(cmd); 374 List<string> args = new List<string>(cmd);
373 375
374 args.RemoveAt(0); 376 args.RemoveAt(0);
@@ -385,10 +387,6 @@ namespace OpenSim.Framework.Servers
385 Notice(GetThreadsReport()); 387 Notice(GetThreadsReport());
386 break; 388 break;
387 389
388 case "uptime":
389 Notice(GetUptimeReport());
390 break;
391
392 case "version": 390 case "version":
393 Notice(GetVersionText()); 391 Notice(GetVersionText());
394 break; 392 break;
@@ -430,33 +428,6 @@ namespace OpenSim.Framework.Servers
430 } 428 }
431 429
432 /// <summary> 430 /// <summary>
433 /// Console output is only possible if a console has been established.
434 /// That is something that cannot be determined within this class. So
435 /// all attempts to use the console MUST be verified.
436 /// </summary>
437 /// <param name="msg"></param>
438 protected void Notice(string msg)
439 {
440 if (m_console != null)
441 {
442 m_console.Output(msg);
443 }
444 }
445
446 /// <summary>
447 /// Console output is only possible if a console has been established.
448 /// That is something that cannot be determined within this class. So
449 /// all attempts to use the console MUST be verified.
450 /// </summary>
451 /// <param name="format"></param>
452 /// <param name="components"></param>
453 protected void Notice(string format, params string[] components)
454 {
455 if (m_console != null)
456 m_console.OutputFormat(format, components);
457 }
458
459 /// <summary>
460 /// Enhance the version string with extra information if it's available. 431 /// Enhance the version string with extra information if it's available.
461 /// </summary> 432 /// </summary>
462 protected void EnhanceVersionInformation() 433 protected void EnhanceVersionInformation()
diff --git a/OpenSim/Framework/Servers/ServerBase.cs b/OpenSim/Framework/Servers/ServerBase.cs
index d19234b..afe1f73 100644
--- a/OpenSim/Framework/Servers/ServerBase.cs
+++ b/OpenSim/Framework/Servers/ServerBase.cs
@@ -26,13 +26,20 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections.Generic;
29using System.Text; 30using System.Text;
31using OpenSim.Framework.Console;
30 32
31namespace OpenSim.Framework.Servers 33namespace OpenSim.Framework.Servers
32{ 34{
33 public class ServerBase 35 public class ServerBase
34 { 36 {
35 /// <summary> 37 /// <summary>
38 /// Console to be used for any command line output. Can be null, in which case there should be no output.
39 /// </summary>
40 protected ICommandConsole m_console;
41
42 /// <summary>
36 /// Time at which this server was started 43 /// Time at which this server was started
37 /// </summary> 44 /// </summary>
38 protected DateTime m_startuptime; 45 protected DateTime m_startuptime;
@@ -42,6 +49,22 @@ namespace OpenSim.Framework.Servers
42 m_startuptime = DateTime.Now; 49 m_startuptime = DateTime.Now;
43 } 50 }
44 51
52 public virtual void HandleShow(string module, string[] cmd)
53 {
54 List<string> args = new List<string>(cmd);
55
56 args.RemoveAt(0);
57
58 string[] showParams = args.ToArray();
59
60 switch (showParams[0])
61 {
62 case "uptime":
63 Notice(GetUptimeReport());
64 break;
65 }
66 }
67
45 /// <summary> 68 /// <summary>
46 /// Return a report about the uptime of this server 69 /// Return a report about the uptime of this server
47 /// </summary> 70 /// </summary>
@@ -54,5 +77,32 @@ namespace OpenSim.Framework.Servers
54 77
55 return sb.ToString(); 78 return sb.ToString();
56 } 79 }
80
81 /// <summary>
82 /// Console output is only possible if a console has been established.
83 /// That is something that cannot be determined within this class. So
84 /// all attempts to use the console MUST be verified.
85 /// </summary>
86 /// <param name="msg"></param>
87 protected void Notice(string msg)
88 {
89 if (m_console != null)
90 {
91 m_console.Output(msg);
92 }
93 }
94
95 /// <summary>
96 /// Console output is only possible if a console has been established.
97 /// That is something that cannot be determined within this class. So
98 /// all attempts to use the console MUST be verified.
99 /// </summary>
100 /// <param name="format"></param>
101 /// <param name="components"></param>
102 protected void Notice(string format, params string[] components)
103 {
104 if (m_console != null)
105 m_console.OutputFormat(format, components);
106 }
57 } 107 }
58} \ No newline at end of file 108} \ No newline at end of file
diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs
index 808c760..618ce0a 100644
--- a/OpenSim/Region/Application/OpenSimBase.cs
+++ b/OpenSim/Region/Application/OpenSimBase.cs
@@ -242,7 +242,7 @@ namespace OpenSim
242 } 242 }
243 } 243 }
244 244
245 protected virtual void AddPluginCommands(CommandConsole console) 245 protected virtual void AddPluginCommands(ICommandConsole console)
246 { 246 {
247 List<string> topics = GetHelpTopics(); 247 List<string> topics = GetHelpTopics();
248 248
diff --git a/OpenSim/Server/Base/ServicesServerBase.cs b/OpenSim/Server/Base/ServicesServerBase.cs
index 56bb7ae..7b49ac9 100644
--- a/OpenSim/Server/Base/ServicesServerBase.cs
+++ b/OpenSim/Server/Base/ServicesServerBase.cs
@@ -174,6 +174,8 @@ namespace OpenSim.Server.Base
174 MainConsole.Instance = new LocalConsole(prompt); 174 MainConsole.Instance = new LocalConsole(prompt);
175 } 175 }
176 176
177 m_console = MainConsole.Instance;
178
177 // Configure the appenders for log4net 179 // Configure the appenders for log4net
178 // 180 //
179 OpenSimAppender consoleAppender = null; 181 OpenSimAppender consoleAppender = null;
@@ -351,21 +353,5 @@ namespace OpenSim.Server.Base
351 { 353 {
352 } 354 }
353 } 355 }
354
355 public virtual void HandleShow(string module, string[] cmd)
356 {
357 List<string> args = new List<string>(cmd);
358
359 args.RemoveAt(0);
360
361 string[] showParams = args.ToArray();
362
363 switch (showParams[0])
364 {
365 case "uptime":
366 MainConsole.Instance.Output(GetUptimeReport());
367 break;
368 }
369 }
370 } 356 }
371} \ No newline at end of file 357} \ No newline at end of file