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.cs144
1 files changed, 144 insertions, 0 deletions
diff --git a/OpenSim/Server/Base/ServerUtils.cs b/OpenSim/Server/Base/ServerUtils.cs
index 42c82cf..6c6af62 100644
--- a/OpenSim/Server/Base/ServerUtils.cs
+++ b/OpenSim/Server/Base/ServerUtils.cs
@@ -33,11 +33,118 @@ 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 }
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
41 public static class ServerUtils 148 public static class ServerUtils
42 { 149 {
43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 150 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@@ -333,5 +440,42 @@ namespace OpenSim.Server.Base
333 440
334 return ret; 441 return ret;
335 } 442 }
443
444 public static IConfig GetConfig(string configFile, string configName)
445 {
446 IConfig config;
447
448 if (File.Exists(configFile))
449 {
450 IConfigSource configsource = new IniConfigSource(configFile);
451 config = configsource.Configs[configName];
452 }
453 else
454 config = null;
455
456 return config;
457 }
458
459 public static IConfigSource LoadInitialConfig(string url)
460 {
461 IConfigSource source = new XmlConfigSource();
462 m_log.InfoFormat("[CONFIG]: {0} is a http:// URI, fetching ...", url);
463
464 // The ini file path is a http URI
465 // Try to read it
466 try
467 {
468 XmlReader r = XmlReader.Create(url);
469 IConfigSource cs = new XmlConfigSource(r);
470 source.Merge(cs);
471 }
472 catch (Exception e)
473 {
474 m_log.FatalFormat("[CONFIG]: Exception reading config from URI {0}\n" + e.ToString(), url);
475 Environment.Exit(1);
476 }
477
478 return source;
479 }
336 } 480 }
337} 481}