OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
ScriptEngineConsoleCommands.cs
Go to the documentation of this file.
1 /*
2  * Copyright (c) Contributors, http://opensimulator.org/
3  * See CONTRIBUTORS.TXT for a full list of copyright holders.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the OpenSimulator Project nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 using System;
29 using System.Collections.Generic;
30 using OpenSim.Framework;
31 using OpenSim.Framework.Console;
32 using OpenSim.Region.ScriptEngine.Interfaces;
33 using OpenSim.Region.ScriptEngine.Shared.Api;
34 using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
35 
36 namespace OpenSim.Region.ScriptEngine.XEngine
37 {
39  {
40  IScriptEngine m_engine;
41 
43  {
44  m_engine = engine;
45  }
46 
47  public void RegisterCommands()
48  {
49  MainConsole.Instance.Commands.AddCommand(
50  "Scripts", false, "show script sensors", "show script sensors", "Show script sensors information",
51  HandleShowSensors);
52 
53  MainConsole.Instance.Commands.AddCommand(
54  "Scripts", false, "show script timers", "show script timers", "Show script sensors information",
55  HandleShowTimers);
56  }
57 
58  private bool IsSceneSelected()
59  {
60  return MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_engine.World;
61  }
62 
63  private void HandleShowSensors(string module, string[] cmdparams)
64  {
65  if (!IsSceneSelected())
66  return;
67 
68  SensorRepeat sr = AsyncCommandManager.GetSensorRepeatPlugin(m_engine);
69 
70  if (sr == null)
71  {
72  MainConsole.Instance.Output("Plugin not yet initialized");
73  return;
74  }
75 
76  List<SensorRepeat.SensorInfo> sensorInfo = sr.GetSensorInfo();
77 
79  cdt.AddColumn("Part name", 40);
80  cdt.AddColumn("Script item ID", 36);
81  cdt.AddColumn("Type", 4);
82  cdt.AddColumn("Interval", 8);
83  cdt.AddColumn("Range", 8);
84  cdt.AddColumn("Arc", 8);
85 
86  foreach (SensorRepeat.SensorInfo s in sensorInfo)
87  {
88  cdt.AddRow(s.host.Name, s.itemID, s.type, s.interval, s.range, s.arc);
89  }
90 
91  MainConsole.Instance.Output(cdt.ToString());
92  MainConsole.Instance.OutputFormat("Total: {0}", sensorInfo.Count);
93  }
94 
95  private void HandleShowTimers(string module, string[] cmdparams)
96  {
97  if (!IsSceneSelected())
98  return;
99 
100  Timer timerPlugin = AsyncCommandManager.GetTimerPlugin(m_engine);
101 
102  if (timerPlugin == null)
103  {
104  MainConsole.Instance.Output("Plugin not yet initialized");
105  return;
106  }
107 
108  List<Timer.TimerInfo> timersInfo = timerPlugin.GetTimersInfo();
109 
111  cdt.AddColumn("Part local ID", 13);
112  cdt.AddColumn("Script item ID", 36);
113  cdt.AddColumn("Interval", 10);
114  cdt.AddColumn("Next", 8);
115 
116  foreach (Timer.TimerInfo t in timersInfo)
117  {
118  // Convert from 100 ns ticks back to seconds
119  cdt.AddRow(t.localID, t.itemID, (double)t.interval / 10000000, t.next);
120  }
121 
122  MainConsole.Instance.Output(cdt.ToString());
123  MainConsole.Instance.OutputFormat("Total: {0}", timersInfo.Count);
124  }
125  }
126 }
Used to generated a formatted table for the console.
An interface for a script API module to communicate with the engine it's running under ...