| 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 |
# define JLOG_API(x) x |
|---|
| 47 |
# endif |
|---|
| 48 |
#endif |
|---|
| 49 |
|
|---|
| 50 |
struct _jlog_ctx; |
|---|
| 51 |
struct _jlog_message_header; |
|---|
| 52 |
struct _jlog_id; |
|---|
| 53 |
|
|---|
| 54 |
typedef struct _jlog_ctx jlog_ctx; |
|---|
| 55 |
|
|---|
| 56 |
typedef struct _jlog_message_header { |
|---|
| 57 |
u_int32_t reserved; |
|---|
| 58 |
u_int32_t tv_sec; |
|---|
| 59 |
u_int32_t tv_usec; |
|---|
| 60 |
u_int32_t mlen; |
|---|
| 61 |
} jlog_message_header; |
|---|
| 62 |
|
|---|
| 63 |
typedef struct _jlog_id { |
|---|
| 64 |
u_int32_t log; |
|---|
| 65 |
u_int32_t marker; |
|---|
| 66 |
} jlog_id; |
|---|
| 67 |
|
|---|
| 68 |
#define JLOG_ID_ADVANCE(id) (id)->marker++ |
|---|
| 69 |
|
|---|
| 70 |
typedef struct _jlog_message { |
|---|
| 71 |
jlog_message_header *header; |
|---|
| 72 |
u_int32_t mess_len; |
|---|
| 73 |
void *mess; |
|---|
| 74 |
jlog_message_header aligned_header; |
|---|
| 75 |
} jlog_message; |
|---|
| 76 |
|
|---|
| 77 |
typedef enum { |
|---|
| 78 |
JLOG_BEGIN, |
|---|
| 79 |
JLOG_END |
|---|
| 80 |
} jlog_position; |
|---|
| 81 |
|
|---|
| 82 |
typedef enum { |
|---|
| 83 |
JLOG_UNSAFE, |
|---|
| 84 |
JLOG_ALMOST_SAFE, |
|---|
| 85 |
JLOG_SAFE |
|---|
| 86 |
} jlog_safety; |
|---|
| 87 |
|
|---|
| 88 |
typedef enum { |
|---|
| 89 |
JLOG_ERR_SUCCESS = 0, |
|---|
| 90 |
JLOG_ERR_ILLEGAL_INIT, |
|---|
| 91 |
JLOG_ERR_ILLEGAL_OPEN, |
|---|
| 92 |
JLOG_ERR_OPEN, |
|---|
| 93 |
JLOG_ERR_NOTDIR, |
|---|
| 94 |
JLOG_ERR_CREATE_PATHLEN, |
|---|
| 95 |
JLOG_ERR_CREATE_EXISTS, |
|---|
| 96 |
JLOG_ERR_CREATE_MKDIR, |
|---|
| 97 |
JLOG_ERR_CREATE_META, |
|---|
| 98 |
JLOG_ERR_LOCK, |
|---|
| 99 |
JLOG_ERR_IDX_OPEN, |
|---|
| 100 |
JLOG_ERR_IDX_SEEK, |
|---|
| 101 |
JLOG_ERR_IDX_CORRUPT, |
|---|
| 102 |
JLOG_ERR_IDX_WRITE, |
|---|
| 103 |
JLOG_ERR_IDX_READ, |
|---|
| 104 |
JLOG_ERR_FILE_OPEN, |
|---|
| 105 |
JLOG_ERR_FILE_SEEK, |
|---|
| 106 |
JLOG_ERR_FILE_CORRUPT, |
|---|
| 107 |
JLOG_ERR_FILE_READ, |
|---|
| 108 |
JLOG_ERR_FILE_WRITE, |
|---|
| 109 |
JLOG_ERR_META_OPEN, |
|---|
| 110 |
JLOG_ERR_ILLEGAL_WRITE, |
|---|
| 111 |
JLOG_ERR_ILLEGAL_CHECKPOINT, |
|---|
| 112 |
JLOG_ERR_INVALID_SUBSCRIBER, |
|---|
| 113 |
JLOG_ERR_ILLEGAL_LOGID, |
|---|
| 114 |
JLOG_ERR_SUBSCRIBER_EXISTS, |
|---|
| 115 |
JLOG_ERR_CHECKPOINT, |
|---|
| 116 |
JLOG_ERR_NOT_SUPPORTED, |
|---|
| 117 |
} jlog_err; |
|---|
| 118 |
|
|---|
| 119 |
typedef void (*jlog_error_func) (void *ctx, const char *msg, ...); |
|---|
| 120 |
|
|---|
| 121 |
JLOG_API(jlog_ctx *) jlog_new(const char *path); |
|---|
| 122 |
JLOG_API(void) jlog_set_error_func(jlog_ctx *ctx, jlog_error_func Func, void *ptr); |
|---|
| 123 |
JLOG_API(size_t) jlog_raw_size(jlog_ctx *ctx); |
|---|
| 124 |
JLOG_API(int) jlog_ctx_init(jlog_ctx *ctx); |
|---|
| 125 |
JLOG_API(int) jlog_get_checkpoint(jlog_ctx *ctx, const char *s, jlog_id *id); |
|---|
| 126 |
JLOG_API(int) jlog_ctx_list_subscribers_dispose(jlog_ctx *ctx, char **subs); |
|---|
| 127 |
JLOG_API(int) jlog_ctx_list_subscribers(jlog_ctx *ctx, char ***subs); |
|---|
| 128 |
|
|---|
| 129 |
JLOG_API(int) jlog_ctx_err(jlog_ctx *ctx); |
|---|
| 130 |
JLOG_API(const char *) jlog_ctx_err_string(jlog_ctx *ctx); |
|---|
| 131 |
JLOG_API(int) jlog_ctx_errno(jlog_ctx *ctx); |
|---|
| 132 |
JLOG_API(int) jlog_ctx_open_writer(jlog_ctx *ctx); |
|---|
| 133 |
JLOG_API(int) jlog_ctx_open_reader(jlog_ctx *ctx, const char *subscriber); |
|---|
| 134 |
JLOG_API(int) jlog_ctx_close(jlog_ctx *ctx); |
|---|
| 135 |
|
|---|
| 136 |
JLOG_API(int) jlog_ctx_alter_mode(jlog_ctx *ctx, int mode); |
|---|
| 137 |
JLOG_API(int) jlog_ctx_alter_journal_size(jlog_ctx *ctx, size_t size); |
|---|
| 138 |
JLOG_API(int) jlog_ctx_alter_safety(jlog_ctx *ctx, jlog_safety safety); |
|---|
| 139 |
JLOG_API(int) jlog_ctx_add_subscriber(jlog_ctx *ctx, const char *subscriber, |
|---|
| 140 |
jlog_position whence); |
|---|
| 141 |
JLOG_API(int) jlog_ctx_remove_subscriber(jlog_ctx *ctx, const char *subscriber); |
|---|
| 142 |
|
|---|
| 143 |
JLOG_API(int) jlog_ctx_write(jlog_ctx *ctx, const void *message, size_t mess_len); |
|---|
| 144 |
JLOG_API(int) jlog_ctx_write_message(jlog_ctx *ctx, jlog_message *msg, struct timeval *when); |
|---|
| 145 |
JLOG_API(int) jlog_ctx_read_interval(jlog_ctx *ctx, |
|---|
| 146 |
jlog_id *first_mess, jlog_id *last_mess); |
|---|
| 147 |
JLOG_API(int) jlog_ctx_read_message(jlog_ctx *ctx, const jlog_id *, jlog_message *); |
|---|
| 148 |
JLOG_API(int) jlog_ctx_read_checkpoint(jlog_ctx *ctx, const jlog_id *checkpoint); |
|---|
| 149 |
JLOG_API(int) jlog_snprint_logid(char *buff, int n, const jlog_id *checkpoint); |
|---|
| 150 |
|
|---|
| 151 |
JLOG_API(int) __jlog_pending_readers(jlog_ctx *ctx, u_int32_t log); |
|---|
| 152 |
JLOG_API(int) jlog_ctx_first_log_id(jlog_ctx *ctx, jlog_id *id); |
|---|
| 153 |
JLOG_API(int) jlog_ctx_last_log_id(jlog_ctx *ctx, jlog_id *id); |
|---|
| 154 |
JLOG_API(int) jlog_ctx_advance_id(jlog_ctx *ctx, jlog_id *cur, |
|---|
| 155 |
jlog_id *start, jlog_id *finish); |
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 |
#endif |
|---|