corosync  2.3.5-dirty
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 
48 typedef int64_t cs_time_t;
49 
50 #define CS_FALSE 0
51 #define CS_TRUE !CS_FALSE
52 #define CS_MAX_NAME_LENGTH 256
53 #define CS_TIME_END ((cs_time_t)0x7FFFFFFFFFFFFFFFULL)
54 #define CS_MAX(x, y) (((x) > (y)) ? (x) : (y))
55 
56 typedef struct {
57  uint16_t length;
59 } cs_name_t;
60 
61 typedef struct {
63  unsigned char majorVersion;
64  unsigned char minorVersion;
65 } cs_version_t;
66 
67 typedef enum {
73 
74 #define CS_TRACK_CURRENT 0x01
75 #define CS_TRACK_CHANGES 0x02
76 #define CS_TRACK_CHANGES_ONLY 0x04
77 
78 typedef enum {
79  CS_OK = 1,
109 } cs_error_t;
110 
111 #define CS_IPC_TIMEOUT_MS -1
112 
113 #define CS_TIME_MS_IN_SEC 1000ULL
114 #define CS_TIME_US_IN_SEC 1000000ULL
115 #define CS_TIME_NS_IN_SEC 1000000000ULL
116 #define CS_TIME_US_IN_MSEC 1000ULL
117 #define CS_TIME_NS_IN_MSEC 1000000ULL
118 #define CS_TIME_NS_IN_USEC 1000ULL
119 static inline uint64_t cs_timestamp_get(void)
120 {
121  uint64_t result;
122 
123 #if defined _POSIX_MONOTONIC_CLOCK && _POSIX_MONOTONIC_CLOCK >= 0
124  struct timespec ts;
125 
126  clock_gettime (CLOCK_MONOTONIC, &ts);
127  result = (ts.tv_sec * CS_TIME_NS_IN_SEC) + (uint64_t)ts.tv_nsec;
128 #else
129  struct timeval time_from_epoch;
130 
131  gettimeofday (&time_from_epoch, 0);
132  result = ((time_from_epoch.tv_sec * CS_TIME_NS_IN_SEC) +
133  (time_from_epoch.tv_usec * CS_TIME_NS_IN_USEC));
134 #endif
135 
136  return result;
137 }
138 
139 cs_error_t qb_to_cs_error (int result);
140 const char * cs_strerror(cs_error_t err);
141 cs_error_t hdb_error_to_cs (int res);
142 
143 #ifdef __cplusplus
144 }
145 #endif
146 
147 #endif /* COROTYPES_H_DEFINED */
148 
uint32_t value
const char * cs_strerror(cs_error_t err)
unsigned char minorVersion
Definition: corotypes.h:64
cs_error_t hdb_error_to_cs(int res)
char releaseCode
Definition: corotypes.h:62
int64_t cs_time_t
Definition: corotypes.h:48
cs_error_t
Definition: corotypes.h:78
#define CS_TIME_NS_IN_SEC
Definition: corotypes.h:115
cs_dispatch_flags_t
Definition: corotypes.h:67
unsigned char majorVersion
Definition: corotypes.h:63
#define CS_MAX_NAME_LENGTH
Definition: corotypes.h:52
#define CS_TIME_NS_IN_USEC
Definition: corotypes.h:118
uint16_t length
Definition: corotypes.h:57
cs_error_t qb_to_cs_error(int result)