PageRenderTime 45ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/sipsorcery-servers/SIPSorcery.WatchTower/WatchTowerDaemon.cs

https://github.com/thecc4re/sipsorcery-mono
C# | 133 lines | 83 code | 12 blank | 38 comment | 10 complexity | ac9d244a4e13e38447d675be1568065b MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. // ============================================================================
  2. // FileName: WatchTowerDaemon.cs
  3. //
  4. // Description:
  5. // A daemon to configure and start the Call Dispatcher Server Agent.
  6. //
  7. // Author(s):
  8. // Aaron Clauson
  9. //
  10. // History:
  11. // 20 Nov 2009 Aaron Clauson Created.
  12. //
  13. // License:
  14. // This software is licensed under the BSD License http://www.opensource.org/licenses/bsd-license.php
  15. //
  16. // Copyright (c) 2009 Aaron Clauson (aaronc@blueface.ie), Blue Face Ltd, Dublin, Ireland (www.blueface.ie)
  17. // All rights reserved.
  18. //
  19. // Redistribution and use in source and binary forms, with or without modification, are permitted provided that
  20. // the following conditions are met:
  21. //
  22. // Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  23. // Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
  24. // disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of Blue Face Ltd.
  25. // nor the names of its contributors may be used to endorse or promote products derived from this software without specific
  26. // prior written permission.
  27. //
  28. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
  29. // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  30. // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  31. // OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  32. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  33. // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  34. // POSSIBILITY OF SUCH DAMAGE.
  35. // ============================================================================
  36. using System;
  37. using System.Collections.Generic;
  38. using System.IO;
  39. using System.Linq;
  40. using System.Net;
  41. using System.Text;
  42. using System.Xml;
  43. using SIPSorcery.Servers;
  44. using SIPSorcery.SIP;
  45. using SIPSorcery.SIP.App;
  46. using SIPSorcery.Sys;
  47. using log4net;
  48. namespace SIPSorcery.WatchTower
  49. {
  50. public class WatchTowerDaemon
  51. {
  52. private ILog logger = WatchTowerState.logger;
  53. private static int m_monitorEventLoopbackPort = WatchTowerState.MonitorLoopbackPort;
  54. private static string m_proxyAppServerEndPointsPath = WatchTowerState.AppServerEndPointsPath;
  55. private XmlNode m_sipAppServerWorkersNode = WatchTowerState.SIPAppServerWorkersNode;
  56. private XmlNode m_transportNode = WatchTowerState.SIPSocketsNode;
  57. private SIPMonitorEventWriter m_monitorEventWriter;
  58. private SIPTransport m_sipTransport;
  59. private SIPAppServerManager m_appServerManager;
  60. public WatchTowerDaemon()
  61. { }
  62. public void Start()
  63. {
  64. try
  65. {
  66. logger.Debug("WatchTowerDaemon starting...");
  67. // Send events from this process to the monitoring socket.
  68. if (m_monitorEventLoopbackPort != 0)
  69. {
  70. m_monitorEventWriter = new SIPMonitorEventWriter(m_monitorEventLoopbackPort);
  71. }
  72. List<SIPChannel> sipChannels = SIPTransportConfig.ParseSIPChannelsNode(m_transportNode);
  73. m_sipTransport = new SIPTransport(SIPDNSManager.ResolveSIPService, new SIPTransactionEngine());
  74. m_sipTransport.AddSIPChannel(sipChannels);
  75. if (m_sipAppServerWorkersNode != null)
  76. {
  77. m_appServerManager = new SIPAppServerManager(
  78. FireSIPMonitorEvent,
  79. m_sipTransport,
  80. m_sipAppServerWorkersNode,
  81. m_proxyAppServerEndPointsPath);
  82. }
  83. //m_sipTransport.SIPTransportRequestReceived += GotRequest;
  84. //m_sipTransport.SIPTransportResponseReceived += GotResponse;
  85. }
  86. catch (Exception excp)
  87. {
  88. logger.Error("Exception WatchTowerDaemon Start. " + excp.Message);
  89. }
  90. }
  91. public void Stop()
  92. {
  93. try
  94. {
  95. m_appServerManager.Stop();
  96. }
  97. catch (Exception excp)
  98. {
  99. logger.Error("Exception WatchTowerDaemon Stop. " + excp.Message);
  100. }
  101. }
  102. private void FireSIPMonitorEvent(SIPMonitorEvent sipMonitorEvent)
  103. {
  104. try
  105. {
  106. if (sipMonitorEvent != null && m_monitorEventWriter != null)
  107. {
  108. if (!(sipMonitorEvent is SIPMonitorConsoleEvent &&
  109. ((SIPMonitorConsoleEvent)sipMonitorEvent).EventType == SIPMonitorEventTypesEnum.SIPTransaction))
  110. {
  111. m_monitorEventWriter.Send(sipMonitorEvent);
  112. }
  113. }
  114. }
  115. catch (Exception excp)
  116. {
  117. logger.Error("Exception FireSIPMonitorEvent. " + excp.Message);
  118. }
  119. }
  120. }
  121. }