corosync 3.1.7
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
46typedef int8_t mar_int8_t;
47typedef int16_t mar_int16_t;
48typedef int32_t mar_int32_t;
49typedef int64_t mar_int64_t;
50
51typedef uint8_t mar_uint8_t;
52typedef uint16_t mar_uint16_t;
53typedef uint32_t mar_uint32_t;
54typedef uint64_t mar_uint64_t;
55
60static inline void swab_mar_int8_t (mar_int8_t *to_swab)
61{
62 return;
63}
64
69static inline void swab_mar_int16_t (mar_int16_t *to_swab)
70{
71 *to_swab = swab16 (*to_swab);
72}
73
78static inline void swab_mar_int32_t (mar_int32_t *to_swab)
79{
80 *to_swab = swab32 (*to_swab);
81}
82
87static inline void swab_mar_int64_t (mar_int64_t *to_swab)
88{
89 *to_swab = swab64 (*to_swab);
90}
91
96static inline void swab_mar_uint8_t (mar_uint8_t *to_swab)
97{
98 return;
99}
100
105static inline void swab_mar_uint16_t (mar_uint16_t *to_swab)
106{
107 *to_swab = swab16 (*to_swab);
108}
109
114static inline void swab_mar_uint32_t (mar_uint32_t *to_swab)
115{
116 *to_swab = swab32 (*to_swab);
117}
118
123static inline void swab_mar_uint64_t (mar_uint64_t *to_swab)
124{
125 *to_swab = swab64 (*to_swab);
126}
127
133static inline void swabbin(char *data, size_t len)
134{
135 int i;
136 char tmp;
137
138 for (i = 0; i < len / 2; i++) {
139 tmp = data[i];
140 data[i] = data[len - i - 1];
141 data[len - i - 1] = tmp;
142 }
143}
144
149static inline void swabflt(float *flt)
150{
151 swabbin((char *)flt, sizeof(*flt));
152}
153
158static inline void swabdbl(double *dbl)
159{
160 swabbin((char *)dbl, sizeof(*dbl));
161}
162
166typedef struct {
167 mar_uint16_t length __attribute__((aligned(8)));
169} mar_name_t;
170
176static inline const char *get_mar_name_t (const mar_name_t *name) {
177 return ((const char *)name->value);
178}
179
186static inline int mar_name_match(const mar_name_t *name1, const mar_name_t *name2)
187{
188 if (name1->length == name2->length) {
189 return ((strncmp ((const char *)name1->value,
190 (const char *)name2->value,
191 name1->length)) == 0);
192 }
193 return 0;
194}
195
200static inline void swab_mar_name_t (mar_name_t *to_swab)
201{
202 swab_mar_uint16_t (&to_swab->length);
203}
204
210static inline void marshall_from_mar_name_t (
211 cs_name_t *dest,
212 const mar_name_t *src)
213{
214 dest->length = src->length;
215 memcpy (dest->value, src->value, CS_MAX_NAME_LENGTH);
216}
217
223static inline void marshall_to_mar_name_t (
224 mar_name_t *dest,
225 const cs_name_t *src)
226{
227 dest->length = src->length;
228 memcpy (dest->value, src->value, CS_MAX_NAME_LENGTH);
229}
230
234typedef enum {
236 MAR_TRUE = 1
238
243
248static inline void swab_mar_time_t (mar_time_t *to_swab)
249{
250 swab_mar_uint64_t (to_swab);
251}
252
253#define MAR_TIME_END ((int64_t)0x7fffffffffffffffull)
254#define MAR_TIME_BEGIN 0x0ULL
255#define MAR_TIME_UNKNOWN 0x8000000000000000ULL
256
257#define MAR_TIME_ONE_MICROSECOND 1000ULL
258#define MAR_TIME_ONE_MILLISECOND 1000000ULL
259#define MAR_TIME_ONE_SECOND 1000000000ULL
260#define MAR_TIME_ONE_MINUTE 60000000000ULL
261#define MAR_TIME_ONE_HOUR 3600000000000ULL
262#define MAR_TIME_ONE_DAY 86400000000000ULL
263#define MAR_TIME_MAX CS_TIME_END
264
265#define MAR_TRACK_CURRENT 0x01
266#define MAR_TRACK_CHANGES 0x02
267#define MAR_TRACK_CHANGES_ONLY 0x04
268
273
278static inline void swab_mar_invocation_t (mar_invocation_t *to_swab)
279{
280 swab_mar_uint64_t (to_swab);
281}
282
287
292static inline void swab_mar_size_t (mar_size_t *to_swab)
293{
294 swab_mar_uint64_t (to_swab);
295}
296
301static inline void swab_coroipc_request_header_t (struct qb_ipc_request_header *to_swab)
302{
303 swab_mar_int32_t (&to_swab->size);
304 swab_mar_int32_t (&to_swab->id);
305}
306
307#endif /* MAR_GEN_H_DEFINED */
#define CS_MAX_NAME_LENGTH
Definition: corotypes.h:55
uint32_t value
int32_t mar_int32_t
Definition: mar_gen.h:48
int16_t mar_int16_t
Definition: mar_gen.h:47
int64_t mar_int64_t
Definition: mar_gen.h:49
mar_uint64_t mar_invocation_t
mar_invocation_t
Definition: mar_gen.h:272
uint32_t mar_uint32_t
Definition: mar_gen.h:53
int8_t mar_int8_t
Definition: mar_gen.h:46
mar_bool_t
mar_bool_t enum
Definition: mar_gen.h:234
@ MAR_FALSE
Definition: mar_gen.h:235
@ MAR_TRUE
Definition: mar_gen.h:236
mar_uint64_t mar_size_t
mar_size_t
Definition: mar_gen.h:286
mar_uint64_t mar_time_t
mar_time_t
Definition: mar_gen.h:242
uint8_t mar_uint8_t
Definition: mar_gen.h:51
uint16_t mar_uint16_t
Definition: mar_gen.h:52
uint64_t mar_uint64_t
Definition: mar_gen.h:54
The cs_name_t struct.
Definition: corotypes.h:66
uint8_t value[CS_MAX_NAME_LENGTH]
Definition: corotypes.h:68
uint16_t length
Definition: corotypes.h:67
mar_name_t struct
Definition: mar_gen.h:166
mar_uint8_t value[CS_MAX_NAME_LENGTH] __attribute__((aligned(8)))
mar_uint16_t length __attribute__((aligned(8)))
#define swab64(x)
The swab64 macro.
Definition: swab.h:65
#define swab16(x)
The swab16 macro.
Definition: swab.h:39
#define swab32(x)
The swab32 macro.
Definition: swab.h:51