diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/PluginLoader.cs | 228 |
1 files changed, 114 insertions, 114 deletions
diff --git a/OpenSim/Framework/PluginLoader.cs b/OpenSim/Framework/PluginLoader.cs index d0f9282..081a646 100644 --- a/OpenSim/Framework/PluginLoader.cs +++ b/OpenSim/Framework/PluginLoader.cs | |||
@@ -1,114 +1,114 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.IO; | 29 | using System.IO; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Reflection; | 31 | using System.Reflection; |
32 | using log4net; | 32 | using log4net; |
33 | using Mono.Addins; | 33 | using Mono.Addins; |
34 | 34 | ||
35 | namespace OpenSim.Framework | 35 | namespace OpenSim.Framework |
36 | { | 36 | { |
37 | public class PluginLoader <T> : IDisposable where T : IPlugin | 37 | public class PluginLoader <T> : IDisposable where T : IPlugin |
38 | { | 38 | { |
39 | private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 39 | private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
40 | private List<T> loaded = new List<T>(); | 40 | private List<T> loaded = new List<T>(); |
41 | 41 | ||
42 | public PluginLoader (string dir) | 42 | public PluginLoader (string dir) |
43 | { | 43 | { |
44 | AddPluginDir (dir); | 44 | AddPluginDir (dir); |
45 | } | 45 | } |
46 | 46 | ||
47 | public void AddPluginDir (string dir) | 47 | public void AddPluginDir (string dir) |
48 | { | 48 | { |
49 | suppress_console_output_ (true); | 49 | suppress_console_output_ (true); |
50 | AddinManager.Initialize (dir); | 50 | AddinManager.Initialize (dir); |
51 | AddinManager.Registry.Update (null); | 51 | AddinManager.Registry.Update (null); |
52 | suppress_console_output_ (false); | 52 | suppress_console_output_ (false); |
53 | } | 53 | } |
54 | 54 | ||
55 | public delegate void Initialiser (IPlugin p); | 55 | public delegate void Initialiser (IPlugin p); |
56 | private void default_initialiser_ (IPlugin p) { p.Initialise(); } | 56 | private void default_initialiser_ (IPlugin p) { p.Initialise(); } |
57 | 57 | ||
58 | public void Load (string extpoint) | 58 | public void Load (string extpoint) |
59 | { | 59 | { |
60 | Load (extpoint, default_initialiser_); | 60 | Load (extpoint, default_initialiser_); |
61 | } | 61 | } |
62 | 62 | ||
63 | public void Load (string extpoint, Initialiser initialize) | 63 | public void Load (string extpoint, Initialiser initialize) |
64 | { | 64 | { |
65 | ExtensionNodeList ns = AddinManager.GetExtensionNodes(extpoint); | 65 | ExtensionNodeList ns = AddinManager.GetExtensionNodes(extpoint); |
66 | foreach (TypeExtensionNode n in ns) | 66 | foreach (TypeExtensionNode n in ns) |
67 | { | 67 | { |
68 | T p = (T) n.CreateInstance(); | 68 | T p = (T) n.CreateInstance(); |
69 | initialize (p); | 69 | initialize (p); |
70 | Plugins.Add (p); | 70 | Plugins.Add (p); |
71 | 71 | ||
72 | log.Info("[PLUGINS]: Loading plugin " + n.Path + "/" + p.Name); | 72 | log.Info("[PLUGINS]: Loading plugin " + n.Path + "/" + p.Name); |
73 | } | 73 | } |
74 | } | 74 | } |
75 | 75 | ||
76 | public List<T> Plugins | 76 | public List<T> Plugins |
77 | { | 77 | { |
78 | get { return loaded; } | 78 | get { return loaded; } |
79 | } | 79 | } |
80 | 80 | ||
81 | public void Dispose () | 81 | public void Dispose () |
82 | { | 82 | { |
83 | foreach (T p in Plugins) | 83 | foreach (T p in Plugins) |
84 | p.Dispose (); | 84 | p.Dispose (); |
85 | } | 85 | } |
86 | 86 | ||
87 | public void ClearCache() | 87 | public void ClearCache() |
88 | { | 88 | { |
89 | // The Mono addin manager (in Mono.Addins.dll version 0.2.0.0) occasionally seems to corrupt its addin cache | 89 | // The Mono addin manager (in Mono.Addins.dll version 0.2.0.0) occasionally seems to corrupt its addin cache |
90 | // Hence, as a temporary solution we'll remove it before each startup | 90 | // Hence, as a temporary solution we'll remove it before each startup |
91 | if (Directory.Exists("addin-db-000")) | 91 | if (Directory.Exists("addin-db-000")) |
92 | Directory.Delete("addin-db-000", true); | 92 | Directory.Delete("addin-db-000", true); |
93 | 93 | ||
94 | if (Directory.Exists("addin-db-001")) | 94 | if (Directory.Exists("addin-db-001")) |
95 | Directory.Delete("addin-db-001", true); | 95 | Directory.Delete("addin-db-001", true); |
96 | } | 96 | } |
97 | 97 | ||
98 | private static TextWriter prev_console_; | 98 | private static TextWriter prev_console_; |
99 | public void suppress_console_output_ (bool save) | 99 | public void suppress_console_output_ (bool save) |
100 | { | 100 | { |
101 | if (save) | 101 | if (save) |
102 | { | 102 | { |
103 | prev_console_ = System.Console.Out; | 103 | prev_console_ = System.Console.Out; |
104 | System.Console.SetOut(new StreamWriter(Stream.Null)); | 104 | System.Console.SetOut(new StreamWriter(Stream.Null)); |
105 | } | 105 | } |
106 | else | 106 | else |
107 | { | 107 | { |
108 | if (prev_console_ != null) | 108 | if (prev_console_ != null) |
109 | System.Console.SetOut(prev_console_); | 109 | System.Console.SetOut(prev_console_); |
110 | } | 110 | } |
111 | } | 111 | } |
112 | 112 | ||
113 | } | 113 | } |
114 | } | 114 | } |