corosync  2.3.5-dirty
mar_gen.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2006-2011 Red Hat, Inc.
3  *
4  * All rights reserved.
5  *
6  * Author: Steven Dake (sdake@redhat.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 
35 #ifndef MAR_GEN_H_DEFINED
36 #define MAR_GEN_H_DEFINED
37 
38 #include <stdint.h>
39 #include <string.h>
40 
41 #include <corosync/corotypes.h>
42 #include <corosync/swab.h>
43 
44 #define MAR_ALIGN_UP(addr,size) (((addr)+((size)-1))&(~((size)-1)))
45 
46 typedef int8_t mar_int8_t;
47 typedef int16_t mar_int16_t;
48 typedef int32_t mar_int32_t;
49 typedef int64_t mar_int64_t;
50 
51 typedef uint8_t mar_uint8_t;
52 typedef uint16_t mar_uint16_t;
53 typedef uint32_t mar_uint32_t;
54 typedef uint64_t mar_uint64_t;
55 
56 static inline void swab_mar_int8_t (mar_int8_t *to_swab)
57 {
58  return;
59 }
60 
61 static inline void swab_mar_int16_t (mar_int16_t *to_swab)
62 {
63  *to_swab = swab16 (*to_swab);
64 }
65 
66 static inline void swab_mar_int32_t (mar_int32_t *to_swab)
67 {
68  *to_swab = swab32 (*to_swab);
69 }
70 
71 static inline void swab_mar_int64_t (mar_int64_t *to_swab)
72 {
73  *to_swab = swab64 (*to_swab);
74 }
75 
76 static inline void swab_mar_uint8_t (mar_uint8_t *to_swab)
77 {
78  return;
79 }
80 
81 static inline void swab_mar_uint16_t (mar_uint16_t *to_swab)
82 {
83  *to_swab = swab16 (*to_swab);
84 }
85 
86 static inline void swab_mar_uint32_t (mar_uint32_t *to_swab)
87 {
88  *to_swab = swab32 (*to_swab);
89 }
90 
91 static inline void swab_mar_uint64_t (mar_uint64_t *to_swab)
92 {
93  *to_swab = swab64 (*to_swab);
94 }
95 
96 static inline void swabbin(char *data, size_t len)
97 {
98  int i;
99  char tmp;
100 
101  for (i = 0; i < len / 2; i++) {
102  tmp = data[i];
103  data[i] = data[len - i - 1];
104  data[len - i - 1] = tmp;
105  }
106 }
107 
108 static inline void swabflt(float *flt)
109 {
110  swabbin((char *)flt, sizeof(*flt));
111 }
112 
113 static inline void swabdbl(double *dbl)
114 {
115  swabbin((char *)dbl, sizeof(*dbl));
116 }
117 
118 typedef struct {
119  mar_uint16_t length __attribute__((aligned(8)));
121 } mar_name_t;
122 
123 static inline const char *get_mar_name_t (const mar_name_t *name) {
124  return ((const char *)name->value);
125 }
126 
127 static inline int mar_name_match(const mar_name_t *name1, const mar_name_t *name2)
128 {
129  if (name1->length == name2->length) {
130  return ((strncmp ((const char *)name1->value,
131  (const char *)name2->value,
132  name1->length)) == 0);
133  }
134  return 0;
135 }
136 
137 
138 static inline void swab_mar_name_t (mar_name_t *to_swab)
139 {
140  swab_mar_uint16_t (&to_swab->length);
141 }
142 
143 static inline void marshall_from_mar_name_t (
144  cs_name_t *dest,
145  const mar_name_t *src)
146 {
147  dest->length = src->length;
148  memcpy (dest->value, src->value, CS_MAX_NAME_LENGTH);
149 }
150 
151 static inline void marshall_to_mar_name_t (
152  mar_name_t *dest,
153  const cs_name_t *src)
154 {
155  dest->length = src->length;
156  memcpy (dest->value, src->value, CS_MAX_NAME_LENGTH);
157 }
158 
159 typedef enum {
162 } mar_bool_t;
163 
165 
166 static inline void swab_mar_time_t (mar_time_t *to_swab)
167 {
168  swab_mar_uint64_t (to_swab);
169 }
170 
171 #define MAR_TIME_END ((int64_t)0x7fffffffffffffffull)
172 #define MAR_TIME_BEGIN 0x0ULL
173 #define MAR_TIME_UNKNOWN 0x8000000000000000ULL
174 
175 #define MAR_TIME_ONE_MICROSECOND 1000ULL
176 #define MAR_TIME_ONE_MILLISECOND 1000000ULL
177 #define MAR_TIME_ONE_SECOND 1000000000ULL
178 #define MAR_TIME_ONE_MINUTE 60000000000ULL
179 #define MAR_TIME_ONE_HOUR 3600000000000ULL
180 #define MAR_TIME_ONE_DAY 86400000000000ULL
181 #define MAR_TIME_MAX CS_TIME_END
182 
183 #define MAR_TRACK_CURRENT 0x01
184 #define MAR_TRACK_CHANGES 0x02
185 #define MAR_TRACK_CHANGES_ONLY 0x04
186 
188 
189 static inline void swab_mar_invocation_t (mar_invocation_t *to_swab)
190 {
191  swab_mar_uint64_t (to_swab);
192 }
193 
195 
196 static inline void swab_mar_size_t (mar_size_t *to_swab)
197 {
198  swab_mar_uint64_t (to_swab);
199 }
200 
201 static inline void swab_coroipc_request_header_t (struct qb_ipc_request_header *to_swab)
202 {
203  swab_mar_int32_t (&to_swab->size);
204  swab_mar_int32_t (&to_swab->id);
205 }
206 
207 #endif /* MAR_GEN_H_DEFINED */
int16_t mar_int16_t
Definition: mar_gen.h:47
uint32_t value
int64_t mar_int64_t
Definition: mar_gen.h:49
uint8_t value[CS_MAX_NAME_LENGTH]
Definition: corotypes.h:58
#define swab64(x)
Definition: swab.h:52
mar_uint64_t mar_time_t
Definition: mar_gen.h:164
uint64_t mar_uint64_t
Definition: mar_gen.h:54
mar_uint64_t mar_size_t
Definition: mar_gen.h:194
uint8_t mar_uint8_t
Definition: mar_gen.h:51
typedef __attribute__
int8_t mar_int8_t
Definition: mar_gen.h:46
uint16_t mar_uint16_t
Definition: mar_gen.h:52
mar_bool_t
Definition: mar_gen.h:159
#define swab32(x)
Definition: swab.h:43
mar_uint64_t mar_invocation_t
Definition: mar_gen.h:187
uint32_t mar_uint32_t
Definition: mar_gen.h:53
#define swab16(x)
Definition: swab.h:35
#define CS_MAX_NAME_LENGTH
Definition: corotypes.h:52
uint16_t length
Definition: corotypes.h:57
int32_t mar_int32_t
Definition: mar_gen.h:48