diff options
Diffstat (limited to 'OpenSim/Tools/OpenSim.GridLaunch/Program.cs')
-rw-r--r-- | OpenSim/Tools/OpenSim.GridLaunch/Program.cs | 245 |
1 files changed, 0 insertions, 245 deletions
diff --git a/OpenSim/Tools/OpenSim.GridLaunch/Program.cs b/OpenSim/Tools/OpenSim.GridLaunch/Program.cs deleted file mode 100644 index ecfb0af..0000000 --- a/OpenSim/Tools/OpenSim.GridLaunch/Program.cs +++ /dev/null | |||
@@ -1,245 +0,0 @@ | |||
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 OpenSimulator 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.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Reflection; | ||
32 | using System.Threading; | ||
33 | using log4net; | ||
34 | using log4net.Appender; | ||
35 | using log4net.Repository.Hierarchy; | ||
36 | using OpenSim.GridLaunch.GUI; | ||
37 | using OpenSim.GridLaunch.GUI.Network; | ||
38 | |||
39 | namespace OpenSim.GridLaunch | ||
40 | { | ||
41 | class Program | ||
42 | { | ||
43 | public static readonly string ConfigFile = "OpenSim.GridLaunch.ini"; | ||
44 | internal static Dictionary<string, AppExecutor> AppList = new Dictionary<string, AppExecutor>(); | ||
45 | private static readonly int delayBetweenExecuteSeconds = 10; | ||
46 | //private static readonly int consoleReadIntervalMilliseconds = 50; | ||
47 | ////private static readonly Timer readTimer = new Timer(readConsole, null, Timeout.Infinite, Timeout.Infinite); | ||
48 | //private static Thread timerThread; | ||
49 | //private static object timerThreadLock = new object(); | ||
50 | private static IGUI GUIModule; | ||
51 | private static string GUIModuleName = ""; | ||
52 | public static readonly CommandProcessor Command = new CommandProcessor(); | ||
53 | public static readonly Settings Settings = new Settings(); | ||
54 | |||
55 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
56 | |||
57 | public delegate void AppConsoleOutputDelegate(string App, string Text); | ||
58 | public static event AppConsoleOutputDelegate AppConsoleOutput; | ||
59 | public delegate void AppConsoleErrorDelegate(string App, string Text); | ||
60 | public static event AppConsoleErrorDelegate AppConsoleError; | ||
61 | public delegate void AppCreatedDelegate(string App); | ||
62 | public static event AppCreatedDelegate AppCreated; | ||
63 | public delegate void AppRemovedDelegate(string App); | ||
64 | public static event AppRemovedDelegate AppRemoved; | ||
65 | |||
66 | internal static void FireAppConsoleOutput(string App, string Text) | ||
67 | { | ||
68 | if (AppConsoleOutput != null) | ||
69 | AppConsoleOutput(App, Text); | ||
70 | } | ||
71 | internal static void FireAppConsoleError(string App, string Text) | ||
72 | { | ||
73 | if (AppConsoleError != null) | ||
74 | AppConsoleError(App, Text); | ||
75 | } | ||
76 | |||
77 | |||
78 | private static readonly object startStopLock = new object(); | ||
79 | |||
80 | public static string Name { get { return "OpenSim Grid executor"; } } | ||
81 | |||
82 | #region Start/Shutdown | ||
83 | static void Main(string[] args) | ||
84 | { | ||
85 | log4net.Config.XmlConfigurator.Configure(); | ||
86 | |||
87 | // Startup | ||
88 | m_log.Info(Name); | ||
89 | m_log.Info(new string('-', Name.Length)); | ||
90 | |||
91 | // Read settings | ||
92 | Settings.LoadConfig(ConfigFile); | ||
93 | // Command line arguments override settings | ||
94 | Settings.ParseCommandArguments(args); | ||
95 | |||
96 | // Start GUI module | ||
97 | StartGUIModule(); | ||
98 | |||
99 | // Start the processes | ||
100 | ThreadPool.QueueUserWorkItem(startProcesses); | ||
101 | |||
102 | // Hand over thread control to whatever GUI module | ||
103 | GUIModule.StartGUI(); | ||
104 | |||
105 | // GUI module returned, we are done | ||
106 | Shutdown(); | ||
107 | |||
108 | } | ||
109 | |||
110 | private static void StartGUIModule() | ||
111 | { | ||
112 | // Create GUI module | ||
113 | GUIModuleName = Settings["GUI"]; | ||
114 | |||
115 | switch (GUIModuleName.ToLower()) | ||
116 | { | ||
117 | case "winform": | ||
118 | GUIModuleName = "WinForm"; | ||
119 | GUIModule = new GUI.WinForm.ProcessPanel(); | ||
120 | break; | ||
121 | case "service": | ||
122 | GUIModuleName = "Service"; | ||
123 | GUIModule = new Service(); | ||
124 | break; | ||
125 | case "tcpd": | ||
126 | GUIModuleName = "TCPD"; | ||
127 | GUIModule = new TCPD(); | ||
128 | break; | ||
129 | case "console": | ||
130 | default: | ||
131 | GUIModuleName = "Console"; | ||
132 | GUIModule = new GUI.Console.Console(); | ||
133 | break; | ||
134 | } | ||
135 | m_log.Info("GUI type: " + GUIModuleName); | ||
136 | |||
137 | } | ||
138 | |||
139 | internal static void Shutdown() | ||
140 | { | ||
141 | // Stop the processes | ||
142 | stopProcesses(); | ||
143 | |||
144 | lock (startStopLock) | ||
145 | { | ||
146 | // Stop GUI module | ||
147 | if (GUIModule != null) | ||
148 | { | ||
149 | GUIModule.StopGUI(); | ||
150 | GUIModule = null; | ||
151 | } | ||
152 | } | ||
153 | } | ||
154 | |||
155 | internal static void SafeDisposeOf(object obj) | ||
156 | { | ||
157 | IDisposable o = obj as IDisposable; | ||
158 | try | ||
159 | { | ||
160 | if (o != null) | ||
161 | o.Dispose(); | ||
162 | } | ||
163 | catch { } | ||
164 | } | ||
165 | #endregion | ||
166 | |||
167 | #region Start / Stop applications | ||
168 | private static void startProcesses(Object stateInfo) | ||
169 | { | ||
170 | // Stop before starting | ||
171 | stopProcesses(); | ||
172 | |||
173 | // Start console read timer | ||
174 | //timer_Start(); | ||
175 | |||
176 | // Start the applications | ||
177 | foreach (string file in new ArrayList(Settings.Components.Keys)) | ||
178 | { | ||
179 | // Is this file marked for startup? | ||
180 | if (Settings.Components[file]) | ||
181 | { | ||
182 | AppExecutor app = new AppExecutor(file); | ||
183 | app.Start(); | ||
184 | AppList.Add(file, app); | ||
185 | if (AppCreated != null) | ||
186 | AppCreated(app.File); | ||
187 | System.Threading.Thread.Sleep(1000*delayBetweenExecuteSeconds); | ||
188 | } | ||
189 | } | ||
190 | } | ||
191 | |||
192 | private static void stopProcesses() | ||
193 | { | ||
194 | // Stop timer | ||
195 | //timer_Stop(); | ||
196 | |||
197 | // Lock so we don't collide with any timer still executing on AppList | ||
198 | lock (AppList) | ||
199 | { | ||
200 | // Start the applications | ||
201 | foreach (AppExecutor app in AppList.Values) | ||
202 | { | ||
203 | try | ||
204 | { | ||
205 | m_log.Info("Stopping: " + app.File); | ||
206 | app.Stop(); | ||
207 | } | ||
208 | catch (Exception ex) | ||
209 | { | ||
210 | m_log.ErrorFormat("Exception while stopping \"{0}\": {1}", app.File, ex.ToString()); | ||
211 | } | ||
212 | finally | ||
213 | { | ||
214 | if (AppRemoved != null) | ||
215 | AppRemoved(app.File); | ||
216 | app.Dispose(); | ||
217 | } | ||
218 | |||
219 | } | ||
220 | AppList.Clear(); | ||
221 | } | ||
222 | } | ||
223 | #endregion | ||
224 | |||
225 | public static void Write(string App, string Text) | ||
226 | { | ||
227 | // Check if it is a commands | ||
228 | bool isCommand = Command.Process(App, Text); | ||
229 | |||
230 | // Write to stdInput of app | ||
231 | if (!isCommand && AppList.ContainsKey(App)) | ||
232 | AppList[App].Write(Text); | ||
233 | } | ||
234 | |||
235 | public static void WriteLine(string App, string Text) | ||
236 | { | ||
237 | // Check if it is a commands | ||
238 | bool isCommand = Command.Process(App, Text); | ||
239 | |||
240 | // Write to stdInput of app | ||
241 | if (!isCommand && AppList.ContainsKey(App)) | ||
242 | AppList[App].WriteLine(Text); | ||
243 | } | ||
244 | } | ||
245 | } | ||