* Gave ModuleLoader some good lovin'

* Introduced ModuleLoader.PickupModules that currently picks up IRegionModule:s from /bin
* Made LogBase thread-safe (or at least not thread-ignorant)
* Ignored some genned files
afrisby
lbsa71 2007-10-10 18:24:13 +00:00
parent 87d99ee2a2
commit a40e7100a2
21 changed files with 1527 additions and 1483 deletions

View File

@ -46,6 +46,8 @@ namespace OpenSim.Framework.Console
public class LogBase
{
private object m_syncRoot = new object();
StreamWriter Log;
public conscmd_callback cmdparser;
public string componentname;
@ -76,27 +78,6 @@ namespace OpenSim.Framework.Console
Log.Close();
}
[Obsolete("Log.WriteLine is obsolete, use Warn / Error / Verbose instead.")]
public void Write(string format, params object[] args)
{
// HOUSEKEEPING : Will remove once use is removed.
Notice(format, args);
return;
}
[Obsolete("Log.WriteLine is obsolete, use Warn / Error / Verbose instead.")]
public void WriteLine(LogPriority importance, string format, params object[] args)
{
// HOUSEKEEPING : Will remove once use is removed.
Log.WriteLine(format, args);
Log.Flush();
if (!m_silent)
{
System.Console.WriteLine(format, args);
}
return;
}
/// <summary>
/// derive an ansi color from a string, ignoring the darker colors.
/// This is used to help automatically bin component tags with colors
@ -246,6 +227,8 @@ namespace OpenSim.Framework.Console
}
private void WriteNewLine(ConsoleColor color, string format, params object[] args)
{
lock (m_syncRoot)
{
string now = System.DateTime.Now.ToString("[MM-dd hh:mm:ss] ");
Log.Write(now);
@ -270,8 +253,11 @@ namespace OpenSim.Framework.Console
}
return;
}
}
private void WritePrefixLine(ConsoleColor color, string sender)
{
lock (m_syncRoot)
{
sender = sender.ToUpper();
Log.WriteLine("[" + sender + "] ");
@ -298,15 +284,19 @@ namespace OpenSim.Framework.Console
return;
}
}
public string ReadLine()
{
try {
try
{
string TempStr = System.Console.ReadLine();
Log.WriteLine(TempStr);
return TempStr;
} catch (Exception e) {
}
catch (Exception e)
{
MainLog.Instance.Error("Console", "System.Console.ReadLine exception " + e.ToString());
return "";
}
@ -446,9 +436,12 @@ namespace OpenSim.Framework.Console
Array.Resize<string>(ref tempstrarray, tempstrarray.Length - 1);
Array.Reverse(tempstrarray);
string[] cmdparams = (string[])tempstrarray;
try {
try
{
RunCmd(cmd, cmdparams);
} catch (Exception e) {
}
catch (Exception e)
{
MainLog.Instance.Error("Console", "Command failed with exception " + e.ToString());
}
}

View File

@ -113,18 +113,18 @@ namespace OpenSim.Grid.ScriptEngine.DotNetEngine
}
public void CloseDown()
public void Close()
{
}
public string GetName()
public string Name
{
return "LSLScriptingModule";
get { return "LSLScriptingModule"; }
}
public bool IsSharedModule()
public bool IsSharedModule
{
return false;
get { return false; }
}
#endregion

View File

@ -202,7 +202,7 @@ namespace OpenSim
configFiles = Directory.GetFiles(regionConfigPath, "*.xml");
}
m_moduleLoader = new ModuleLoader();
m_moduleLoader = new ModuleLoader( m_log );
MainLog.Instance.Verbose("Loading Shared Modules");
m_moduleLoader.LoadDefaultSharedModules(m_exceptSharedModules);
@ -220,7 +220,9 @@ namespace OpenSim
m_moduleLoader.InitialiseSharedModules(scene);
MainLog.Instance.Verbose("Loading Region's Modules");
m_moduleLoader.CreateDefaultModules(scene, m_exceptModules);
//m_moduleLoader.CreateDefaultModules(scene, m_exceptModules);
m_moduleLoader.PickupModules( scene );
scene.SetModuleInterfaces();
// Check if we have a script engine to load
@ -616,7 +618,7 @@ namespace OpenSim
m_log.Error("The currently loaded shared modules are:");
foreach (OpenSim.Region.Environment.Interfaces.IRegionModule module in m_moduleLoader.LoadedSharedModules.Values)
{
m_log.Error("Shared Module: " + module.GetName());
m_log.Error("Shared Module: " + module.Name);
}
break;
}

