mar_gen.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Copyright (C) 2006 Red Hat, 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_MAR_GEN_H_DEFINED
  35. #define AIS_MAR_GEN_H_DEFINED
  36. #include <stdint.h>
  37. #include <string.h>
  38. #include "saAis.h"
  39. #include "swab.h"
  40. typedef int8_t mar_int8_t;
  41. typedef int16_t mar_int16_t;
  42. typedef int32_t mar_int32_t;
  43. typedef int64_t mar_int64_t;
  44. typedef uint8_t mar_uint8_t;
  45. typedef uint16_t mar_uint16_t;
  46. typedef uint32_t mar_uint32_t;
  47. typedef uint64_t mar_uint64_t;
  48. static inline void swab_mar_int8_t (mar_int8_t *to_swab)
  49. {
  50. return;
  51. }
  52. static inline void swab_mar_int16_t (mar_int16_t *to_swab)
  53. {
  54. *to_swab = swab16 (*to_swab);
  55. }
  56. static inline void swab_mar_int32_t (mar_int32_t *to_swab)
  57. {
  58. *to_swab = swab32 (*to_swab);
  59. }
  60. static inline void swab_mar_int64_t (mar_int64_t *to_swab)
  61. {
  62. *to_swab = swab64 (*to_swab);
  63. }
  64. static inline void swab_mar_uint8_t (mar_uint8_t *to_swab)
  65. {
  66. return;
  67. }
  68. static inline void swab_mar_uint16_t (mar_uint16_t *to_swab)
  69. {
  70. *to_swab = swab16 (*to_swab);
  71. }
  72. static inline void swab_mar_uint32_t (mar_uint32_t *to_swab)
  73. {
  74. *to_swab = swab32 (*to_swab);
  75. }
  76. static inline void swab_mar_uint64_t (mar_uint64_t *to_swab)
  77. {
  78. *to_swab = swab64 (*to_swab);
  79. }
  80. typedef struct {
  81. mar_uint16_t length __attribute__((aligned(8)));
  82. mar_uint8_t value[SA_MAX_NAME_LENGTH] __attribute__((aligned(8)));
  83. } mar_name_t;
  84. static inline void swab_mar_name_t (mar_name_t *to_swab)
  85. {
  86. swab_mar_uint16_t (&to_swab->length);
  87. }
  88. static inline void marshall_from_mar_name_t (
  89. SaNameT *dest,
  90. mar_name_t *src)
  91. {
  92. dest->length = src->length;
  93. memcpy (dest->value, src->value, SA_MAX_NAME_LENGTH);
  94. }
  95. static inline void marshall_to_mar_name_t (
  96. mar_name_t *dest,
  97. SaNameT *src)
  98. {
  99. dest->length = src->length;
  100. memcpy (dest->value, src->value, SA_MAX_NAME_LENGTH);
  101. }
  102. typedef enum {
  103. MAR_FALSE = 0,
  104. MAR_TRUE = 1
  105. } mar_bool_t;
  106. typedef mar_uint64_t mar_time_t;
  107. static inline void swab_mar_time_t (mar_time_t *to_swab)
  108. {
  109. swab_mar_uint64_t (to_swab);
  110. }
  111. #define MAR_TIME_END ((SaTimeT)0x7fffffffffffffffull)
  112. #define MAR_TIME_BEGIN 0x0ULL
  113. #define MAR_TIME_UNKNOWN 0x8000000000000000ULL
  114. #define MAR_TIME_ONE_MICROSECOND 1000ULL
  115. #define MAR_TIME_ONE_MILLISECOND 1000000ULL
  116. #define MAR_TIME_ONE_SECOND 1000000000ULL
  117. #define MAR_TIME_ONE_MINUTE 60000000000ULL
  118. #define MAR_TIME_ONE_HOUR 3600000000000ULL
  119. #define MAR_TIME_ONE_DAY 86400000000000ULL
  120. #define MAR_TIME_MAX SA_TIME_END
  121. #define MAR_TRACK_CURRENT 0x01
  122. #define MAR_TRACK_CHANGES 0x02
  123. #define MAR_TRACK_CHANGES_ONLY 0x04
  124. typedef mar_uint64_t mar_invocation_t;
  125. static inline void swab_mar_invocation_t (mar_invocation_t *to_swab)
  126. {
  127. swab_mar_uint64_t (to_swab);
  128. }
  129. typedef mar_uint64_t mar_size_t;
  130. static inline void swab_mar_size_t (mar_size_t *to_swab)
  131. {
  132. swab_mar_uint64_t (to_swab);
  133. }
  134. #endif /* AIS_MAR_GEN_TYPES_H_DEFINED */