jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.9KB

  1. /*
  2. Copyright (C) 2010 Devin Anderson
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as published by
  5. the Free Software Foundation; either version 2.1 of the License, or
  6. (at your option) any later version.
  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 Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #ifndef __JackEventAsyncWaitQueue__
  16. #define __JackEventAsyncWaitQueue__
  17. #include "JackEventAsyncQueue.h"
  18. namespace Jack {
  19. /**
  20. * This is an asynchronous wait queue that allows a thread to wait for a
  21. * message, either indefinitely or for a specified time. This is one
  22. * example of a way that the `JackEventAsyncQueue` class can be extended so
  23. * that process threads can interact with non-process threads to send
  24. * events.
  25. *
  26. * XXX: As of right now, this code hasn't been tested. Also, note the
  27. * warning in the JackEventAsyncWaitQueue.cpp about semaphore wait
  28. * resolution.
  29. */
  30. class SERVER_EXPORT JackEventAsyncWaitQueue: public JackEventAsyncQueue {
  31. private:
  32. JackSynchro semaphore;
  33. public:
  34. using JackEventAsyncQueue::EnqueueEvent;
  35. /**
  36. * Creates a new asynchronous wait message queue. The queue can
  37. * store up to `max_messages` messages and up to `max_bytes` of
  38. * messagea data before it starts rejecting messages.
  39. */
  40. JackEventAsyncWaitQueue(size_t max_bytes=4096,
  41. size_t max_messages=1024);
  42. ~JackEventAsyncWaitQueue();
  43. /**
  44. * Dequeues and returns a MIDI event. Returns '0' if there are no MIDI
  45. * events available right now.
  46. */
  47. jack_event_t *
  48. DequeueEvent();
  49. /**
  50. * Waits a specified time for an event to be available, or
  51. * indefinitely if the time is negative. Returns the event, or
  52. * '0' if time runs out and no event is available.
  53. */
  54. jack_event_t *
  55. DequeueEvent(long usecs);
  56. /**
  57. * Waits until the specified frame for an event to be available.
  58. * Returns the event, or '0' if time runs out and no event is
  59. * available.
  60. */
  61. jack_event_t *
  62. DequeueEvent(jack_nframes_t frame);
  63. /**
  64. * Enqueues the event specified by the arguments. The return
  65. * value indicates whether or not the event was successfully enqueued.
  66. */
  67. EnqueueResult
  68. EnqueueEvent(jack_nframes_t time, size_t size,
  69. jack_event_data_t *buffer);
  70. };
  71. }
  72. #endif