corosync  3.0.4
corotypes.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 Allied Telesis Labs.
3  * Copyright (c) 2012 Red Hat, Inc.
4  *
5  * All rights reserved.
6  *
7  * Author: Angus Salkeld (ahsalkeld@gmail.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 
36 #ifndef COROTYPES_H_DEFINED
37 #define COROTYPES_H_DEFINED
38 
39 #include <stdint.h>
40 #include <errno.h>
41 #include <time.h>
42 #include <sys/time.h>
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
51 typedef int64_t cs_time_t;
52 
53 #define CS_FALSE 0
54 #define CS_TRUE !CS_FALSE
55 #define CS_MAX_NAME_LENGTH 256
56 #define CS_TIME_END ((cs_time_t)0x7FFFFFFFFFFFFFFFULL)
57 #define CS_MAX(x, y) (((x) > (y)) ? (x) : (y))
58 
59 #define CS_PRI_NODE_ID "%" PRIu32
60 #define CS_PRI_RING_ID_SEQ "%" PRIx64
61 #define CS_PRI_RING_ID "%" PRIx32 ".%" PRIx64
62 
65 typedef struct {
66  uint16_t length;
68 } cs_name_t;
69 
70 
74 typedef struct {
76  unsigned char majorVersion;
77  unsigned char minorVersion;
78 } cs_version_t;
79 
83 typedef enum {
89 
90 #define CS_TRACK_CURRENT 0x01
91 #define CS_TRACK_CHANGES 0x02
92 #define CS_TRACK_CHANGES_ONLY 0x04
93 
97 typedef enum {
98  CS_OK = 1,
128 } cs_error_t;
129 
130 #define CS_IPC_TIMEOUT_MS -1
131 
132 #define CS_TIME_MS_IN_SEC 1000ULL
133 #define CS_TIME_US_IN_SEC 1000000ULL
134 #define CS_TIME_NS_IN_SEC 1000000000ULL
135 #define CS_TIME_US_IN_MSEC 1000ULL
136 #define CS_TIME_NS_IN_MSEC 1000000ULL
137 #define CS_TIME_NS_IN_USEC 1000ULL
138 
143 static inline uint64_t cs_timestamp_get(void)
144 {
145  uint64_t result;
146 
147 #if defined _POSIX_MONOTONIC_CLOCK && _POSIX_MONOTONIC_CLOCK >= 0
148  struct timespec ts;
149 
150  clock_gettime (CLOCK_MONOTONIC, &ts);
151  result = (ts.tv_sec * CS_TIME_NS_IN_SEC) + (uint64_t)ts.tv_nsec;
152 #else
153  struct timeval time_from_epoch;
154 
155  gettimeofday (&time_from_epoch, 0);
156  result = ((time_from_epoch.tv_sec * CS_TIME_NS_IN_SEC) +
157  (time_from_epoch.tv_usec * CS_TIME_NS_IN_USEC));
158 #endif
159 
160  return result;
161 }
167 cs_error_t qb_to_cs_error (int result);
168 
174 const char * cs_strerror(cs_error_t err);
175 
181 cs_error_t hdb_error_to_cs (int res);
182 
183 #ifdef __cplusplus
184 }
185 #endif
186 
187 #endif /* COROTYPES_H_DEFINED */
188 
uint32_t value
const char * cs_strerror(cs_error_t err)
cs_strerror
unsigned char minorVersion
Definition: corotypes.h:77
cs_error_t hdb_error_to_cs(int res)
hdb_error_to_cs
char releaseCode
Definition: corotypes.h:75
int64_t cs_time_t
cs_time_t
Definition: corotypes.h:51
cs_error_t
The cs_error_t enum.
Definition: corotypes.h:97
#define CS_TIME_NS_IN_SEC
Definition: corotypes.h:134
cs_dispatch_flags_t
The cs_dispatch_flags_t enum.
Definition: corotypes.h:83
unsigned char majorVersion
Definition: corotypes.h:76
#define CS_MAX_NAME_LENGTH
Definition: corotypes.h:55
#define CS_TIME_NS_IN_USEC
Definition: corotypes.h:137
uint16_t length
Definition: corotypes.h:66
The cs_version_t struct.
Definition: corotypes.h:74
cs_error_t qb_to_cs_error(int result)
qb_to_cs_error
The cs_name_t struct.
Definition: corotypes.h:65