Refactor IEventReceiver back into IScriptEngine

0.6.0-stable
Melanie Thielker 2008-11-08 02:24:34 +00:00
parent 8699c2b3b9
commit 833f5e8bed
15 changed files with 110 additions and 105 deletions

View File

@ -2100,6 +2100,8 @@ namespace OpenSim.Region.Environment.Scenes
SceneObjectGroup sceneObject = m_serialiser.DeserializeGroupFromXml2(objXMLData); SceneObjectGroup sceneObject = m_serialiser.DeserializeGroupFromXml2(objXMLData);
AddRestoredSceneObject(sceneObject, true, false); AddRestoredSceneObject(sceneObject, true, false);
sceneObject.CreateScriptInstances(0, false, DefaultScriptEngine);
SceneObjectPart RootPrim = GetSceneObjectPart(primID); SceneObjectPart RootPrim = GetSceneObjectPart(primID);
if (RootPrim != null) if (RootPrim != null)
{ {

View File

@ -44,7 +44,7 @@ using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
namespace OpenSim.Region.ScriptEngine.DotNetEngine namespace OpenSim.Region.ScriptEngine.DotNetEngine
{ {
[Serializable] [Serializable]
public class ScriptEngine : IRegionModule, IEventReceiver, IScriptModule public class ScriptEngine : IRegionModule, IScriptEngine, IScriptModule
{ {
private static readonly ILog m_log = private static readonly ILog m_log =
LogManager.GetLogger( LogManager.GetLogger(
@ -388,5 +388,20 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
{ {
return m_ScriptManager.GetApi(itemID, name); return m_ScriptManager.GetApi(itemID, name);
} }
public IScriptWorkItem QueueEventHandler(Object o)
{
return null;
}
public string GetAssemblyName(UUID itemID)
{
return "";
}
public string GetXMLState(UUID itemID)
{
return "";
}
} }
} }

View File

@ -1,71 +0,0 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using log4net;
using System;
using OpenSim.Region.ScriptEngine.Shared;
using OpenSim.Region.Environment.Scenes;
using OpenMetaverse;
using Nini.Config;
using OpenSim.Region.ScriptEngine.Interfaces;
using Amib.Threading;
using OpenSim.Framework;
namespace OpenSim.Region.ScriptEngine.Interfaces
{
/// <summary>
/// An interface for a script API module to communicate with
/// the engine it's running under
/// </summary>
public interface IEventReceiver
{
Scene World { get; }
/// <summary>
/// Post an event to a single script
/// </summary>
bool PostScriptEvent(UUID itemID, EventParams parms);
/// <summary>
/// Post event to an entire prim
/// </summary>
bool PostObjectEvent(uint localID, EventParams parms);
DetectParams GetDetectParams(UUID item, int number);
int GetStartParameter(UUID itemID);
void SetScriptState(UUID itemID, bool state);
bool GetScriptState(UUID itemID);
void SetState(UUID itemID, string newState);
void ApiResetScript(UUID itemID);
void ResetScript(UUID itemID);
IConfig Config { get; }
string ScriptEngineName { get; }
ILog Log { get; }
IScriptApi GetApi(UUID itemID, string name);
}
}

View File

@ -38,6 +38,6 @@ namespace OpenSim.Region.ScriptEngine.Interfaces
// Each API has an identifier, which is used to load the // Each API has an identifier, which is used to load the
// proper runtime assembly at load time. // proper runtime assembly at load time.
// //
void Initialize(IEventReceiver engine, SceneObjectPart part, uint localID, UUID item); void Initialize(IScriptEngine engine, SceneObjectPart part, uint localID, UUID item);
} }
} }

View File

