factor out common HandleShow code for "show uptime"

0.7.4-extended
Justin Clark-Casey (justincc) 2012-11-22 04:05:09 +00:00
parent d68ba391fc
commit 08234d0097
9 changed files with 74 additions and 65 deletions

View File

@ -702,7 +702,7 @@ namespace OpenSim.Framework.Console
/// </summary> /// </summary>
public void Prompt() public void Prompt()
{ {
string line = ReadLine(m_defaultPrompt + "# ", true, true); string line = ReadLine(DefaultPrompt + "# ", true, true);
if (line != String.Empty) if (line != String.Empty)
Output("Invalid command"); Output("Invalid command");

View File

@ -43,15 +43,7 @@ namespace OpenSim.Framework.Console
public object ConsoleScene { get; set; } public object ConsoleScene { get; set; }
/// <summary> public string DefaultPrompt { get; set; }
/// The default prompt text.
/// </summary>
public string DefaultPrompt
{
set { m_defaultPrompt = value; }
get { return m_defaultPrompt; }
}
protected string m_defaultPrompt;
public ConsoleBase(string defaultPrompt) public ConsoleBase(string defaultPrompt)
{ {

View File

@ -44,13 +44,18 @@ namespace OpenSim.Framework.Console
public ICommands Commands { get { return m_commands; } } public ICommands Commands { get { return m_commands; } }
public string DefaultPrompt { get; set; }
public void Prompt() {} public void Prompt() {}
public void RunCommand(string cmd) {} public void RunCommand(string cmd) {}
public string ReadLine(string p, bool isCommand, bool e) { return ""; } public string ReadLine(string p, bool isCommand, bool e) { return ""; }
public object ConsoleScene { get { return null; } } public object ConsoleScene {
get { return null; }
set {}
}
public void Output(string text, string level) {} public void Output(string text, string level) {}
public void Output(string text) {} public void Output(string text) {}
@ -76,4 +81,4 @@ namespace OpenSim.Framework.Console
public string[] Resolve(string[] cmd) { return null; } public string[] Resolve(string[] cmd) { return null; }
public XmlElement GetXml(XmlDocument doc) { return null; } public XmlElement GetXml(XmlDocument doc) { return null; }
} }
} }

View File

@ -78,6 +78,11 @@ namespace OpenSim.Framework
{ {
ICommands Commands { get; } ICommands Commands { get; }
/// <summary>
/// The default prompt text.
/// </summary>
string DefaultPrompt { get; set; }
/// <summary> /// <summary>
/// Display a command prompt on the console and wait for user input /// Display a command prompt on the console and wait for user input
/// </summary> /// </summary>
@ -87,4 +92,4 @@ namespace OpenSim.Framework
string ReadLine(string p, bool isCommand, bool e); string ReadLine(string p, bool isCommand, bool e);
} }
} }

View File

@ -32,7 +32,7 @@ namespace OpenSim.Framework
{ {
public interface IConsole public interface IConsole
{ {
object ConsoleScene { get; } object ConsoleScene { get; set; }
void Output(string text, string level); void Output(string text, string level);
void Output(string text); void Output(string text);

View File

@ -62,7 +62,6 @@ namespace OpenSim.Framework.Servers
/// </summary> /// </summary>
private Timer m_periodicDiagnosticsTimer = new Timer(60 * 60 * 1000); private Timer m_periodicDiagnosticsTimer = new Timer(60 * 60 * 1000);
protected CommandConsole m_console;
protected OpenSimAppender m_consoleAppender; protected OpenSimAppender m_consoleAppender;
protected IAppender m_logFileAppender = null; protected IAppender m_logFileAppender = null;
@ -139,7 +138,8 @@ namespace OpenSim.Framework.Servers
} }
else else
{ {
m_consoleAppender.Console = m_console; // FIXME: This should be done through an interface rather than casting.
m_consoleAppender.Console = (ConsoleBase)m_console;
// If there is no threshold set then the threshold is effectively everything. // If there is no threshold set then the threshold is effectively everything.
if (null == m_consoleAppender.Threshold) if (null == m_consoleAppender.Threshold)
@ -367,8 +367,10 @@ namespace OpenSim.Framework.Servers
} }
} }
public virtual void HandleShow(string module, string[] cmd) public override void HandleShow(string module, string[] cmd)
{ {
base.HandleShow(module, cmd);
List<string> args = new List<string>(cmd); List<string> args = new List<string>(cmd);
args.RemoveAt(0); args.RemoveAt(0);
@ -385,10 +387,6 @@ namespace OpenSim.Framework.Servers
Notice(GetThreadsReport()); Notice(GetThreadsReport());
break; break;
case "uptime":
Notice(GetUptimeReport());
break;
case "version": case "version":
Notice(GetVersionText()); Notice(GetVersionText());
break; break;
@ -429,33 +427,6 @@ namespace OpenSim.Framework.Servers
return String.Format("Version: {0} (interface version {1})", m_version, VersionInfo.MajorInterfaceVersion); return String.Format("Version: {0} (interface version {1})", m_version, VersionInfo.MajorInterfaceVersion);
} }
/// <summary>
/// Console output is only possible if a console has been established.
/// That is something that cannot be determined within this class. So
/// all attempts to use the console MUST be verified.
/// </summary>
/// <param name="msg"></param>
protected void Notice(string msg)
{
if (m_console != null)
{
m_console.Output(msg);
}
}
/// <summary>
/// Console output is only possible if a console has been established.
/// That is something that cannot be determined within this class. So
/// all attempts to use the console MUST be verified.
/// </summary>
/// <param name="format"></param>
/// <param name="components"></param>
protected void Notice(string format, params string[] components)
{
if (m_console != null)
m_console.OutputFormat(format, components);
}
/// <summary> /// <summary>
/// Enhance the version string with extra information if it's available. /// Enhance the version string with extra information if it's available.
/// </summary> /// </summary>