View File

@ -6,8 +6,8 @@ namespace OpenSim.Region.Environment.Interfaces
{
void Initialise(Scene scene);
void PostInitialise();
void CloseDown();
string GetName();
bool IsSharedModule();
void Close();
string Name { get; }
bool IsSharedModule { get; }
}
}

View File

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using OpenSim.Framework.Console;
using OpenSim.Region.Environment.Interfaces;
using OpenSim.Region.Environment.Modules;
using OpenSim.Region.Environment.Scenes;
@ -14,43 +15,56 @@ namespace OpenSim.Region.Environment
public List<IRegionModule> LoadedModules = new List<IRegionModule>();
public Dictionary<string, IRegionModule> LoadedSharedModules = new Dictionary<string, IRegionModule>();
private readonly LogBase m_log;
public ModuleLoader()
public ModuleLoader(LogBase log)
{
m_log = log;
}
/// <summary>
/// Should have a module factory?
/// </summary>
/// <param name="scene"></param>
public void CreateDefaultModules(Scene scene, string exceptModules)
//public void CreateDefaultModules(Scene scene, string exceptModules)
//{
// IRegionModule module = new XferModule();
// InitializeModule(module, scene);
// module = new ChatModule();
// InitializeModule(module, scene);
// module = new AvatarProfilesModule();
// InitializeModule(module, scene);
// module = new XMLRPCModule();
// InitializeModule(module, scene);
// module = new WorldCommModule();
// InitializeModule(module, scene);
// LoadRegionModule("OpenSim.Region.ExtensionsScriptModule.dll", "ExtensionsScriptingModule", scene);
// string lslPath = Path.Combine("ScriptEngines", "OpenSim.Region.ScriptEngine.DotNetEngine.dll");
// LoadRegionModule(lslPath, "LSLScriptingModule", scene);
//}
public void PickupModules(Scene scene)
{
IRegionModule module = new XferModule();
InitialiseModule(module, scene);
string moduleDir = ".";
module = new ChatModule();
InitialiseModule(module, scene);
DirectoryInfo dir = new DirectoryInfo(moduleDir);
module = new AvatarProfilesModule();
InitialiseModule(module, scene);
module = new XMLRPCModule();
InitialiseModule(module, scene);
module = new WorldCommModule();
InitialiseModule(module, scene);
LoadRegionModule("OpenSim.Region.ExtensionsScriptModule.dll", "ExtensionsScriptingModule", scene);
string lslPath = Path.Combine("ScriptEngines", "OpenSim.Region.ScriptEngine.DotNetEngine.dll");
LoadRegionModule(lslPath, "LSLScriptingModule", scene);
foreach (FileInfo fileInfo in dir.GetFiles("*.dll"))
{
LoadRegionModules(fileInfo.FullName, scene);
}
}
public void LoadDefaultSharedModules(string exceptModules)
{
DynamicTextureModule dynamicModule = new DynamicTextureModule();
LoadedSharedModules.Add(dynamicModule.GetName(), dynamicModule);
LoadedSharedModules.Add(dynamicModule.Name, dynamicModule);
}
public void InitialiseSharedModules(Scene scene)
@ -58,14 +72,14 @@ namespace OpenSim.Region.Environment
foreach (IRegionModule module in LoadedSharedModules.Values)
{
module.Initialise(scene);
scene.AddModule(module.GetName(), module); //should be doing this?
scene.AddModule(module.Name, module); //should be doing this?
}
}
private void InitialiseModule(IRegionModule module, Scene scene)
private void InitializeModule(IRegionModule module, Scene scene)
{
module.Initialise(scene);
scene.AddModule(module.GetName(), module);
scene.AddModule(module.Name, module);
LoadedModules.Add(module);
}
@ -80,7 +94,22 @@ namespace OpenSim.Region.Environment
IRegionModule module = LoadModule(dllName, moduleName);
if (module != null)
{
LoadedSharedModules.Add(module.GetName(), module);
LoadedSharedModules.Add(module.Name, module);
}
}
public void LoadRegionModules(string dllName, Scene scene)
{
IRegionModule[] modules = LoadModules(dllName);
if (modules.Length > 0)
{
m_log.Verbose("MODULES", "Found Module Library [{0}]", dllName );
foreach (IRegionModule module in modules)
{
m_log.Verbose("MODULES", " [{0}]: Initializing.", module.Name);
InitializeModule(module, scene);
}
}
}
@ -89,7 +118,7 @@ namespace OpenSim.Region.Environment
IRegionModule module = LoadModule(dllName, moduleName);
if (module != null)
{
InitialiseModule(module, scene);
InitializeModule(module, scene);
}
}
@ -101,44 +130,62 @@ namespace OpenSim.Region.Environment
/// <param name="scene"></param>
public IRegionModule LoadModule(string dllName, string moduleName)
{
Assembly pluginAssembly = null;
if (LoadedAssemblys.ContainsKey(dllName))
IRegionModule[] modules = LoadModules(dllName);
foreach (IRegionModule module in modules)
{
pluginAssembly = LoadedAssemblys[dllName];
if ((module != null) && (module.Name == moduleName))
{
return module;
}
else
}
return null;
}
public IRegionModule[] LoadModules(string dllName)
{
List<IRegionModule> modules = new List<IRegionModule>();
Assembly pluginAssembly;
if (!LoadedAssemblys.TryGetValue(dllName, out pluginAssembly ))
{
try
{
pluginAssembly = Assembly.LoadFrom(dllName);
LoadedAssemblys.Add(dllName, pluginAssembly);
}
catch( BadImageFormatException e )
{
m_log.Error( "MODULES", "The file [{0}] is not a valid assembly.", e.FileName );
}
}
IRegionModule module = null;
if (pluginAssembly != null)
{
foreach (Type pluginType in pluginAssembly.GetTypes())
{
if (pluginType.IsPublic)
{
if (!pluginType.IsAbstract)
{
Type typeInterface = pluginType.GetInterface("IRegionModule", true);
//if (dllName.Contains("OpenSim.Region.Environment"))
//{
// int i = 1;
// i++;
//}
if (typeInterface != null)
if( pluginType.GetInterface("IRegionModule") != null )
{
module =
(IRegionModule) Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
break;
}
typeInterface = null;
modules.Add((IRegionModule) Activator.CreateInstance(pluginType));
}
}
}
}
pluginAssembly = null;
if ((module != null) || (module.GetName() == moduleName))
{
return module;
}
return null;
return modules.ToArray();
}
public void PostInitialise()

