Main.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 OpenSim 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. using System;
  28. using System.Threading;
  29. using Gtk;
  30. namespace OpenGridServices.Manager
  31. {
  32. class MainClass
  33. {
  34. public static bool QuitReq=false;
  35. public static BlockingQueue<string> PendingOperations = new BlockingQueue<string>();
  36. private static Thread OperationsRunner;
  37. private static GridServerConnectionManager gridserverConn;
  38. private static MainWindow win;
  39. public static void DoMainLoop()
  40. {
  41. while(!QuitReq)
  42. {
  43. Application.RunIteration();
  44. }
  45. }
  46. public static void RunOperations()
  47. {
  48. string operation;
  49. string cmd;
  50. char[] sep = new char[1];
  51. sep[0]=' ';
  52. while(!QuitReq)
  53. {
  54. operation=PendingOperations.Dequeue();
  55. Console.WriteLine(operation);
  56. cmd = operation.Split(sep)[0];
  57. switch(cmd) {
  58. case "connect_to_gridserver":
  59. win.SetStatus("Connecting to grid server...");
  60. if(gridserverConn.Connect(operation.Split(sep)[1],operation.Split(sep)[2],operation.Split(sep)[3])) {
  61. win.SetStatus("Connected OK with session ID:" + gridserverConn.SessionID);
  62. win.SetGridServerConnected(true);
  63. Thread.Sleep(3000);
  64. win.SetStatus("Downloading region maps...");
  65. gridserverConn.DownloadMap();
  66. } else {
  67. win.SetStatus("Could not connect");
  68. }
  69. break;
  70. case "restart_gridserver":
  71. win.SetStatus("Restarting grid server...");
  72. if(gridserverConn.RestartServer()) {
  73. win.SetStatus("Restarted server OK");
  74. Thread.Sleep(3000);
  75. win.SetStatus("");
  76. } else {
  77. win.SetStatus("Error restarting grid server!!!");
  78. }
  79. break;
  80. case "shutdown_gridserver":
  81. win.SetStatus("Shutting down grid server...");
  82. if(gridserverConn.ShutdownServer()) {
  83. win.SetStatus("Grid server shutdown");
  84. win.SetGridServerConnected(false);
  85. Thread.Sleep(3000);
  86. win.SetStatus("");
  87. } else {
  88. win.SetStatus("Could not shutdown grid server!!!");
  89. }
  90. break;
  91. case "disconnect_gridserver":
  92. gridserverConn.DisconnectServer();
  93. win.SetGridServerConnected(false);
  94. break;
  95. }
  96. }
  97. }
  98. public static void Main (string[] args)
  99. {
  100. gridserverConn = new GridServerConnectionManager();
  101. Application.Init ();
  102. win = new MainWindow ();
  103. win.Show ();
  104. OperationsRunner = new Thread(new ThreadStart(RunOperations));
  105. OperationsRunner.IsBackground=true;
  106. OperationsRunner.Start();
  107. DoMainLoop();
  108. }
  109. }
  110. }