mar_gen.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * Copyright (C) 2006 Red Hat, Inc.
  3. * Copyright (c) 2006-2008 Red Hat, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Author: Steven Dake (sdake@redhat.com)
  8. *
  9. * This software licensed under BSD license, the text of which follows:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. * - Redistributions in binary form must reproduce the above copyright notice,
  17. * this list of conditions and the following disclaimer in the documentation
  18. * and/or other materials provided with the distribution.
  19. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  33. * THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #ifndef AIS_MAR_GEN_H_DEFINED
  36. #define AIS_MAR_GEN_H_DEFINED
  37. #ifndef OPENAIS_SOLARIS
  38. #include <stdint.h>
  39. #else
  40. #include <sys/types.h>
  41. #endif
  42. #include <string.h>
  43. #include <saAis.h>
  44. #ifdef COROSYNC_EXTERNAL_ENGINE
  45. #include <corosync/engine/swab.h>
  46. #else
  47. #include "swab.h"
  48. #endif
  49. typedef int8_t mar_int8_t;
  50. typedef int16_t mar_int16_t;
  51. typedef int32_t mar_int32_t;
  52. typedef int64_t mar_int64_t;
  53. typedef uint8_t mar_uint8_t;
  54. typedef uint16_t mar_uint16_t;
  55. typedef uint32_t mar_uint32_t;
  56. typedef uint64_t mar_uint64_t;
  57. static inline void swab_mar_int8_t (mar_int8_t *to_swab)
  58. {
  59. return;
  60. }
  61. static inline void swab_mar_int16_t (mar_int16_t *to_swab)
  62. {
  63. *to_swab = swab16 (*to_swab);
  64. }
  65. static inline void swab_mar_int32_t (mar_int32_t *to_swab)
  66. {
  67. *to_swab = swab32 (*to_swab);
  68. }
  69. static inline void swab_mar_int64_t (mar_int64_t *to_swab)
  70. {
  71. *to_swab = swab64 (*to_swab);
  72. }
  73. static inline void swab_mar_uint8_t (mar_uint8_t *to_swab)
  74. {
  75. return;
  76. }
  77. static inline void swab_mar_uint16_t (mar_uint16_t *to_swab)
  78. {
  79. *to_swab = swab16 (*to_swab);
  80. }
  81. static inline void swab_mar_uint32_t (mar_uint32_t *to_swab)
  82. {
  83. *to_swab = swab32 (*to_swab);
  84. }
  85. static inline void swab_mar_uint64_t (mar_uint64_t *to_swab)
  86. {
  87. *to_swab = swab64 (*to_swab);
  88. }
  89. typedef struct {
  90. mar_uint16_t length __attribute__((aligned(8)));
  91. mar_uint8_t value[SA_MAX_NAME_LENGTH] __attribute__((aligned(8)));
  92. } mar_name_t;
  93. static inline char *get_mar_name_t (mar_name_t *name) {
  94. return ((char *)name->value);
  95. }
  96. static inline int mar_name_match(mar_name_t *name1, mar_name_t *name2)
  97. {
  98. if (name1->length == name2->length) {
  99. return ((strncmp ((char *)name1->value, (char *)name2->value,
  100. name1->length)) == 0);
  101. }
  102. return 0;
  103. }
  104. static inline void swab_mar_name_t (mar_name_t *to_swab)
  105. {
  106. swab_mar_uint16_t (&to_swab->length);
  107. }
  108. static inline void marshall_from_mar_name_t (
  109. SaNameT *dest,
  110. mar_name_t *src)
  111. {
  112. dest->length = src->length;
  113. memcpy (dest->value, src->value, SA_MAX_NAME_LENGTH);
  114. }
  115. static inline void marshall_to_mar_name_t (
  116. mar_name_t *dest,
  117. SaNameT *src)
  118. {
  119. dest->length = src->length;
  120. memcpy (dest->value, src->value, SA_MAX_NAME_LENGTH);
  121. }
  122. typedef enum {
  123. MAR_FALSE = 0,
  124. MAR_TRUE = 1
  125. } mar_bool_t;
  126. typedef mar_uint64_t mar_time_t;
  127. static inline void swab_mar_time_t (mar_time_t *to_swab)
  128. {
  129. swab_mar_uint64_t (to_swab);
  130. }
  131. #define MAR_TIME_END ((SaTimeT)0x7fffffffffffffffull)
  132. #define MAR_TIME_BEGIN 0x0ULL
  133. #define MAR_TIME_UNKNOWN 0x8000000000000000ULL
  134. #define MAR_TIME_ONE_MICROSECOND 1000ULL
  135. #define MAR_TIME_ONE_MILLISECOND 1000000ULL
  136. #define MAR_TIME_ONE_SECOND 1000000000ULL
  137. #define MAR_TIME_ONE_MINUTE 60000000000ULL
  138. #define MAR_TIME_ONE_HOUR 3600000000000ULL
  139. #define MAR_TIME_ONE_DAY 86400000000000ULL
  140. #define MAR_TIME_MAX SA_TIME_END
  141. #define MAR_TRACK_CURRENT 0x01
  142. #define MAR_TRACK_CHANGES 0x02
  143. #define MAR_TRACK_CHANGES_ONLY 0x04
  144. typedef mar_uint64_t mar_invocation_t;
  145. static inline void swab_mar_invocation_t (mar_invocation_t *to_swab)
  146. {
  147. swab_mar_uint64_t (to_swab);
  148. }
  149. typedef mar_uint64_t mar_size_t;
  150. static inline void swab_mar_size_t (mar_size_t *to_swab)
  151. {
  152. swab_mar_uint64_t (to_swab);
  153. }
  154. #endif /* AIS_MAR_GEN_TYPES_H_DEFINED */