StreamPassInterface.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * @file StreamPassInterface.c
  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. #include <flow/StreamPassInterface.h>
  23. void _StreamPassInterface_job_operation (StreamPassInterface *i)
  24. {
  25. ASSERT(i->d_user_busy)
  26. ASSERT(i->buf_len > 0)
  27. ASSERT(i->handler_done)
  28. DebugObject_Access(&i->d_obj);
  29. #ifndef NDEBUG
  30. DebugIn_AmOut(&i->d_in_operation);
  31. DebugIn_AmOut(&i->d_in_done);
  32. #endif
  33. // call operation handler
  34. #ifndef NDEBUG
  35. DebugIn_GoIn(&i->d_in_operation);
  36. DEAD_ENTER(i->d_dead)
  37. #endif
  38. i->handler_operation(i->user_provider, i->buf, i->buf_len);
  39. #ifndef NDEBUG
  40. if (DEAD_LEAVE(i->d_dead)) {
  41. return;
  42. }
  43. DebugIn_GoOut(&i->d_in_operation);
  44. #endif
  45. }
  46. void _StreamPassInterface_job_done (StreamPassInterface *i)
  47. {
  48. ASSERT(i->d_user_busy)
  49. ASSERT(i->buf_len > 0)
  50. ASSERT(i->done_len > 0)
  51. ASSERT(i->done_len <= i->buf_len)
  52. ASSERT(i->handler_done)
  53. DebugObject_Access(&i->d_obj);
  54. #ifndef NDEBUG
  55. DebugIn_AmOut(&i->d_in_operation);
  56. DebugIn_AmOut(&i->d_in_done);
  57. #endif
  58. #ifndef NDEBUG
  59. i->d_user_busy = 0;
  60. #endif
  61. // call done handler
  62. #ifndef NDEBUG
  63. DebugIn_GoIn(&i->d_in_done);
  64. DEAD_ENTER(i->d_dead)
  65. #endif
  66. i->handler_done(i->user_user, i->done_len);
  67. #ifndef NDEBUG
  68. if (DEAD_LEAVE(i->d_dead)) {
  69. return;
  70. }
  71. DebugIn_GoOut(&i->d_in_done);
  72. #endif
  73. }