diff options
author | Charles Krinke | 2008-06-27 02:15:57 +0000 |
---|---|---|
committer | Charles Krinke | 2008-06-27 02:15:57 +0000 |
commit | ca8d1d57e1bbf49cb52abe81b3a7246dacbe9b03 (patch) | |
tree | 97f8cce96ea2e98b96b36e523c59361bf00f63b8 /OpenSim/Framework | |
parent | Mantis#1610. Thank you, Melanie for a patch that: (diff) | |
download | opensim-SC_OLD-ca8d1d57e1bbf49cb52abe81b3a7246dacbe9b03.zip opensim-SC_OLD-ca8d1d57e1bbf49cb52abe81b3a7246dacbe9b03.tar.gz opensim-SC_OLD-ca8d1d57e1bbf49cb52abe81b3a7246dacbe9b03.tar.bz2 opensim-SC_OLD-ca8d1d57e1bbf49cb52abe81b3a7246dacbe9b03.tar.xz |
Mantis#1591. Thank you graciously, Sempuki for a patch that:
Currently module loading is done ad-hoc. I propose creating a simple
loader class that leverages Mono.Addins (and perhaps the new .NET
addins when they become available in mono). Attached is a basic
patch for review that compiles into HEAD, but doesn't yet replace
any existing ad-hoc loaders.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/IAssetProvider.cs | 2 | ||||
-rw-r--r-- | OpenSim/Framework/IPlugin.cs | 18 | ||||
-rw-r--r-- | OpenSim/Framework/PluginLoader.cs | 115 | ||||
-rw-r--r-- | OpenSim/Framework/Servers/OSHttpRequestPump.cs | 2 |
4 files changed, 132 insertions, 5 deletions
diff --git a/OpenSim/Framework/IAssetProvider.cs b/OpenSim/Framework/IAssetProvider.cs index 5c02ff1..dcb79ea 100644 --- a/OpenSim/Framework/IAssetProvider.cs +++ b/OpenSim/Framework/IAssetProvider.cs | |||
@@ -38,4 +38,4 @@ namespace OpenSim.Framework | |||
38 | void CommitAssets(); // force a sync to the database | 38 | void CommitAssets(); // force a sync to the database |
39 | void Initialise(string connect); | 39 | void Initialise(string connect); |
40 | } | 40 | } |
41 | } \ No newline at end of file | 41 | } |
diff --git a/OpenSim/Framework/IPlugin.cs b/OpenSim/Framework/IPlugin.cs index 8a0b2b1..342918c 100644 --- a/OpenSim/Framework/IPlugin.cs +++ b/OpenSim/Framework/IPlugin.cs | |||
@@ -25,12 +25,24 @@ | |||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | ||
29 | |||
28 | namespace OpenSim.Framework | 30 | namespace OpenSim.Framework |
29 | { | 31 | { |
30 | /// <summary> | 32 | /// <summary> |
33 | /// Exception thrown if Initialise has been called, but failed. | ||
34 | /// </summary> | ||
35 | public class PluginNotInitialisedException : Exception | ||
36 | { | ||
37 | public PluginNotInitialisedException () : base() {} | ||
38 | public PluginNotInitialisedException (string msg) : base(msg) {} | ||
39 | public PluginNotInitialisedException (string msg, Exception e) : base(msg, e) {} | ||
40 | } | ||
41 | |||
42 | /// <summary> | ||
31 | /// This interface, describes a generic plugin | 43 | /// This interface, describes a generic plugin |
32 | /// </summary> | 44 | /// </summary> |
33 | public interface IPlugin | 45 | public interface IPlugin : System.IDisposable |
34 | { | 46 | { |
35 | /// <summary> | 47 | /// <summary> |
36 | /// Returns the plugin version | 48 | /// Returns the plugin version |
@@ -45,8 +57,8 @@ namespace OpenSim.Framework | |||
45 | string Name { get; } | 57 | string Name { get; } |
46 | 58 | ||
47 | /// <summary> | 59 | /// <summary> |
48 | /// Initialises the plugin (artificial constructor) | 60 | /// Default-initialises the plugin |
49 | /// </summary> | 61 | /// </summary> |
50 | void Initialise(); | 62 | void Initialise(); |
51 | } | 63 | } |
52 | } \ No newline at end of file | 64 | } |
diff --git a/OpenSim/Framework/PluginLoader.cs b/OpenSim/Framework/PluginLoader.cs new file mode 100644 index 0000000..26df3d1 --- /dev/null +++ b/OpenSim/Framework/PluginLoader.cs | |||
@@ -0,0 +1,115 @@ | |||
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 OpenSim 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.IO; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Reflection; | ||
32 | using log4net; | ||
33 | using Mono.Addins; | ||
34 | |||
35 | namespace OpenSim.Framework | ||
36 | { | ||
37 | public class PluginLoader <T> : IDisposable where T : IPlugin | ||
38 | { | ||
39 | private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
40 | private List<T> loaded = new List<T>(); | ||
41 | |||
42 | public PluginLoader (string dir) | ||
43 | { | ||
44 | AddPluginDir (dir); | ||
45 | } | ||
46 | |||
47 | public void AddPluginDir (string dir) | ||
48 | { | ||
49 | suppress_console_output_ (true); | ||
50 | AddinManager.Initialize (dir); | ||
51 | suppress_console_output_ (false); | ||
52 | } | ||
53 | |||
54 | public delegate void Initialiser (IPlugin p); | ||
55 | private void default_initialiser_ (IPlugin p) { p.Initialise(); } | ||
56 | |||
57 | public void Load (string extpoint) | ||
58 | { | ||
59 | Load (extpoint, default_initialiser_); | ||
60 | } | ||
61 | |||
62 | public void Load (string extpoint, Initialiser initialize) | ||
63 | { | ||
64 | AddinManager.Registry.Update (null); | ||
65 | |||
66 | ExtensionNodeList ns = AddinManager.GetExtensionNodes(extpoint); | ||
67 | foreach (TypeExtensionNode n in ns) | ||
68 | { | ||
69 | T p = (T) n.CreateInstance(); | ||
70 | initialize (p); | ||
71 | Plugins.Add (p); | ||
72 | |||
73 | log.Info("[PLUGINS]: Loading plugin " + n.Path + "/" + p.Name); | ||
74 | } | ||
75 | } | ||
76 | |||
77 | public List<T> Plugins | ||
78 | { | ||
79 | get { return loaded; } | ||
80 | } | ||
81 | |||
82 | public void Dispose () | ||
83 | { | ||
84 | foreach (T p in Plugins) | ||
85 | p.Dispose (); | ||
86 | } | ||
87 | |||
88 | public void ClearCache() | ||
89 | { | ||
90 | // The Mono addin manager (in Mono.Addins.dll version 0.2.0.0) occasionally seems to corrupt its addin cache | ||
91 | // Hence, as a temporary solution we'll remove it before each startup | ||
92 | if (Directory.Exists("addin-db-000")) | ||
93 | Directory.Delete("addin-db-000", true); | ||
94 | |||
95 | if (Directory.Exists("addin-db-001")) | ||
96 | Directory.Delete("addin-db-001", true); | ||
97 | } | ||
98 | |||
99 | private static TextWriter prev_console_; | ||
100 | public void suppress_console_output_ (bool save) | ||
101 | { | ||
102 | if (save) | ||
103 | { | ||
104 | prev_console_ = System.Console.Out; | ||
105 | System.Console.SetOut(new StreamWriter(Stream.Null)); | ||
106 | } | ||
107 | else | ||
108 | { | ||
109 | if (prev_console_ != null) | ||
110 | System.Console.SetOut(prev_console_); | ||
111 | } | ||
112 | } | ||
113 | |||
114 | } | ||
115 | } | ||
diff --git a/OpenSim/Framework/Servers/OSHttpRequestPump.cs b/OpenSim/Framework/Servers/OSHttpRequestPump.cs index 06e41e4..6214ab0 100644 --- a/OpenSim/Framework/Servers/OSHttpRequestPump.cs +++ b/OpenSim/Framework/Servers/OSHttpRequestPump.cs | |||
@@ -58,4 +58,4 @@ namespace OpenSim.Framework.Servers | |||
58 | return pumps; | 58 | return pumps; |
59 | } | 59 | } |
60 | } | 60 | } |
61 | } \ No newline at end of file | 61 | } |