util.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 req_init_types init_type);
  62. SaErrorT
  63. saRecvRetry (
  64. int s,
  65. void *msg,
  66. size_t len,
  67. int flags);
  68. SaErrorT
  69. saRecvQueue (
  70. int s,
  71. void *msg,
  72. struct queue *queue,
  73. int findMessageId);
  74. SaErrorT
  75. saActivatePoll (int s);
  76. SaErrorT
  77. saSendRetry (
  78. int s,
  79. const void *msg,
  80. size_t len,
  81. int flags);
  82. SaErrorT saSendMsgRetry (
  83. int s,
  84. struct iovec *iov,
  85. int iov_len);
  86. SaErrorT
  87. saSelectRetry (
  88. int s,
  89. fd_set *readfds,
  90. fd_set *writefds,
  91. fd_set *exceptfds,
  92. struct timeval *timeout);
  93. SaErrorT
  94. saPollRetry (
  95. struct pollfd *ufds,
  96. unsigned int nfds,
  97. int timeout);
  98. SaErrorT
  99. saHandleCreate (
  100. struct saHandleDatabase *handleDatabase,
  101. int instanceSize,
  102. unsigned int *handleOut);
  103. SaErrorT
  104. saHandleDestroy (
  105. struct saHandleDatabase *handleDatabase,
  106. unsigned int handle);
  107. SaErrorT
  108. saHandleInstanceGet (
  109. struct saHandleDatabase *handleDatabase,
  110. unsigned int handle,
  111. void **instance);
  112. SaErrorT
  113. saHandleInstancePut (
  114. struct saHandleDatabase *handleDatabase,
  115. unsigned int handle);
  116. SaErrorT
  117. saVersionVerify (
  118. struct saVersionDatabase *versionDatabase,
  119. const SaVersionT *version);
  120. SaErrorT
  121. saQueueInit (
  122. struct queue *queue,
  123. int queueItems,
  124. int sizePerItem);
  125. SaErrorT
  126. saQueueIsFull (
  127. struct queue *queue,
  128. int *isFull);
  129. SaErrorT
  130. saQueueIsEmpty (
  131. struct queue *queue,
  132. int *isEmpty);
  133. SaErrorT
  134. saQueueItemAdd (
  135. struct queue *queue,
  136. void *item);
  137. SaErrorT
  138. saQueueItemGet (struct queue *queue, void **item);
  139. SaErrorT
  140. saQueueItemRemove (struct queue *queue);
  141. #define offset_of(type,member) (int)(&(((type *)0)->member))
  142. SaTimeT
  143. clustTimeNow(void);
  144. #endif /* AIS_UTIL_H_DEFINED */