OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
MockScriptEngine.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;
30 using System.Collections.Generic;
31 using System.Reflection;
32 using Nini.Config;
33 using OpenMetaverse;
34 using OpenSim.Framework;
35 using OpenSim.Region.Framework.Interfaces;
36 using OpenSim.Region.Framework.Scenes;
37 using OpenSim.Region.ScriptEngine.Interfaces;
38 using OpenSim.Region.ScriptEngine.Shared;
39 
40 namespace OpenSim.Tests.Common
41 {
43  {
44  public IConfigSource ConfigSource { get; private set; }
45 
46  public IConfig Config { get; private set; }
47 
48  private Scene m_scene;
49 
53  public Dictionary<UUID, List<EventParams>> PostedEvents { get; private set; }
54 
61  public event Action<UUID, EventParams> PostEventHook;
62 
63  public void Initialise(IConfigSource source)
64  {
65  ConfigSource = source;
66 
67  // Can set later on if required
68  Config = new IniConfig("MockScriptEngine", ConfigSource);
69 
70  PostedEvents = new Dictionary<UUID, List<EventParams>>();
71  }
72 
73  public void Close()
74  {
75  }
76 
77  public void AddRegion(Scene scene)
78  {
79  m_scene = scene;
80 
81  m_scene.StackModuleInterface<IScriptModule>(this);
82  }
83 
84  public void RemoveRegion(Scene scene)
85  {
86  }
87 
88  public void RegionLoaded(Scene scene)
89  {
90  }
91 
92  public string Name { get { return "Mock Script Engine"; } }
93  public string ScriptEngineName { get { return Name; } }
94 
95  public Type ReplaceableInterface { get { return null; } }
96 
97 #pragma warning disable 0067
100 #pragma warning restore 0067
101 
102  public string GetXMLState (UUID itemID)
103  {
104  throw new System.NotImplementedException ();
105  }
106 
107  public bool SetXMLState(UUID itemID, string xml)
108  {
109  throw new System.NotImplementedException ();
110  }
111 
112  public bool PostScriptEvent(UUID itemID, string name, object[] args)
113  {
114 // Console.WriteLine("Posting event {0} for {1}", name, itemID);
115 
116  return PostScriptEvent(itemID, new EventParams(name, args, null));
117  }
118 
119  public bool PostScriptEvent(UUID itemID, EventParams evParams)
120  {
121  List<EventParams> eventsForItem;
122 
123  if (!PostedEvents.ContainsKey(itemID))
124  {
125  eventsForItem = new List<EventParams>();
126  PostedEvents.Add(itemID, eventsForItem);
127  }
128  else
129  {
130  eventsForItem = PostedEvents[itemID];
131  }
132 
133  eventsForItem.Add(evParams);
134 
135  if (PostEventHook != null)
136  PostEventHook(itemID, evParams);
137 
138  return true;
139  }
140 
141  public bool PostObjectEvent(uint localID, EventParams evParams)
142  {
143  return PostObjectEvent(m_scene.GetSceneObjectPart(localID), evParams);
144  }
145 
146  public bool PostObjectEvent(UUID itemID, string name, object[] args)
147  {
148  return PostObjectEvent(m_scene.GetSceneObjectPart(itemID), new EventParams(name, args, null));
149  }
150 
151  private bool PostObjectEvent(SceneObjectPart part, EventParams evParams)
152  {
153  foreach (TaskInventoryItem item in part.Inventory.GetInventoryItems(InventoryType.LSL))
154  PostScriptEvent(item.ItemID, evParams);
155 
156  return true;
157  }
158 
159  public void SuspendScript(UUID itemID)
160  {
161  throw new System.NotImplementedException ();
162  }
163 
164  public void ResumeScript(UUID itemID)
165  {
166  throw new System.NotImplementedException ();
167  }
168 
169  public ArrayList GetScriptErrors(UUID itemID)
170  {
171  throw new System.NotImplementedException ();
172  }
173 
174  public bool HasScript(UUID itemID, out bool running)
175  {
176  throw new System.NotImplementedException ();
177  }
178 
179  public bool GetScriptState(UUID itemID)
180  {
181  throw new System.NotImplementedException ();
182  }
183 
184  public void SaveAllState()
185  {
186  throw new System.NotImplementedException ();
187  }
188 
189  public void StartProcessing()
190  {
191  throw new System.NotImplementedException ();
192  }
193 
194  public float GetScriptExecutionTime(List<UUID> itemIDs)
195  {
196  throw new System.NotImplementedException ();
197  }
198 
199  public Dictionary<uint, float> GetObjectScriptsExecutionTimes()
200  {
201  throw new System.NotImplementedException ();
202  }
203 
204  public IScriptWorkItem QueueEventHandler(object parms)
205  {
206  throw new System.NotImplementedException ();
207  }
208 
209  public DetectParams GetDetectParams(UUID item, int number)
210  {
211  throw new System.NotImplementedException ();
212  }
213 
214  public void SetMinEventDelay(UUID itemID, double delay)
215  {
216  throw new System.NotImplementedException ();
217  }
218 
219  public int GetStartParameter(UUID itemID)
220  {
221  throw new System.NotImplementedException ();
222  }
223 
224  public void SetScriptState(UUID itemID, bool state)
225  {
226  throw new System.NotImplementedException ();
227  }
228 
229  public void SetState(UUID itemID, string newState)
230  {
231  throw new System.NotImplementedException ();
232  }
233 
234  public void ApiResetScript(UUID itemID)
235  {
236  throw new System.NotImplementedException ();
237  }
238 
239  public void ResetScript (UUID itemID)
240  {
241  throw new System.NotImplementedException ();
242  }
243 
244  public IScriptApi GetApi(UUID itemID, string name)
245  {
246  throw new System.NotImplementedException ();
247  }
248 
249  public Scene World { get { return m_scene; } }
250 
251  public IScriptModule ScriptModule { get { return this; } }
252 
253  public string ScriptEnginePath { get { throw new System.NotImplementedException (); }}
254 
255  public string ScriptClassName { get { throw new System.NotImplementedException (); } }
256 
257  public string ScriptBaseClassName { get { throw new System.NotImplementedException (); } }
258 
259  public string[] ScriptReferencedAssemblies { get { throw new System.NotImplementedException (); } }
260 
261  public ParameterInfo[] ScriptBaseClassParameters { get { throw new System.NotImplementedException (); } }
262 
263  public void ClearPostedEvents()
264  {
265  PostedEvents.Clear();
266  }
267 
268  public void SleepScript(UUID itemID, int delay)
269  {
270  }
271  }
272 }
void SetMinEventDelay(UUID itemID, double delay)
void ResumeScript(UUID itemID)
Resumes a script.
void SetScriptState(UUID itemID, bool state)
IEntityInventory Inventory
This part's inventory
IScriptWorkItem QueueEventHandler(object parms)
Queue an event for execution
bool HasScript(UUID itemID, out bool running)
bool GetScriptState(UUID itemID)
Returns true if a script is running.
bool PostScriptEvent(UUID itemID, EventParams evParams)
Post an event to a single script
void SuspendScript(UUID itemID)
Suspends a script.
DetectParams GetDetectParams(UUID item, int number)
Represents an item in a task inventory
bool PostObjectEvent(uint localID, EventParams evParams)
Post event to an entire prim
float GetScriptExecutionTime(List< UUID > itemIDs)
Get the execution times of all scripts in the given array if they are currently running.
An interface for a script API module to communicate with the engine it's running under ...
bool PostObjectEvent(UUID itemID, string name, object[] args)
bool SetXMLState(UUID itemID, string xml)
delegate void ObjectRemoved(UUID prim)
List< TaskInventoryItem > GetInventoryItems()
Get all inventory items.
void SetState(UUID itemID, string newState)
Action< UUID, EventParams > PostEventHook
A very primitive way of hooking text cose to a posed event.
void Initialise(IConfigSource source)
This is called to initialize the region module. For shared modules, this is called exactly once...
void StartProcessing()
Starts the processing threads.
bool PostScriptEvent(UUID itemID, string name, object[] args)
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
Dictionary< uint, float > GetObjectScriptsExecutionTimes()
Get the execution times of all scripts in each object.
delegate void ScriptRemoved(UUID script)
Holds all the data required to execute a scripting event.
Definition: Helpers.cs:281
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
IScriptApi GetApi(UUID itemID, string name)
void SleepScript(UUID itemID, int delay)
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...