diff options
Diffstat (limited to 'OpenSim/Server/Base/ServerUtils.cs')
-rw-r--r-- | OpenSim/Server/Base/ServerUtils.cs | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/OpenSim/Server/Base/ServerUtils.cs b/OpenSim/Server/Base/ServerUtils.cs index 4a696c4..6c6af62 100644 --- a/OpenSim/Server/Base/ServerUtils.cs +++ b/OpenSim/Server/Base/ServerUtils.cs | |||
@@ -36,9 +36,115 @@ using log4net; | |||
36 | using Nini.Config; | 36 | using Nini.Config; |
37 | using OpenSim.Framework; | 37 | using OpenSim.Framework; |
38 | using OpenMetaverse; | 38 | using OpenMetaverse; |
39 | using Mono.Addins; | ||
40 | using OpenSim.Framework.Servers.HttpServer; | ||
41 | using OpenSim.Framework.Servers; | ||
39 | 42 | ||
43 | |||
44 | [assembly:AddinRoot("Robust", "0.1")] | ||
40 | namespace OpenSim.Server.Base | 45 | namespace OpenSim.Server.Base |
41 | { | 46 | { |
47 | [TypeExtensionPoint(Path="/Robust/Connector", Name="RobustConnector")] | ||
48 | public interface IRobustConnector | ||
49 | { | ||
50 | string ConfigName | ||
51 | { | ||
52 | get; | ||
53 | } | ||
54 | |||
55 | bool Enabled | ||
56 | { | ||
57 | get; | ||
58 | } | ||
59 | |||
60 | string PluginPath | ||
61 | { | ||
62 | get; | ||
63 | set; | ||
64 | } | ||
65 | |||
66 | uint Configure(IConfigSource config); | ||
67 | void Initialize(IHttpServer server); | ||
68 | } | ||
69 | |||
70 | public class PluginLoader | ||
71 | { | ||
72 | static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
73 | |||
74 | public AddinRegistry Registry | ||
75 | { | ||
76 | get; | ||
77 | private set; | ||
78 | } | ||
79 | |||
80 | public IConfigSource Config | ||
81 | { | ||
82 | get; | ||
83 | private set; | ||
84 | } | ||
85 | |||
86 | public PluginLoader(IConfigSource config, string registryPath) | ||
87 | { | ||
88 | Config = config; | ||
89 | |||
90 | Registry = new AddinRegistry(registryPath, "."); | ||
91 | AddinManager.Initialize(registryPath); | ||
92 | AddinManager.Registry.Update(); | ||
93 | CommandManager commandmanager = new CommandManager(Registry); | ||
94 | AddinManager.AddExtensionNodeHandler("/Robust/Connector", OnExtensionChanged); | ||
95 | } | ||
96 | |||
97 | private void OnExtensionChanged(object s, ExtensionNodeEventArgs args) | ||
98 | { | ||
99 | IRobustConnector connector = (IRobustConnector)args.ExtensionObject; | ||
100 | |||
101 | Addin a = Registry.GetAddin(args.ExtensionNode.Addin.Id); | ||
102 | m_log.InfoFormat("[SERVER]: Extension Change: {0}/{1}", Registry.DefaultAddinsFolder, a.Name.Replace(',', '.')); | ||
103 | |||
104 | switch(args.Change) | ||
105 | { | ||
106 | case ExtensionChange.Add: | ||
107 | connector.PluginPath = String.Format("{0}/{1}", Registry.DefaultAddinsFolder, a.Name.Replace(',', '.')); | ||
108 | LoadPlugin(connector); | ||
109 | break; | ||
110 | case ExtensionChange.Remove: | ||
111 | UnloadPlugin(connector); | ||
112 | break; | ||
113 | } | ||
114 | } | ||
115 | |||
116 | private void LoadPlugin(IRobustConnector connector) | ||
117 | { | ||
118 | IHttpServer server = null; | ||
119 | uint port = connector.Configure(Config); | ||
120 | |||
121 | if(connector.Enabled) | ||
122 | { | ||
123 | server = GetServer(connector, port); | ||
124 | m_log.InfoFormat("[SERVER]: Path is {0}", connector.PluginPath); | ||
125 | connector.Initialize(server); | ||
126 | } | ||
127 | else | ||
128 | m_log.InfoFormat("[SERVER]: {0} Disabled.", connector.ConfigName); | ||
129 | } | ||
130 | |||
131 | private void UnloadPlugin(IRobustConnector connector) | ||
132 | { | ||
133 | } | ||
134 | |||
135 | private IHttpServer GetServer(IRobustConnector connector, uint port) | ||
136 | { | ||
137 | IHttpServer server; | ||
138 | |||
139 | if(port != 0) | ||
140 | server = MainServer.GetHttpServer(port); | ||
141 | else | ||
142 | server = MainServer.Instance; | ||
143 | |||
144 | return server; | ||
145 | } | ||
146 | } | ||
147 | |||
42 | public static class ServerUtils | 148 | public static class ServerUtils |
43 | { | 149 | { |
44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 150 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |