* refactor: Move module handling code up into SceneBase from Scene, reducing the large number of different things that Scene does

0.6.3-post-fixes
Justin Clarke Casey 2009-02-05 18:36:53 +00:00
parent efcf00ee60
commit d04025ff3d
4 changed files with 191 additions and 192 deletions

View File

@ -52,7 +52,7 @@ using OpenSim.Region.Physics.Manager;
namespace OpenSim namespace OpenSim
{ {
/// <summary> /// <summary>
/// Common OpenSim region service code /// Common OpenSim simulator code
/// </summary> /// </summary>
public class OpenSimBase : RegionApplicationBase public class OpenSimBase : RegionApplicationBase
{ {
@ -76,13 +76,12 @@ namespace OpenSim
/// </summary> /// </summary>
protected const string DEFAULT_INV_BACKUP_FILENAME = "opensim_inv.tar.gz"; protected const string DEFAULT_INV_BACKUP_FILENAME = "opensim_inv.tar.gz";
protected ConfigSettings m_configSettings;
public ConfigSettings ConfigurationSettings public ConfigSettings ConfigurationSettings
{ {
get { return m_configSettings; } get { return m_configSettings; }
set { m_configSettings = value; } set { m_configSettings = value; }
} }
protected ConfigSettings m_configSettings;
protected ConfigurationLoader m_configLoader; protected ConfigurationLoader m_configLoader;
@ -125,13 +124,12 @@ namespace OpenSim
get { return m_httpServerPort; } get { return m_httpServerPort; }
} }
protected ModuleLoader m_moduleLoader;
public ModuleLoader ModuleLoader public ModuleLoader ModuleLoader
{ {
get { return m_moduleLoader; } get { return m_moduleLoader; }
set { m_moduleLoader = value; } set { m_moduleLoader = value; }
} }
protected ModuleLoader m_moduleLoader;
/// <summary> /// <summary>
/// Constructor. /// Constructor.
@ -441,7 +439,7 @@ namespace OpenSim
if (!String.IsNullOrEmpty(scene.RegionInfo.RegionFile)) if (!String.IsNullOrEmpty(scene.RegionInfo.RegionFile))
{ {
File.Delete(scene.RegionInfo.RegionFile); File.Delete(scene.RegionInfo.RegionFile);
m_log.InfoFormat("[OPENSIM MAIN] deleting region file \"{0}\"", scene.RegionInfo.RegionFile); m_log.InfoFormat("[OPENSIM]: deleting region file \"{0}\"", scene.RegionInfo.RegionFile);
} }
} }
@ -480,7 +478,7 @@ namespace OpenSim
public void handleRestartRegion(RegionInfo whichRegion) public void handleRestartRegion(RegionInfo whichRegion)
{ {
m_log.Error("[OPENSIM MAIN]: Got restart signal from SceneManager"); m_log.Info("[OPENSIM]: Got restart signal from SceneManager");
// Shutting down the client server // Shutting down the client server
bool foundClientServer = false; bool foundClientServer = false;
@ -488,8 +486,6 @@ namespace OpenSim
for (int i = 0; i < m_clientServers.Count; i++) for (int i = 0; i < m_clientServers.Count; i++)
{ {
//--> Melanie, the following needs to be fixed
// the Equals override is not returning true if the locations are actually equal
if (m_clientServers[i].HandlesRegion(new Location(whichRegion.RegionHandle))) if (m_clientServers[i].HandlesRegion(new Location(whichRegion.RegionHandle)))
{ {
clientServerElement = i; clientServerElement = i;
@ -497,6 +493,7 @@ namespace OpenSim
break; break;
} }
} }
if (foundClientServer) if (foundClientServer)
{ {
m_clientServers[clientServerElement].Server.Close(); m_clientServers[clientServerElement].Server.Close();

View File

@ -263,6 +263,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain
throw new TerrainException(String.Format("unable to load heightmap: parser {0} does not support loading", loader.Value)); throw new TerrainException(String.Format("unable to load heightmap: parser {0} does not support loading", loader.Value));
} }
} }
CheckForTerrainUpdates(); CheckForTerrainUpdates();
m_log.Info("[TERRAIN]: File (" + filename + ") loaded successfully"); m_log.Info("[TERRAIN]: File (" + filename + ") loaded successfully");
return; return;

