Main.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. {
  59. case "connect_to_gridserver":
  60. win.SetStatus("Connecting to grid server...");
  61. if (gridserverConn.Connect(operation.Split(sep)[1], operation.Split(sep)[2], operation.Split(sep)[3]))
  62. {
  63. win.SetStatus("Connected OK with session ID:" + gridserverConn.SessionID);
  64. win.SetGridServerConnected(true);
  65. Thread.Sleep(3000);
  66. win.SetStatus("Downloading region maps...");
  67. gridserverConn.DownloadMap();
  68. }
  69. else
  70. {
  71. win.SetStatus("Could not connect");
  72. }
  73. break;
  74. case "restart_gridserver":
  75. win.SetStatus("Restarting grid server...");
  76. if (gridserverConn.RestartServer())
  77. {
  78. win.SetStatus("Restarted server OK");
  79. Thread.Sleep(3000);
  80. win.SetStatus("");
  81. }
  82. else
  83. {
  84. win.SetStatus("Error restarting grid server!!!");
  85. }
  86. break;
  87. case "shutdown_gridserver":
  88. win.SetStatus("Shutting down grid server...");
  89. if (gridserverConn.ShutdownServer())
  90. {
  91. win.SetStatus("Grid server shutdown");
  92. win.SetGridServerConnected(false);
  93. Thread.Sleep(3000);
  94. win.SetStatus("");
  95. }
  96. else
  97. {
  98. win.SetStatus("Could not shutdown grid server!!!");
  99. }
  100. break;
  101. case "disconnect_gridserver":
  102. gridserverConn.DisconnectServer();
  103. win.SetGridServerConnected(false);
  104. break;
  105. }
  106. }
  107. }
  108. public static void Main (string[] args)
  109. {
  110. gridserverConn = new GridServerConnectionManager();
  111. Application.Init ();
  112. win = new MainWindow ();
  113. win.Show ();
  114. OperationsRunner = new Thread(new ThreadStart(RunOperations));
  115. OperationsRunner.IsBackground=true;
  116. OperationsRunner.Start();
  117. DoMainLoop();
  118. }
  119. }
  120. }