corosync  3.0.3
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 
CS_DISPATCH_ONE
Definition: corotypes.h:84
CS_ERR_NAME_TOO_LONG
Definition: corotypes.h:110
CS_ERR_TOO_MANY_GROUPS
Definition: corotypes.h:126
CS_MAX_NAME_LENGTH
#define CS_MAX_NAME_LENGTH
Definition: corotypes.h:55
value
uint32_t value
Definition: exec/votequorum.c:100
CS_ERR_NO_RESOURCES
Definition: corotypes.h:115
hdb_error_to_cs
cs_error_t hdb_error_to_cs(int res)
hdb_error_to_cs
CS_TIME_NS_IN_SEC
#define CS_TIME_NS_IN_SEC
Definition: corotypes.h:134
CS_ERR_LIBRARY
Definition: corotypes.h:99
CS_ERR_TRY_AGAIN
Definition: corotypes.h:103
CS_ERR_BAD_OPERATION
Definition: corotypes.h:117
CS_DISPATCH_ALL
Definition: corotypes.h:85
CS_ERR_NOT_EXIST
Definition: corotypes.h:109
cs_name_t
The cs_name_t struct.
Definition: corotypes.h:65
CS_ERR_MESSAGE_ERROR
Definition: corotypes.h:119
CS_ERR_TOO_BIG
Definition: corotypes.h:123
cs_dispatch_flags_t
cs_dispatch_flags_t
The cs_dispatch_flags_t enum.
Definition: corotypes.h:83
cs_version_t::majorVersion
unsigned char majorVersion
Definition: corotypes.h:76
CS_ERR_NOT_SUPPORTED
Definition: corotypes.h:116
CS_ERR_CONTEXT_NOT_FOUND
Definition: corotypes.h:125
CS_ERR_INIT
Definition: corotypes.h:101
cs_strerror
const char * cs_strerror(cs_error_t err)
cs_strerror
CS_OK
Definition: corotypes.h:98
CS_ERR_NO_SPACE
Definition: corotypes.h:112
CS_ERR_QUEUE_FULL
Definition: corotypes.h:120
CS_ERR_BUSY
Definition: corotypes.h:107
cs_error_t
cs_error_t
The cs_error_t enum.
Definition: corotypes.h:97
CS_ERR_ACCESS
Definition: corotypes.h:108
cs_version_t::releaseCode
char releaseCode
Definition: corotypes.h:75
CS_ERR_INTERRUPT
Definition: corotypes.h:113
cs_name_t::length
uint16_t length
Definition: corotypes.h:66
qb_to_cs_error
cs_error_t qb_to_cs_error(int result)
qb_to_cs_error
CS_ERR_EXIST
Definition: corotypes.h:111
CS_ERR_VERSION
Definition: corotypes.h:100
CS_ERR_BAD_HANDLE
Definition: corotypes.h:106
CS_ERR_NO_SECTIONS
Definition: corotypes.h:124
CS_ERR_BAD_FLAGS
Definition: corotypes.h:122
CS_DISPATCH_BLOCKING
Definition: corotypes.h:86
CS_TIME_NS_IN_USEC
#define CS_TIME_NS_IN_USEC
Definition: corotypes.h:137
cs_time_t
int64_t cs_time_t
cs_time_t
Definition: corotypes.h:51
CS_ERR_INVALID_PARAM
Definition: corotypes.h:104
CS_ERR_NAME_NOT_FOUND
Definition: corotypes.h:114
cs_version_t
The cs_version_t struct.
Definition: corotypes.h:74
CS_ERR_FAILED_OPERATION
Definition: corotypes.h:118
cs_version_t::minorVersion
unsigned char minorVersion
Definition: corotypes.h:77
CS_ERR_TIMEOUT
Definition: corotypes.h:102
CS_ERR_NO_MEMORY
Definition: corotypes.h:105
CS_ERR_QUEUE_NOT_AVAILABLE
Definition: corotypes.h:121
CS_ERR_SECURITY
Definition: corotypes.h:127
CS_DISPATCH_ONE_NONBLOCKING
Definition: corotypes.h:87