PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/tools/e133/E133HealthCheckedConnection.cpp

https://code.google.com/
C++ | 68 lines | 28 code | 7 blank | 33 comment | 2 complexity | 214af443fea57bde74606f3bd20b33b2 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License as published by
  4. * the Free Software Foundation; either version 2 of the License, or
  5. * (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU Library General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. *
  16. * E133HealthCheckedConnection.cpp
  17. * Copyright (C) 2012 Simon Newton
  18. */
  19. #include <ola/Logging.h>
  20. #include "plugins/e131/e131/RootSender.h"
  21. #include "tools/e133/E133HealthCheckedConnection.h"
  22. /**
  23. * Create a new E1.33 Health Checked Connection.
  24. * @param transport the transport to send heartbeats on
  25. * @param sender the RootSender to use when sending heartbeats
  26. * @param on_timeout the callback to run when the heartbeats don't arrive
  27. * @param scheduler A SchedulerInterface used to control the timers
  28. * @param vector the vector to use in the RootPDUs
  29. * @param heartbeat_interval the TimeInterval between heartbeats
  30. */
  31. E133HealthCheckedConnection::E133HealthCheckedConnection(
  32. ola::plugin::e131::OutgoingStreamTransport *transport,
  33. ola::plugin::e131::RootSender *sender,
  34. ola::SingleUseCallback0<void> *on_timeout,
  35. ola::thread::SchedulerInterface *scheduler,
  36. unsigned int vector,
  37. const ola::TimeInterval heartbeat_interval)
  38. : HealthCheckedConnection(scheduler, heartbeat_interval),
  39. m_in_timeout(false),
  40. m_vector(vector),
  41. m_transport(transport),
  42. m_sender(sender),
  43. m_on_timeout(on_timeout) {
  44. }
  45. /**
  46. * Send a E1.33 heartbeat
  47. */
  48. void E133HealthCheckedConnection::SendHeartbeat() {
  49. OLA_INFO << "Sending heartbeat";
  50. if (!m_sender->SendEmpty(m_vector, m_transport))
  51. OLA_WARN << "Failed to send heartbeat";
  52. }
  53. /**
  54. * Called if the connection is declared dead
  55. */
  56. void E133HealthCheckedConnection::HeartbeatTimeout() {
  57. OLA_INFO << "TCP connection heartbeat timeout";
  58. m_in_timeout = true;
  59. if (m_on_timeout)
  60. m_on_timeout->Run();
  61. }