View File

@ -26,12 +26,19 @@
*/ */
using System; using System;
using System.Collections.Generic;
using System.Text; using System.Text;
using OpenSim.Framework.Console;
namespace OpenSim.Framework.Servers namespace OpenSim.Framework.Servers
{ {
public class ServerBase public class ServerBase
{ {
/// <summary>
/// Console to be used for any command line output. Can be null, in which case there should be no output.
/// </summary>
protected ICommandConsole m_console;
/// <summary> /// <summary>
/// Time at which this server was started /// Time at which this server was started
/// </summary> /// </summary>
@ -42,6 +49,22 @@ namespace OpenSim.Framework.Servers
m_startuptime = DateTime.Now; m_startuptime = DateTime.Now;
} }
public virtual void HandleShow(string module, string[] cmd)
{
List<string> args = new List<string>(cmd);
args.RemoveAt(0);
string[] showParams = args.ToArray();
switch (showParams[0])
{
case "uptime":
Notice(GetUptimeReport());
break;
}
}
/// <summary> /// <summary>
/// Return a report about the uptime of this server /// Return a report about the uptime of this server
/// </summary> /// </summary>
@ -54,5 +77,32 @@ namespace OpenSim.Framework.Servers
return sb.ToString(); return sb.ToString();
} }
/// <summary>
/// Console output is only possible if a console has been established.
/// That is something that cannot be determined within this class. So
/// all attempts to use the console MUST be verified.
/// </summary>
/// <param name="msg"></param>
protected void Notice(string msg)
{
if (m_console != null)
{
m_console.Output(msg);
}
}
/// <summary>
/// Console output is only possible if a console has been established.
/// That is something that cannot be determined within this class. So
/// all attempts to use the console MUST be verified.
/// </summary>
/// <param name="format"></param>
/// <param name="components"></param>
protected void Notice(string format, params string[] components)
{
if (m_console != null)
m_console.OutputFormat(format, components);
}
} }
} }

View File

@ -253,7 +253,7 @@ namespace OpenSim
} }
} }
protected virtual void AddPluginCommands(CommandConsole console) protected virtual void AddPluginCommands(ICommandConsole console)
{ {
List<string> topics = GetHelpTopics(); List<string> topics = GetHelpTopics();

View File

@ -174,6 +174,8 @@ namespace OpenSim.Server.Base
MainConsole.Instance = new LocalConsole(prompt); MainConsole.Instance = new LocalConsole(prompt);
} }
m_console = MainConsole.Instance;
// Configure the appenders for log4net // Configure the appenders for log4net
// //
OpenSimAppender consoleAppender = null; OpenSimAppender consoleAppender = null;
@ -351,21 +353,5 @@ namespace OpenSim.Server.Base
{ {
} }
} }
public virtual void HandleShow(string module, string[] cmd)
{
List<string> args = new List<string>(cmd);
args.RemoveAt(0);
string[] showParams = args.ToArray();
switch (showParams[0])
{
case "uptime":
MainConsole.Instance.Output(GetUptimeReport());
break;
}
}
} }
} }