root/jlog.h

Revision be427d7d0f9dace3dcda51dab9099c37ccbc9a64, 5.5 kB (checked in by Jon Olsson <jon.olsson@gmail.com>, 1 year ago)

Make jlog.h usable from C++

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