@ -33,6 +33,7 @@ using OpenMetaverse;
using Nini.Config; using Nini.Config;
using OpenSim.Region.ScriptEngine.Interfaces; using OpenSim.Region.ScriptEngine.Interfaces;
using Amib.Threading; using Amib.Threading;
using OpenSim.Framework;
namespace OpenSim.Region.ScriptEngine.Interfaces namespace OpenSim.Region.ScriptEngine.Interfaces
{ {
@ -40,11 +41,39 @@ namespace OpenSim.Region.ScriptEngine.Interfaces
/// An interface for a script API module to communicate with /// An interface for a script API module to communicate with
/// the engine it's running under /// the engine it's running under
/// </summary> /// </summary>
public interface IScriptEngine : IEventReceiver public interface IScriptEngine
{ {
/// <summary> /// <summary>
/// Queue an event for execution /// Queue an event for execution
/// </summary> /// </summary>
IScriptWorkItem QueueEventHandler(object parms); IScriptWorkItem QueueEventHandler(object parms);
Scene World { get; }
/// <summary>
/// Post an event to a single script
/// </summary>
bool PostScriptEvent(UUID itemID, EventParams parms);
/// <summary>
/// Post event to an entire prim
/// </summary>
bool PostObjectEvent(uint localID, EventParams parms);
DetectParams GetDetectParams(UUID item, int number);
int GetStartParameter(UUID itemID);
void SetScriptState(UUID itemID, bool state);
bool GetScriptState(UUID itemID);
void SetState(UUID itemID, string newState);
void ApiResetScript(UUID itemID);
void ResetScript(UUID itemID);
IConfig Config { get; }
string ScriptEngineName { get; }
ILog Log { get; }
IScriptApi GetApi(UUID itemID, string name);
string GetAssemblyName(UUID itemID);
string GetXMLState(UUID itemID);
} }
} }

View File

@ -99,5 +99,8 @@ namespace OpenSim.Region.ScriptEngine.Interfaces
Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> LineMap Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> LineMap
{ get; set; } { get; set; }
string GetAssemblyName();
string GetXMLState();
} }
} }

View File

