msg_q.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /* Copyright (c) 2011, The Linux Foundation. All rights reserved.
  2. *
  3. * Redistribution and use in source and binary forms, with or without
  4. * modification, are permitted provided that the following conditions are
  5. * met:
  6. * * Redistributions of source code must retain the above copyright
  7. * notice, this list of conditions and the following disclaimer.
  8. * * Redistributions in binary form must reproduce the above
  9. * copyright notice, this list of conditions and the following
  10. * disclaimer in the documentation and/or other materials provided
  11. * with the distribution.
  12. * * Neither the name of The Linux Foundation nor the names of its
  13. * contributors may be used to endorse or promote products derived
  14. * from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
  19. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
  20. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  21. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  22. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  23. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  24. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  25. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  26. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. #ifndef __MSG_Q_H__
  29. #define __MSG_Q_H__
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif /* __cplusplus */
  33. #include <stdlib.h>
  34. /** Linked List Return Codes */
  35. typedef enum
  36. {
  37. eMSG_Q_SUCCESS = 0,
  38. /**< Request was successful. */
  39. eMSG_Q_FAILURE_GENERAL = -1,
  40. /**< Failed because of a general failure. */
  41. eMSG_Q_INVALID_PARAMETER = -2,
  42. /**< Failed because the request contained invalid parameters. */
  43. eMSG_Q_INVALID_HANDLE = -3,
  44. /**< Failed because an invalid handle was specified. */
  45. eMSG_Q_UNAVAILABLE_RESOURCE = -4,
  46. /**< Failed because an there were not enough resources. */
  47. eMSG_Q_INSUFFICIENT_BUFFER = -5,
  48. /**< Failed because an the supplied buffer was too small. */
  49. eMSG_Q_EMPTY = -6
  50. /**< Failed because list is empty. */
  51. }msq_q_err_type;
  52. /*===========================================================================
  53. FUNCTION msg_q_init
  54. DESCRIPTION
  55. Initializes internal structures for message queue.
  56. msg_q_data: pointer to an opaque Q handle to be returned; NULL if fails
  57. DEPENDENCIES
  58. N/A
  59. RETURN VALUE
  60. Look at error codes above.
  61. SIDE EFFECTS
  62. N/A
  63. ===========================================================================*/
  64. msq_q_err_type msg_q_init(void** msg_q_data);
  65. /*===========================================================================
  66. FUNCTION msg_q_init2
  67. DESCRIPTION
  68. Initializes internal structures for message queue.
  69. DEPENDENCIES
  70. N/A
  71. RETURN VALUE
  72. opaque handle to the Q created; NULL if create fails
  73. SIDE EFFECTS
  74. N/A
  75. ===========================================================================*/
  76. const void* msg_q_init2();
  77. /*===========================================================================
  78. FUNCTION msg_q_destroy
  79. DESCRIPTION
  80. Releases internal structures for message queue.
  81. msg_q_data: State of message queue to be released.
  82. DEPENDENCIES
  83. N/A
  84. RETURN VALUE
  85. Look at error codes above.
  86. SIDE EFFECTS
  87. N/A
  88. ===========================================================================*/
  89. msq_q_err_type msg_q_destroy(void** msg_q_data);
  90. /*===========================================================================
  91. FUNCTION msg_q_snd
  92. DESCRIPTION
  93. Sends data to the message queue. The passed in data pointer
  94. is not modified or freed. Passed in msg_obj is expected to live throughout
  95. the use of the msg_q (i.e. data is not allocated internally)
  96. msg_q_data: Message Queue to add the element to.
  97. msgp: Pointer to data to add into message queue.
  98. dealloc: Function used to deallocate memory for this element. Pass NULL
  99. if you do not want data deallocated during a flush operation
  100. DEPENDENCIES
  101. N/A
  102. RETURN VALUE
  103. Look at error codes above.
  104. SIDE EFFECTS
  105. N/A
  106. ===========================================================================*/
  107. msq_q_err_type msg_q_snd(void* msg_q_data, void* msg_obj, void (*dealloc)(void*));
  108. /*===========================================================================
  109. FUNCTION msg_q_rcv
  110. DESCRIPTION
  111. Retrieves data from the message queue. msg_obj is the oldest message received
  112. and pointer is simply removed from message queue.
  113. msg_q_data: Message Queue to copy data from into msgp.
  114. msg_obj: Pointer to space to copy msg_q contents to.
  115. DEPENDENCIES
  116. N/A
  117. RETURN VALUE
  118. Look at error codes above.
  119. SIDE EFFECTS
  120. N/A
  121. ===========================================================================*/
  122. msq_q_err_type msg_q_rcv(void* msg_q_data, void** msg_obj);
  123. /*===========================================================================
  124. FUNCTION msg_q_rmv
  125. DESCRIPTION
  126. Remove data from the message queue. msg_obj is the oldest message received
  127. and pointer is simply removed from message queue.
  128. msg_q_data: Message Queue to copy data from into msgp.
  129. msg_obj: Pointer to space to copy msg_q contents to.
  130. DEPENDENCIES
  131. N/A
  132. RETURN VALUE
  133. Look at error codes above.
  134. SIDE EFFECTS
  135. N/A
  136. ===========================================================================*/
  137. msq_q_err_type msg_q_rmv(void* msg_q_data, void** msg_obj);
  138. /*===========================================================================
  139. FUNCTION msg_q_flush
  140. DESCRIPTION
  141. Function removes all elements from the message queue.
  142. msg_q_data: Message Queue to remove elements from.
  143. DEPENDENCIES
  144. N/A
  145. RETURN VALUE
  146. Look at error codes above.
  147. SIDE EFFECTS
  148. N/A
  149. ===========================================================================*/
  150. msq_q_err_type msg_q_flush(void* msg_q_data);
  151. /*===========================================================================
  152. FUNCTION msg_q_unblock
  153. DESCRIPTION
  154. This function will stop use of the message queue. All waiters will wake up
  155. and likely receive nothing from the queue resulting in a negative return
  156. value. The message queue can no longer be used until it is destroyed
  157. and initialized again after calling this function.
  158. msg_q_data: Message queue to unblock.
  159. DEPENDENCIES
  160. N/A
  161. RETURN VALUE
  162. Look at error codes above.
  163. SIDE EFFECTS
  164. N/A
  165. ===========================================================================*/
  166. msq_q_err_type msg_q_unblock(void* msg_q_data);
  167. #ifdef __cplusplus
  168. }
  169. #endif /* __cplusplus */
  170. #endif /* __MSG_Q_H__ */