View File

@ -22,18 +22,18 @@ namespace OpenSim.Region.Environment.Modules
{
}
public void CloseDown()
public void Close()
{
}
public string GetName()
public string Name
{
return "AssetDownloadModule";
get { return "AssetDownloadModule"; }
}
public bool IsSharedModule()
public bool IsSharedModule
{
return false;
get { return false; }
}
public void NewClient(IClientAPI client)

View File

@ -23,18 +23,18 @@ namespace OpenSim.Region.Environment.Modules
{
}
public void CloseDown()
public void Close()
{
}
public string GetName()
public string Name
{
return "AvatarProfilesModule";
get { return "AvatarProfilesModule"; }
}
public bool IsSharedModule()
public bool IsSharedModule
{
return false;
get { return false; }
}
public void NewClient(IClientAPI client)

View File

@ -78,21 +78,21 @@ namespace OpenSim.Region.Environment.Modules
*/
}
public void CloseDown()
public void Close()
{
m_ircWriter.Close();
m_ircReader.Close();
m_irc.Close();
}
public string GetName()
public string Name
{
return "ChatModule";
get { return "ChatModule"; }
}
public bool IsSharedModule()
public bool IsSharedModule
{
return false;
get { return false; }
}
public void NewClient(IClientAPI client)

View File

@ -30,18 +30,18 @@ namespace OpenSim.Region.Environment.Modules
{
}
public void CloseDown()
public void Close()
{
}
public string GetName()
public string Name
{
return "DynamicTextureModule";
get { return "DynamicTextureModule"; }
}
public bool IsSharedModule()
public bool IsSharedModule
{
return true;
get { return true; }
}
public void RegisterRender(string handleType, IDynamicTextureRender render)

View File

@ -16,18 +16,18 @@ namespace OpenSim.Region.Environment.Modules
{
}
public void CloseDown()
public void Close()
{
}
public string GetName()
public string Name
{
return "FriendsModule";
get { return "FriendsModule"; }
}
public bool IsSharedModule()
public bool IsSharedModule
{
return false;
get { return false; }
}
}
}

View File

@ -16,18 +16,18 @@ namespace OpenSim.Region.Environment.Modules
{
}
public void CloseDown()
public void Close()
{
}
public string GetName()
public string Name
{
return "GroupsModule";
get { return "GroupsModule"; }
}
public bool IsSharedModule()
public bool IsSharedModule
{
return false;
get { return false; }
}
}
}

View File