@ -48,24 +48,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
private static int cmdHandlerThreadCycleSleepms; private static int cmdHandlerThreadCycleSleepms;
private static List<IScene> m_Scenes = new List<IScene>(); private static List<IScene> m_Scenes = new List<IScene>();
private static List<IEventReceiver> m_ScriptEngines = private static List<IScriptEngine> m_ScriptEngines =
new List<IEventReceiver>(); new List<IScriptEngine>();
public IEventReceiver m_ScriptEngine; public IScriptEngine m_ScriptEngine;
private IScene m_Scene; private IScene m_Scene;
private static Dictionary<IEventReceiver, Dataserver> m_Dataserver = private static Dictionary<IScriptEngine, Dataserver> m_Dataserver =
new Dictionary<IEventReceiver, Dataserver>(); new Dictionary<IScriptEngine, Dataserver>();
private static Dictionary<IEventReceiver, Timer> m_Timer = private static Dictionary<IScriptEngine, Timer> m_Timer =
new Dictionary<IEventReceiver, Timer>(); new Dictionary<IScriptEngine, Timer>();
private static Dictionary<IEventReceiver, Listener> m_Listener = private static Dictionary<IScriptEngine, Listener> m_Listener =
new Dictionary<IEventReceiver, Listener>(); new Dictionary<IScriptEngine, Listener>();
private static Dictionary<IEventReceiver, HttpRequest> m_HttpRequest = private static Dictionary<IScriptEngine, HttpRequest> m_HttpRequest =
new Dictionary<IEventReceiver, HttpRequest>(); new Dictionary<IScriptEngine, HttpRequest>();
private static Dictionary<IEventReceiver, SensorRepeat> m_SensorRepeat = private static Dictionary<IScriptEngine, SensorRepeat> m_SensorRepeat =
new Dictionary<IEventReceiver, SensorRepeat>(); new Dictionary<IScriptEngine, SensorRepeat>();
private static Dictionary<IEventReceiver, XmlRequest> m_XmlRequest = private static Dictionary<IScriptEngine, XmlRequest> m_XmlRequest =
new Dictionary<IEventReceiver, XmlRequest>(); new Dictionary<IScriptEngine, XmlRequest>();
public Dataserver DataserverPlugin public Dataserver DataserverPlugin
{ {
@ -97,12 +97,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
get { return m_XmlRequest[m_ScriptEngine]; } get { return m_XmlRequest[m_ScriptEngine]; }
} }
public IEventReceiver[] ScriptEngines public IScriptEngine[] ScriptEngines
{ {
get { return m_ScriptEngines.ToArray(); } get { return m_ScriptEngines.ToArray(); }
} }
public AsyncCommandManager(IEventReceiver _ScriptEngine) public AsyncCommandManager(IScriptEngine _ScriptEngine)
{ {
m_ScriptEngine = _ScriptEngine; m_ScriptEngine = _ScriptEngine;
m_Scene = m_ScriptEngine.World; m_Scene = m_ScriptEngine.World;
@ -202,7 +202,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
// Check XMLRPCRequests // Check XMLRPCRequests
m_XmlRequest[m_ScriptEngines[0]].CheckXMLRPCRequests(); m_XmlRequest[m_ScriptEngines[0]].CheckXMLRPCRequests();
foreach (IEventReceiver s in m_ScriptEngines) foreach (IScriptEngine s in m_ScriptEngines)
{ {
// Check Listeners // Check Listeners
m_Listener[s].CheckListeners(); m_Listener[s].CheckListeners();
@ -223,7 +223,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
/// </summary> /// </summary>
/// <param name="localID"></param> /// <param name="localID"></param>
/// <param name="itemID"></param> /// <param name="itemID"></param>
public static void RemoveScript(IEventReceiver engine, uint localID, UUID itemID) public static void RemoveScript(IScriptEngine engine, uint localID, UUID itemID)
{ {
// Remove a specific script // Remove a specific script
@ -250,7 +250,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
} }
public static Object[] GetSerializationData(IEventReceiver engine, UUID itemID) public static Object[] GetSerializationData(IScriptEngine engine, UUID itemID)
{ {
List<Object> data = new List<Object>(); List<Object> data = new List<Object>();
@ -281,7 +281,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return data.ToArray(); return data.ToArray();
} }
public static void CreateFromData(IEventReceiver engine, uint localID, public static void CreateFromData(IScriptEngine engine, uint localID,
UUID itemID, UUID hostID, Object[] data) UUID itemID, UUID hostID, Object[] data)
{ {
int idx = 0; int idx = 0;

View File

@ -66,7 +66,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
/// </summary> /// </summary>
public class LSL_Api : MarshalByRefObject, ILSL_Api, IScriptApi public class LSL_Api : MarshalByRefObject, ILSL_Api, IScriptApi
{ {
protected IEventReceiver m_ScriptEngine; protected IScriptEngine m_ScriptEngine;
protected SceneObjectPart m_host; protected SceneObjectPart m_host;
protected uint m_localID; protected uint m_localID;
protected UUID m_itemID; protected UUID m_itemID;
@ -80,7 +80,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
//private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); //private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public void Initialize(IEventReceiver ScriptEngine, SceneObjectPart host, uint localID, UUID itemID) public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID)
{ {
m_ScriptEngine = ScriptEngine; m_ScriptEngine = ScriptEngine;
m_host = host; m_host = host;

View File

@ -99,7 +99,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
[Serializable] [Serializable]
public class OSSL_Api : MarshalByRefObject, IOSSL_Api, IScriptApi public class OSSL_Api : MarshalByRefObject, IOSSL_Api, IScriptApi
{ {
internal IEventReceiver m_ScriptEngine; internal IScriptEngine m_ScriptEngine;
internal ILSL_Api m_LSL_Api; // get a reference to the LSL API so we can call methods housed there internal ILSL_Api m_LSL_Api; // get a reference to the LSL API so we can call methods housed there
internal SceneObjectPart m_host; internal SceneObjectPart m_host;
internal uint m_localID; internal uint m_localID;
@ -110,7 +110,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
internal float m_ScriptDistanceFactor = 1.0f; internal float m_ScriptDistanceFactor = 1.0f;
internal Dictionary<string, List<UUID> > m_FunctionPerms = new Dictionary<string, List<UUID> >(); internal Dictionary<string, List<UUID> > m_FunctionPerms = new Dictionary<string, List<UUID> >();
public void Initialize(IEventReceiver ScriptEngine, SceneObjectPart host, uint localID, UUID itemID) public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID)
{ {
m_ScriptEngine = ScriptEngine; m_ScriptEngine = ScriptEngine;
m_host = host; m_host = host;

View File

@ -77,7 +77,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
new LSL_Types.LSLString(httpInfo.response_body) new LSL_Types.LSLString(httpInfo.response_body)
}; };
foreach (IEventReceiver e in m_CmdManager.ScriptEngines) foreach (IScriptEngine e in m_CmdManager.ScriptEngines)
{ {
if (e.PostObjectEvent(httpInfo.localID, if (e.PostObjectEvent(httpInfo.localID,
new EventParams("http_response", new EventParams("http_response",

View File

@ -67,7 +67,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
new LSL_Types.LSLString(lInfo.GetMessage()) new LSL_Types.LSLString(lInfo.GetMessage())
}; };
foreach (IEventReceiver e in m_CmdManager.ScriptEngines) foreach (IScriptEngine e in m_CmdManager.ScriptEngines)
{ {
e.PostScriptEvent( e.PostScriptEvent(
lInfo.GetItemID(), new EventParams( lInfo.GetItemID(), new EventParams(

View File

@ -71,7 +71,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
new LSL_Types.LSLString(rInfo.GetStrVal()) new LSL_Types.LSLString(rInfo.GetStrVal())
}; };
foreach (IEventReceiver e in m_CmdManager.ScriptEngines) foreach (IScriptEngine e in m_CmdManager.ScriptEngines)
{ {
if (e.PostScriptEvent( if (e.PostScriptEvent(
rInfo.GetItemID(), new EventParams( rInfo.GetItemID(), new EventParams(
@ -100,7 +100,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
new LSL_Types.LSLString(srdInfo.sdata) new LSL_Types.LSLString(srdInfo.sdata)
}; };
foreach (IEventReceiver e in m_CmdManager.ScriptEngines) foreach (IScriptEngine e in m_CmdManager.ScriptEngines)
{ {
if (e.PostScriptEvent( if (e.PostScriptEvent(
srdInfo.m_itemID, new EventParams( srdInfo.m_itemID, new EventParams(

View File

@ -83,8 +83,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
// private static int instanceID = new Random().Next(0, int.MaxValue); // Unique number to use on our compiled files // private static int instanceID = new Random().Next(0, int.MaxValue); // Unique number to use on our compiled files
private static UInt64 scriptCompileCounter = 0; // And a counter private static UInt64 scriptCompileCounter = 0; // And a counter
public IEventReceiver m_scriptEngine; public IScriptEngine m_scriptEngine;
public Compiler(IEventReceiver scriptEngine) public Compiler(IScriptEngine scriptEngine)
{ {
m_scriptEngine = scriptEngine; m_scriptEngine = scriptEngine;
ReadConfig(); ReadConfig();

View File

@ -848,5 +848,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
return e.ToString(); return e.ToString();
} }
public string GetAssemblyName()
{
return m_Assembly;
}
public string GetXMLState()
{
Stop(100);
return ScriptSerializer.Serialize(this);
}
} }
} }

View File

@ -985,5 +985,21 @@ namespace OpenSim.Region.ScriptEngine.XEngine
controllingClient.AgentId); controllingClient.AgentId);
} }
} }
public string GetAssemblyName(UUID itemID)
{
IScriptInstance instance = GetInstance(itemID);
if (instance == null)
return null;
return instance.GetAssemblyName();
}
public string GetXMLState(UUID itemID)
{
IScriptInstance instance = GetInstance(itemID);
if (instance == null)
return null;
return instance.GetXMLState();
}
} }
} }