From 9bfbfa381abc92f3c5fc8e97405943128c85c5d4 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Tue, 10 Feb 2009 23:15:48 +0000 Subject: Add proper handling for shared vs. unshared modules to the command interface. Shared modules will now only get added once, so the command handler is called once per module, not once per scene. Removal of scenes has no adverse effects. Nonshared modules will be called for each scene. --- OpenSim/Framework/Console/ConsoleBase.cs | 45 ++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 14 deletions(-) (limited to 'OpenSim/Framework/Console') diff --git a/OpenSim/Framework/Console/ConsoleBase.cs b/OpenSim/Framework/Console/ConsoleBase.cs index 8e61587..721e91a 100644 --- a/OpenSim/Framework/Console/ConsoleBase.cs +++ b/OpenSim/Framework/Console/ConsoleBase.cs @@ -49,6 +49,11 @@ namespace OpenSim.Framework.Console public string module; /// + /// Whether the module is shared + /// + public bool shared; + + /// /// Very short BNF description /// public string help_text; @@ -66,7 +71,7 @@ namespace OpenSim.Framework.Console /// /// The method to invoke for this command /// - public CommandDelegate fn; + public List fn; } /// @@ -172,10 +177,11 @@ namespace OpenSim.Framework.Console /// /// /// - public void AddCommand( - string module, string command, string help, string longhelp, CommandDelegate fn) + public void AddCommand(string module, bool shared, string command, + string help, string longhelp, CommandDelegate fn) { - AddCommand(module, command, help, longhelp, String.Empty, fn); + AddCommand(module, shared, command, help, longhelp, + String.Empty, fn); } /// @@ -187,8 +193,9 @@ namespace OpenSim.Framework.Console /// /// /// - public void AddCommand( - string module, string command, string help, string longhelp, string descriptivehelp, CommandDelegate fn) + public void AddCommand(string module, bool shared, string command, + string help, string longhelp, string descriptivehelp, + CommandDelegate fn) { string[] parts = Parser.Parse(command); @@ -212,15 +219,25 @@ namespace OpenSim.Framework.Console } } + CommandInfo info; + if (current.ContainsKey(String.Empty)) + { + info = (CommandInfo)current[String.Empty]; + if (!info.shared && !info.fn.Contains(fn)) + info.fn.Add(fn); + return; + } - CommandInfo info = new CommandInfo(); + info = new CommandInfo(); info.module = module; + info.shared = shared; info.help_text = help; info.long_help = longhelp; info.descriptive_help = descriptivehelp; - info.fn = fn; + info.fn = new List(); + info.fn.Add(fn); current[String.Empty] = info; } @@ -275,7 +292,7 @@ namespace OpenSim.Framework.Console if (s == String.Empty) { CommandInfo ci = (CommandInfo)current[String.Empty]; - if (ci.fn != null) + if (ci.fn.Count != null) addcr = true; } else @@ -337,9 +354,10 @@ namespace OpenSim.Framework.Console if (current.ContainsKey(String.Empty)) { CommandInfo ci = (CommandInfo)current[String.Empty]; - if (ci.fn == null) + if (ci.fn.Count == null) return new string[0]; - ci.fn(ci.module, result); + foreach (CommandDelegate fn in ci.fn) + fn(ci.module, result); return result; } return new string[0]; @@ -409,9 +427,8 @@ namespace OpenSim.Framework.Console { DefaultPrompt = defaultPrompt; - Commands.AddCommand( - "console", "help", "help []", - "Get general command list or more detailed help on a specific command", Help); + Commands.AddCommand("console", false, "help", "help []", + "Get general command list or more detailed help on a specific command", Help); } public void SetGuiMode(bool mode) -- cgit v1.1