aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Base/ServerUtils.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Server/Base/ServerUtils.cs')
-rw-r--r--OpenSim/Server/Base/ServerUtils.cs163
1 files changed, 163 insertions, 0 deletions
diff --git a/OpenSim/Server/Base/ServerUtils.cs b/OpenSim/Server/Base/ServerUtils.cs
index 42c82cf..31b0446 100644
--- a/OpenSim/Server/Base/ServerUtils.cs
+++ b/OpenSim/Server/Base/ServerUtils.cs
@@ -33,11 +33,137 @@ using System.Xml.Serialization;
33using System.Text; 33using System.Text;
34using System.Collections.Generic; 34using System.Collections.Generic;
35using log4net; 35using log4net;
36using Nini.Config;
36using OpenSim.Framework; 37using OpenSim.Framework;
37using OpenMetaverse; 38using OpenMetaverse;
39using Mono.Addins;
40using OpenSim.Framework.Servers.HttpServer;
41using OpenSim.Framework.Servers;
38 42
43
44[assembly:AddinRoot("Robust", "0.1")]
39namespace OpenSim.Server.Base 45namespace OpenSim.Server.Base
40{ 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 void Unload();
69 }
70
71 public class PluginLoader
72 {
73 static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
74
75 public AddinRegistry Registry
76 {
77 get;
78 private set;
79 }
80
81 public IConfigSource Config
82 {
83 get;
84 private set;
85 }
86
87 public PluginLoader(IConfigSource config, string registryPath)
88 {
89 Config = config;
90
91 Registry = new AddinRegistry(registryPath, ".");
92 AddinManager.Initialize(registryPath);
93 AddinManager.Registry.Update();
94 CommandManager commandmanager = new CommandManager(Registry);
95 AddinManager.AddExtensionNodeHandler("/Robust/Connector", OnExtensionChanged);
96 }
97
98 private void OnExtensionChanged(object s, ExtensionNodeEventArgs args)
99 {
100 IRobustConnector connector = (IRobustConnector)args.ExtensionObject;
101 Addin a = Registry.GetAddin(args.ExtensionNode.Addin.Id);
102
103 if(a == null)
104 {
105 Registry.Rebuild(null);
106 a = Registry.GetAddin(args.ExtensionNode.Addin.Id);
107 }
108
109 switch(args.Change)
110 {
111 case ExtensionChange.Add:
112 if (a.AddinFile.Contains(Registry.DefaultAddinsFolder))
113 {
114 m_log.InfoFormat("[SERVER]: Adding {0} from registry", a.Name);
115 connector.PluginPath = String.Format("{0}/{1}", Registry.DefaultAddinsFolder, a.Name.Replace(',', '.'));
116 }
117 else
118 {
119 m_log.InfoFormat("[SERVER]: Adding {0} from ./bin", a.Name);
120 connector.PluginPath = a.AddinFile;
121 }
122 LoadPlugin(connector);
123 break;
124 case ExtensionChange.Remove:
125 m_log.InfoFormat("[SERVER]: Removing {0}", a.Name);
126 UnloadPlugin(connector);
127 break;
128 }
129 }
130
131 private void LoadPlugin(IRobustConnector connector)
132 {
133 IHttpServer server = null;
134 uint port = connector.Configure(Config);
135
136 if(connector.Enabled)
137 {
138 server = GetServer(connector, port);
139 connector.Initialize(server);
140 }
141 else
142 {
143 m_log.InfoFormat("[SERVER]: {0} Disabled.", connector.ConfigName);
144 }
145 }
146
147 private void UnloadPlugin(IRobustConnector connector)
148 {
149 m_log.InfoFormat("[Server]: Unloading {0}", connector.ConfigName);
150
151 connector.Unload();
152 }
153
154 private IHttpServer GetServer(IRobustConnector connector, uint port)
155 {
156 IHttpServer server;
157
158 if(port != 0)
159 server = MainServer.GetHttpServer(port);
160 else
161 server = MainServer.Instance;
162
163 return server;
164 }
165 }
166
41 public static class ServerUtils 167 public static class ServerUtils
42 { 168 {
43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 169 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@@ -333,5 +459,42 @@ namespace OpenSim.Server.Base
333 459
334 return ret; 460 return ret;
335 } 461 }
462
463 public static IConfig GetConfig(string configFile, string configName)
464 {
465 IConfig config;
466
467 if (File.Exists(configFile))
468 {
469 IConfigSource configsource = new IniConfigSource(configFile);
470 config = configsource.Configs[configName];
471 }
472 else
473 config = null;
474
475 return config;
476 }
477
478 public static IConfigSource LoadInitialConfig(string url)
479 {
480 IConfigSource source = new XmlConfigSource();
481 m_log.InfoFormat("[CONFIG]: {0} is a http:// URI, fetching ...", url);
482
483 // The ini file path is a http URI
484 // Try to read it
485 try
486 {
487 XmlReader r = XmlReader.Create(url);
488 IConfigSource cs = new XmlConfigSource(r);
489 source.Merge(cs);
490 }
491 catch (Exception e)
492 {
493 m_log.FatalFormat("[CONFIG]: Exception reading config from URI {0}\n" + e.ToString(), url);
494 Environment.Exit(1);
495 }
496
497 return source;
498 }
336 } 499 }
337} 500}