View File

@ -113,25 +113,6 @@ namespace OpenSim.Region.Environment.Scenes
get { return m_sceneGridService; } get { return m_sceneGridService; }
} }
/// <value>
/// All the region modules attached to this scene.
/// </value>
public Dictionary<string, IRegionModule> Modules
{
get { return m_modules; }
}
protected Dictionary<string, IRegionModule> m_modules = new Dictionary<string, IRegionModule>();
/// <value>
/// The module interfaces available from this scene.
/// </value>
protected Dictionary<Type, List<object> > ModuleInterfaces = new Dictionary<Type, List<object> >();
protected Dictionary<string, object> ModuleAPIMethods = new Dictionary<string, object>();
protected Dictionary<string, ICommander> m_moduleCommanders = new Dictionary<string, ICommander>();
//API module interfaces
public IXfer XferManager; public IXfer XferManager;
protected IXMLRPC m_xmlrpcModule; protected IXMLRPC m_xmlrpcModule;
@ -281,11 +262,6 @@ namespace OpenSim.Region.Environment.Scenes
public int objectCapacity = 45000; public int objectCapacity = 45000;
/// <value>
/// Registered classes that are capable of creating entities.
/// </value>
protected Dictionary<PCode, IEntityCreator> m_entityCreators = new Dictionary<PCode, IEntityCreator>();
#endregion #endregion
#region Constructors #region Constructors
@ -737,16 +713,6 @@ namespace OpenSim.Region.Environment.Scenes
// De-register with region communications (events cleanup) // De-register with region communications (events cleanup)
UnRegisterRegionWithComms(); UnRegisterRegionWithComms();
// Shut down all non shared modules.
foreach (IRegionModule module in Modules.Values)
{
if (!module.IsSharedModule)
{
module.Close();
}
}
Modules.Clear();
// call the base class Close method. // call the base class Close method.
base.Close(); base.Close();
} }
@ -1838,6 +1804,7 @@ namespace OpenSim.Region.Environment.Scenes
/// <summary> /// <summary>
/// Add an object into the scene that has come from storage /// Add an object into the scene that has come from storage
/// </summary> /// </summary>
///
/// <param name="sceneObject"></param> /// <param name="sceneObject"></param>
/// <param name="attachToBackup"> /// <param name="attachToBackup">
/// If true, changes to the object will be reflected in its persisted data /// If true, changes to the object will be reflected in its persisted data
@ -3158,127 +3125,7 @@ namespace OpenSim.Region.Environment.Scenes
#endregion #endregion
#region Module Methods #region Other Methods
/// <summary>
/// Add a module to this scene.
/// </summary>
/// <param name="name"></param>
/// <param name="module"></param>
public void AddModule(string name, IRegionModule module)
{
if (!Modules.ContainsKey(name))
{
Modules.Add(name, module);
}
}
public void RegisterModuleCommander(string name, ICommander commander)
{
lock (m_moduleCommanders)
{
m_moduleCommanders.Add(name, commander);
}
}
public ICommander GetCommander(string name)
{
lock (m_moduleCommanders)
{
return m_moduleCommanders[name];
}
}
public Dictionary<string, ICommander> GetCommanders()
{
return m_moduleCommanders;
}
/// <summary>
/// Register an interface to a region module. This allows module methods to be called directly as
/// well as via events. If there is already a module registered for this interface, it is not replaced
/// (is this the best behaviour?)
/// </summary>
/// <param name="mod"></param>
public void RegisterModuleInterface<M>(M mod)
{
if (!ModuleInterfaces.ContainsKey(typeof(M)))
{
List<Object> l = new List<Object>();
l.Add(mod);
ModuleInterfaces.Add(typeof(M), l);
if (mod is IEntityCreator)
{
IEntityCreator entityCreator = (IEntityCreator)mod;
foreach (PCode pcode in entityCreator.CreationCapabilities)
{
m_entityCreators[pcode] = entityCreator;
}
}
}
}
public void StackModuleInterface<M>(M mod)
{
List<Object> l;
if (ModuleInterfaces.ContainsKey(typeof(M)))
l = ModuleInterfaces[typeof(M)];
else
l = new List<Object>();
if (l.Contains(mod))
return;
l.Add(mod);
if (mod is IEntityCreator)
{
IEntityCreator entityCreator = (IEntityCreator)mod;
foreach (PCode pcode in entityCreator.CreationCapabilities)
{
m_entityCreators[pcode] = entityCreator;
}
}
ModuleInterfaces[typeof(M)] = l;
}
/// <summary>
/// For the given interface, retrieve the region module which implements it.
/// </summary>
/// <returns>null if there is no registered module implementing that interface</returns>
public override T RequestModuleInterface<T>()
{
if (ModuleInterfaces.ContainsKey(typeof(T)))
{
return (T)ModuleInterfaces[typeof(T)][0];
}
else
{
return default(T);
}
}
/// <summary>
/// For the given interface, retrieve an array of region modules that implement it.
/// </summary>
/// <returns>an empty array if there are no registered modules implementing that interface</returns>
public override T[] RequestModuleInterfaces<T>()
{
if (ModuleInterfaces.ContainsKey(typeof(T)))
{
List<T> ret = new List<T>();
foreach (Object o in ModuleInterfaces[typeof(T)])
ret.Add((T)o);
return ret.ToArray();
}
else
{
return new T[] { default(T) };
}
}
public void SetObjectCapacity(int objects) public void SetObjectCapacity(int objects)
{ {
@ -3314,10 +3161,6 @@ namespace OpenSim.Region.Environment.Scenes
return CommsManager.TriggerTerminateFriend(regionHandle, agentID, exFriendID); return CommsManager.TriggerTerminateFriend(regionHandle, agentID, exFriendID);
} }
#endregion
#region Other Methods
public virtual void StoreAddFriendship(UUID ownerID, UUID friendID, uint perms) public virtual void StoreAddFriendship(UUID ownerID, UUID friendID, uint perms)
{ {
m_sceneGridService.AddNewUserFriend(ownerID, friendID, perms); m_sceneGridService.AddNewUserFriend(ownerID, friendID, perms);
@ -3563,12 +3406,10 @@ namespace OpenSim.Region.Environment.Scenes
} }
} }
/// <summary> public override void Show(string[] showParams)
/// Shows various details about the sim based on the parameters supplied by the console command in openSimMain.
/// </summary>
/// <param name="showParams">What to show</param>
public void Show(string[] showParams)
{ {
base.Show(showParams);
switch (showParams[0]) switch (showParams[0])
{ {
case "users": case "users":
@ -3587,16 +3428,7 @@ namespace OpenSim.Region.Environment.Scenes
"Unknown", "Unknown",
RegionInfo.RegionName); RegionInfo.RegionName);
} }
break;
case "modules":
m_log.Error("The currently loaded modules in " + RegionInfo.RegionName + " are:");
foreach (IRegionModule module in Modules.Values)
{
if (!module.IsSharedModule)
{
m_log.Error("Region Module: " + module.Name);
}
}
break; break;
} }
} }

