forked from omniti-labs/jlog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jlog.h
164 lines (145 loc) · 5.68 KB
/
jlog.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
* Copyright (c) 2005-2008, Message Systems, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name Message Systems, Inc. nor the names
* of its contributors may be used to endorse or promote products
* derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _JLOG_H
#define _JLOG_H
#include "jlog_config.h"
#ifndef JLOG_API
# ifdef _WIN32
# ifdef JLOG_EXPORTS
# define JLOG_API(x) __declspec(dllexport) x
# else
# define JLOG_API(x) __declspec(dllimport) x
# endif
# else
# ifdef __cplusplus
# define JLOG_API(x) extern "C" x
# else
# define JLOG_API(x) x
# endif
# endif
#endif
struct _jlog_ctx;
struct _jlog_message_header;
struct _jlog_id;
typedef struct _jlog_ctx jlog_ctx;
typedef struct _jlog_message_header {
u_int32_t reserved;
u_int32_t tv_sec;
u_int32_t tv_usec;
u_int32_t mlen;
} jlog_message_header;
typedef struct _jlog_id {
u_int32_t log;
u_int32_t marker;
} jlog_id;
#define JLOG_ID_ADVANCE(id) (id)->marker++
typedef struct _jlog_message {
jlog_message_header *header;
u_int32_t mess_len;
void *mess;
jlog_message_header aligned_header;
} jlog_message;
typedef enum {
JLOG_BEGIN,
JLOG_END
} jlog_position;
typedef enum {
JLOG_UNSAFE,
JLOG_ALMOST_SAFE,
JLOG_SAFE
} jlog_safety;
typedef enum {
JLOG_ERR_SUCCESS = 0,
JLOG_ERR_ILLEGAL_INIT,
JLOG_ERR_ILLEGAL_OPEN,
JLOG_ERR_OPEN,
JLOG_ERR_NOTDIR,
JLOG_ERR_CREATE_PATHLEN,
JLOG_ERR_CREATE_EXISTS,
JLOG_ERR_CREATE_MKDIR,
JLOG_ERR_CREATE_META,
JLOG_ERR_LOCK,
JLOG_ERR_IDX_OPEN,
JLOG_ERR_IDX_SEEK,
JLOG_ERR_IDX_CORRUPT,
JLOG_ERR_IDX_WRITE,
JLOG_ERR_IDX_READ,
JLOG_ERR_FILE_OPEN,
JLOG_ERR_FILE_SEEK,
JLOG_ERR_FILE_CORRUPT,
JLOG_ERR_FILE_READ,
JLOG_ERR_FILE_WRITE,
JLOG_ERR_META_OPEN,
JLOG_ERR_ILLEGAL_WRITE,
JLOG_ERR_ILLEGAL_CHECKPOINT,
JLOG_ERR_INVALID_SUBSCRIBER,
JLOG_ERR_ILLEGAL_LOGID,
JLOG_ERR_SUBSCRIBER_EXISTS,
JLOG_ERR_CHECKPOINT,
JLOG_ERR_NOT_SUPPORTED,
JLOG_ERR_CLOSE_LOGID,
} jlog_err;
typedef void (*jlog_error_func) (void *ctx, const char *msg, ...);
JLOG_API(jlog_ctx *) jlog_new(const char *path);
JLOG_API(void) jlog_set_error_func(jlog_ctx *ctx, jlog_error_func Func, void *ptr);
JLOG_API(size_t) jlog_raw_size(jlog_ctx *ctx);
JLOG_API(int) jlog_ctx_init(jlog_ctx *ctx);
JLOG_API(int) jlog_get_checkpoint(jlog_ctx *ctx, const char *s, jlog_id *id);
JLOG_API(int) jlog_ctx_list_subscribers_dispose(jlog_ctx *ctx, char **subs);
JLOG_API(int) jlog_ctx_list_subscribers(jlog_ctx *ctx, char ***subs);
JLOG_API(int) jlog_ctx_err(jlog_ctx *ctx);
JLOG_API(const char *) jlog_ctx_err_string(jlog_ctx *ctx);
JLOG_API(int) jlog_ctx_errno(jlog_ctx *ctx);
JLOG_API(int) jlog_ctx_open_writer(jlog_ctx *ctx);
JLOG_API(int) jlog_ctx_open_reader(jlog_ctx *ctx, const char *subscriber);
JLOG_API(int) jlog_ctx_close(jlog_ctx *ctx);
JLOG_API(int) jlog_ctx_alter_mode(jlog_ctx *ctx, int mode);
JLOG_API(int) jlog_ctx_alter_journal_size(jlog_ctx *ctx, size_t size);
JLOG_API(int) jlog_ctx_alter_safety(jlog_ctx *ctx, jlog_safety safety);
JLOG_API(int) jlog_ctx_add_subscriber(jlog_ctx *ctx, const char *subscriber,
jlog_position whence);
JLOG_API(int) jlog_ctx_remove_subscriber(jlog_ctx *ctx, const char *subscriber);
JLOG_API(int) jlog_ctx_write(jlog_ctx *ctx, const void *message, size_t mess_len);
JLOG_API(int) jlog_ctx_write_message(jlog_ctx *ctx, jlog_message *msg, struct timeval *when);
JLOG_API(int) jlog_ctx_read_interval(jlog_ctx *ctx,
jlog_id *first_mess, jlog_id *last_mess);
JLOG_API(int) jlog_ctx_read_message(jlog_ctx *ctx, const jlog_id *, jlog_message *);
JLOG_API(int) jlog_ctx_read_checkpoint(jlog_ctx *ctx, const jlog_id *checkpoint);
JLOG_API(int) jlog_snprint_logid(char *buff, int n, const jlog_id *checkpoint);
JLOG_API(int) jlog_pending_readers(jlog_ctx *ctx, u_int32_t log, u_int32_t *earliest_ptr);
JLOG_API(int) __jlog_pending_readers(jlog_ctx *ctx, u_int32_t log);
JLOG_API(int) jlog_ctx_first_log_id(jlog_ctx *ctx, jlog_id *id);
JLOG_API(int) jlog_ctx_last_log_id(jlog_ctx *ctx, jlog_id *id);
JLOG_API(int) jlog_ctx_advance_id(jlog_ctx *ctx, jlog_id *cur,
jlog_id *start, jlog_id *finish);
JLOG_API(int) jlog_clean(const char *path);
#endif