@ -16,18 +16,18 @@ namespace OpenSim.Region.Environment.Modules
{
}
public void CloseDown()
public void Close()
{
}
public string GetName()
public string Name
{
return "InstantMessageModule";
get { return "InstantMessageModule"; }
}
public bool IsSharedModule()
public bool IsSharedModule
{
return false;
get { return false; }
}
}
}

View File

@ -16,18 +16,18 @@ namespace OpenSim.Region.Environment.Modules
{
}
public void CloseDown()
public void Close()
{
}
public string GetName()
public string Name
{
return "InventoryModule";
get { return "InventoryModule"; }
}
public bool IsSharedModule()
public bool IsSharedModule
{
return false;
get { return false; }
}
}
}

View File

@ -23,18 +23,18 @@ namespace OpenSim.Region.Environment.Modules
{
}
public void CloseDown()
public void Close()
{
}
public string GetName()
public string Name
{
return "TextureDownloadModule";
get { return "TextureDownloadModule"; }
}
public bool IsSharedModule()
public bool IsSharedModule
{
return false;
get { return false; }
}
public void NewClient(IClientAPI client)

View File

@ -71,18 +71,18 @@ namespace OpenSim.Region.Environment.Modules
{
}
public void CloseDown()
public void Close()
{
}
public string GetName()
public string Name
{
return m_name;
get { return m_name; }
}
public bool IsSharedModule()
public bool IsSharedModule
{
return false;
get { return false; }
}
public void NewClient(IClientAPI client)

View File

@ -85,18 +85,18 @@ namespace OpenSim.Region.Environment.Modules
{
}
public void CloseDown()
public void Close()
{
}
public string GetName()
public string Name
{
return m_name;
get { return m_name; }
}
public bool IsSharedModule()
public bool IsSharedModule
{
return false;
get { return false; }
}
/**********************************************

View File

@ -30,18 +30,18 @@ namespace OpenSim.Region.Environment.Modules
{
}
public void CloseDown()
public void Close()
{
}
public string GetName()
public string Name
{
return "XferModule";
get { return "XferModule"; }
}
public bool IsSharedModule()
public bool IsSharedModule
{
return false;
get { return false; }
}
public void NewClient(IClientAPI client)

View File

@ -1337,9 +1337,9 @@ namespace OpenSim.Region.Environment.Scenes
MainLog.Instance.Error("The currently loaded modules in " + RegionInfo.RegionName + " are:");
foreach (IRegionModule module in Modules.Values)
{
if (!module.IsSharedModule())
if (!module.IsSharedModule)
{
MainLog.Instance.Error("Region Module: " + module.GetName());
MainLog.Instance.Error("Region Module: " + module.Name);
}
}
break;

View File

@ -62,13 +62,15 @@ namespace SimpleApp
UDPServer udpServer;
m_moduleLoader = new ModuleLoader();
m_moduleLoader = new ModuleLoader( m_log );
m_moduleLoader.LoadDefaultSharedModules("");
Scene scene = SetupScene(regionInfo, out udpServer);
m_moduleLoader.InitialiseSharedModules(scene);
m_moduleLoader.CreateDefaultModules(scene, "");
// m_moduleLoader.CreateDefaultModules(scene, "");
scene.SetModuleInterfaces();
scene.StartTimer();
@ -131,7 +133,7 @@ namespace SimpleApp
protected override Scene CreateScene(RegionInfo regionInfo, StorageManager storageManager, AgentCircuitManager circuitManager)
{
return new MyWorld(regionInfo, circuitManager, m_commsManager, m_assetCache, storageManager, m_httpServer, new ModuleLoader());
return new MyWorld(regionInfo, circuitManager, m_commsManager, m_assetCache, storageManager, m_httpServer, new ModuleLoader( m_log ));
}
protected override StorageManager CreateStorageManager(RegionInfo regionInfo)

View File

@ -80,19 +80,19 @@ namespace OpenSim.Region.ExtensionsScriptModule
}
public void CloseDown()
public void Close()
{
}
public string GetName()
public string Name
{
return "ExtensionsScriptingModule";
get { return "ExtensionsScriptingModule"; }
}
public bool IsSharedModule()
public bool IsSharedModule
{
return false;
get { return false; }
}
public bool Compile(string filename)

View File

@ -113,18 +113,18 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
}
public void CloseDown()
public void Close()
{
}
public string GetName()
public string Name
{
return "LSLScriptingModule";
get { return "LSLScriptingModule"; }
}
public bool IsSharedModule()
public bool IsSharedModule
{
return false;
get { return false; }
}
#endregion