View File

@ -49,6 +49,30 @@ namespace OpenSim.Region.Environment.Scenes
#region Fields #region Fields
/// <value>
/// All the region modules attached to this scene.
/// </value>
public Dictionary<string, IRegionModule> Modules
{
get { return m_modules; }
}
protected Dictionary<string, IRegionModule> m_modules = new Dictionary<string, IRegionModule>();
/// <value>
/// The module interfaces available from this scene.
/// </value>
protected Dictionary<Type, List<object> > ModuleInterfaces = new Dictionary<Type, List<object> >();
protected Dictionary<string, object> ModuleAPIMethods = new Dictionary<string, object>();
protected Dictionary<string, ICommander> m_moduleCommanders = new Dictionary<string, ICommander>();
/// <value>
/// Registered classes that are capable of creating entities.
/// </value>
protected Dictionary<PCode, IEntityCreator> m_entityCreators = new Dictionary<PCode, IEntityCreator>();
//API module interfaces
/// <summary> /// <summary>
/// The last allocated local prim id. When a new local id is requested, the next number in the sequence is /// The last allocated local prim id. When a new local id is requested, the next number in the sequence is
/// dispensed. /// dispensed.
@ -202,6 +226,16 @@ namespace OpenSim.Region.Environment.Scenes
/// </summary> /// </summary>
public virtual void Close() public virtual void Close()
{ {
// Shut down all non shared modules.
foreach (IRegionModule module in Modules.Values)
{
if (!module.IsSharedModule)
{
module.Close();
}
}
Modules.Clear();
try try
{ {
EventManager.TriggerShutdown(); EventManager.TriggerShutdown();
@ -229,14 +263,149 @@ namespace OpenSim.Region.Environment.Scenes
return myID; return myID;
} }
public virtual T RequestModuleInterface<T>() #region Module Methods
/// <summary>
/// Add a module to this scene.
/// </summary>
/// <param name="name"></param>
/// <param name="module"></param>
public void AddModule(string name, IRegionModule module)
{ {
return default(T); if (!Modules.ContainsKey(name))
{
Modules.Add(name, module);
}
} }
public virtual T[] RequestModuleInterfaces<T>() public void RegisterModuleCommander(string name, ICommander commander)
{ {
return new T[] { default(T) }; lock (m_moduleCommanders)
{
m_moduleCommanders.Add(name, commander);
}
}
public ICommander GetCommander(string name)
{
lock (m_moduleCommanders)
{
return m_moduleCommanders[name];
}
}
public Dictionary<string, ICommander> GetCommanders()
{
return m_moduleCommanders;
}
/// <summary>
/// Register an interface to a region module. This allows module methods to be called directly as
/// well as via events. If there is already a module registered for this interface, it is not replaced
/// (is this the best behaviour?)
/// </summary>
/// <param name="mod"></param>
public void RegisterModuleInterface<M>(M mod)
{
if (!ModuleInterfaces.ContainsKey(typeof(M)))
{
List<Object> l = new List<Object>();
l.Add(mod);
ModuleInterfaces.Add(typeof(M), l);
if (mod is IEntityCreator)
{
IEntityCreator entityCreator = (IEntityCreator)mod;
foreach (PCode pcode in entityCreator.CreationCapabilities)
{
m_entityCreators[pcode] = entityCreator;
}
}
}
}
public void StackModuleInterface<M>(M mod)
{
List<Object> l;
if (ModuleInterfaces.ContainsKey(typeof(M)))
l = ModuleInterfaces[typeof(M)];
else
l = new List<Object>();
if (l.Contains(mod))
return;
l.Add(mod);
if (mod is IEntityCreator)
{
IEntityCreator entityCreator = (IEntityCreator)mod;
foreach (PCode pcode in entityCreator.CreationCapabilities)
{
m_entityCreators[pcode] = entityCreator;
}
}
ModuleInterfaces[typeof(M)] = l;
}
/// <summary>
/// For the given interface, retrieve the region module which implements it.
/// </summary>
/// <returns>null if there is no registered module implementing that interface</returns>
public T RequestModuleInterface<T>()
{
if (ModuleInterfaces.ContainsKey(typeof(T)))
{
return (T)ModuleInterfaces[typeof(T)][0];
}
else
{
return default(T);
}
}
/// <summary>
/// For the given interface, retrieve an array of region modules that implement it.
/// </summary>
/// <returns>an empty array if there are no registered modules implementing that interface</returns>
public T[] RequestModuleInterfaces<T>()
{
if (ModuleInterfaces.ContainsKey(typeof(T)))
{
List<T> ret = new List<T>();
foreach (Object o in ModuleInterfaces[typeof(T)])
ret.Add((T)o);
return ret.ToArray();
}
else
{
return new T[] { default(T) };
}
}
#endregion
/// <summary>
/// Shows various details about the sim based on the parameters supplied by the console command in openSimMain.
/// </summary>
/// <param name="showParams">What to show</param>
public virtual void Show(string[] showParams)
{
switch (showParams[0])
{
case "modules":
m_log.Error("The currently loaded modules in " + RegionInfo.RegionName + " are:");
foreach (IRegionModule module in Modules.Values)
{
if (!module.IsSharedModule)
{
m_log.Error("Region Module: " + module.Name);
}
}
break;
}
} }
} }
} }