PacketPassInactivityMonitor.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /**
  2. * @file PacketPassInactivityMonitor.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * This file is part of BadVPN.
  8. *
  9. * BadVPN is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * BadVPN is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. * @section DESCRIPTION
  23. *
  24. * A {@link PacketPassInterface} layer for detecting inactivity.
  25. */
  26. #ifndef BADVPN_FLOW_PACKETPASSINACTIVITYMONITOR_H
  27. #define BADVPN_FLOW_PACKETPASSINACTIVITYMONITOR_H
  28. #include <system/DebugObject.h>
  29. #include <system/BReactor.h>
  30. #include <flow/PacketPassInterface.h>
  31. /**
  32. * Handler function invoked when inactivity is detected.
  33. * It is guaranteed that the interfaces are in not sending state.
  34. *
  35. * @param user value given to {@link PacketPassInactivityMonitor_Init}
  36. */
  37. typedef void (*PacketPassInactivityMonitor_handler) (void *user);
  38. /**
  39. * A {@link PacketPassInterface} layer for detecting inactivity.
  40. * It reports inactivity to a user provided handler function.
  41. *
  42. * The object behaves like that:
  43. * ("timer set" means started with the given timeout whether if was running or not,
  44. * "timer unset" means stopped if it was running)
  45. * - There is a timer.
  46. * - The timer is set when the object is initialized.
  47. * - When the input calls Send, the call is passed on to the output.
  48. * If the output accepted the packet, the timer is set. If the output
  49. * blocked the packet, the timer is unset.
  50. * - When the output calls Done, the timer is set, and the call is
  51. * passed on to the input.
  52. * - When the input calls Cancel, the timer is set, and the call is
  53. * passed on to the output.
  54. * - When the timer expires, the timer is set, ant the user's handler
  55. * function is invoked.
  56. */
  57. typedef struct {
  58. DebugObject d_obj;
  59. PacketPassInterface *output;
  60. BReactor *reactor;
  61. PacketPassInactivityMonitor_handler handler;
  62. void *user;
  63. PacketPassInterface input;
  64. BTimer timer;
  65. } PacketPassInactivityMonitor;
  66. /**
  67. * Initializes the object.
  68. * See {@link PacketPassInactivityMonitor} for details.
  69. *
  70. * @param o the object
  71. * @param output output interface
  72. * @param reactor reactor we live in
  73. * @param interval timer value in milliseconds
  74. * @param handler handler function for reporting inactivity, or NULL to disable
  75. * @param user value passed to handler functions
  76. */
  77. void PacketPassInactivityMonitor_Init (PacketPassInactivityMonitor *o, PacketPassInterface *output, BReactor *reactor, btime_t interval, PacketPassInactivityMonitor_handler handler, void *user);
  78. /**
  79. * Frees the object.
  80. *
  81. * @param o the object
  82. */
  83. void PacketPassInactivityMonitor_Free (PacketPassInactivityMonitor *o);
  84. /**
  85. * Returns the input interface.
  86. * The MTU of the interface will be the same as of the output interface.
  87. * The interface supports cancel functionality if the output interface supports it.
  88. *
  89. * @param o the object
  90. * @return input interface
  91. */
  92. PacketPassInterface * PacketPassInactivityMonitor_GetInput (PacketPassInactivityMonitor *o);
  93. /**
  94. * Sets or removes the inactivity handler.
  95. *
  96. * @param o the object
  97. * @param handler handler function for reporting inactivity, or NULL to disable
  98. * @param user value passed to handler functions
  99. */
  100. void PacketPassInactivityMonitor_SetHandler (PacketPassInactivityMonitor *o, PacketPassInactivityMonitor_handler handler, void *user);
  101. /**
  102. * Sets the timer to expire immediately in order to force an inactivity report.
  103. *
  104. * @param o the object
  105. */
  106. void PacketPassInactivityMonitor_Force (PacketPassInactivityMonitor *o);
  107. #endif