util.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * Copyright (c) 2002-2003 MontaVista Software, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Steven Dake (sdake@mvista.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #ifndef AIS_UTIL_H_DEFINED
  35. #define AIS_UTIL_H_DEFINED
  36. #include <pthread.h>
  37. #include <sys/poll.h>
  38. #include "../include/ais_msg.h"
  39. struct saHandleDatabase {
  40. unsigned int handleCount;
  41. struct saHandle *handles;
  42. pthread_mutex_t mutex;
  43. void (*handleInstanceDestructor) (void *);
  44. };
  45. struct saVersionDatabase {
  46. int versionCount;
  47. SaVersionT *versionsSupported;
  48. };
  49. struct queue {
  50. int head;
  51. int tail;
  52. int used;
  53. int usedhw;
  54. int size;
  55. void *items;
  56. int bytesPerItem;
  57. };
  58. SaErrorT
  59. saServiceConnect (
  60. int *fdOut,
  61. enum service_types service);
  62. SaErrorT
  63. saServiceConnectTwo (
  64. int *responseOut,
  65. int *callbackOut,
  66. enum service_types service);
  67. SaErrorT
  68. saRecvRetry (
  69. int s,
  70. void *msg,
  71. size_t len,
  72. int flags);
  73. SaErrorT
  74. saRecvQueue (
  75. int s,
  76. void *msg,
  77. struct queue *queue,
  78. int findMessageId);
  79. SaErrorT
  80. saSendRetry (
  81. int s,
  82. const void *msg,
  83. size_t len,
  84. int flags);
  85. SaErrorT saSendMsgRetry (
  86. int s,
  87. struct iovec *iov,
  88. int iov_len);
  89. SaErrorT saSendMsgReceiveReply (
  90. int s,
  91. struct iovec *iov,
  92. int iov_len,
  93. void *responseMessage,
  94. int responseLen);
  95. SaErrorT saSendReceiveReply (
  96. int s,
  97. void *requestMessage,
  98. int requestLen,
  99. void *responseMessage,
  100. int responseLen);
  101. SaErrorT
  102. saSelectRetry (
  103. int s,
  104. fd_set *readfds,
  105. fd_set *writefds,
  106. fd_set *exceptfds,
  107. struct timeval *timeout);
  108. SaErrorT
  109. saPollRetry (
  110. struct pollfd *ufds,
  111. unsigned int nfds,
  112. int timeout);
  113. SaErrorT
  114. saHandleCreate (
  115. struct saHandleDatabase *handleDatabase,
  116. int instanceSize,
  117. SaUint64T *handleOut);
  118. SaErrorT
  119. saHandleDestroy (
  120. struct saHandleDatabase *handleDatabase,
  121. SaUint64T handle);
  122. SaErrorT
  123. saHandleInstanceGet (
  124. struct saHandleDatabase *handleDatabase,
  125. SaUint64T handle,
  126. void **instance);
  127. SaErrorT
  128. saHandleInstancePut (
  129. struct saHandleDatabase *handleDatabase,
  130. SaUint64T handle);
  131. SaErrorT
  132. saVersionVerify (
  133. struct saVersionDatabase *versionDatabase,
  134. SaVersionT *version);
  135. SaErrorT
  136. saQueueInit (
  137. struct queue *queue,
  138. int queueItems,
  139. int sizePerItem);
  140. SaErrorT
  141. saQueueIsFull (
  142. struct queue *queue,
  143. int *isFull);
  144. SaErrorT
  145. saQueueIsEmpty (
  146. struct queue *queue,
  147. int *isEmpty);
  148. SaErrorT
  149. saQueueItemAdd (
  150. struct queue *queue,
  151. void *item);
  152. SaErrorT
  153. saQueueItemGet (struct queue *queue, void **item);
  154. SaErrorT
  155. saQueueItemRemove (struct queue *queue);
  156. #define offset_of(type,member) (int)(&(((type *)0)->member))
  157. SaTimeT
  158. clustTimeNow(void);
  159. #endif /* AIS_UTIL_H_DEFINED */