root/jlog.h

Revision 81ac86a15e3940ff0b787698853fb6a6157f800b, 3.6 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 7 years ago)

initial import with Ecelerity bits removed and some autoconf glue added in. Could certainly use some work on the build/install. Needs shared lib support for multiple platforms

  • Property mode set to 100644
Line 
1 #ifndef _JLOG_H
2 #define _JLOG_H
3
4 #include "jlog_config.h"
5
6 #ifndef JLOG_API
7 # ifdef _WIN32
8 #  ifdef JLOG_EXPORTS
9 #   define JLOG_API(x) __declspec(dllexport) x
10 #  else
11 #   define JLOG_API(x) __declspec(dllimport) x
12 #  endif
13 # else
14 #  define JLOG_API(x)  x
15 # endif
16 #endif
17
18 struct _jlog_ctx;
19 struct _jlog_message_header;
20 struct _jlog_id;
21
22 typedef struct _jlog_ctx jlog_ctx;
23
24 typedef struct _jlog_message_header {
25   u_int32_t reserved;
26   u_int32_t tv_sec;
27   u_int32_t tv_usec;
28   u_int32_t mlen;
29 } jlog_message_header;
30
31 typedef struct _jlog_id {
32   u_int32_t log;
33   u_int32_t marker;
34 } jlog_id;
35
36 #define JLOG_ID_ADVANCE(id) (id)->marker++
37
38 typedef struct _jlog_message {
39   jlog_message_header *header;
40   u_int32_t mess_len;
41   void *mess;
42   jlog_message_header aligned_header;
43 } jlog_message;
44
45 typedef enum {
46   JLOG_BEGIN,
47   JLOG_END
48 } jlog_position;
49
50 typedef enum {
51   JLOG_UNSAFE,
52   JLOG_ALMOST_SAFE,
53   JLOG_SAFE
54 } jlog_safety;
55
56 typedef enum {
57   JLOG_ERR_SUCCESS = 0,
58   JLOG_ERR_ILLEGAL_INIT,
59   JLOG_ERR_ILLEGAL_OPEN,
60   JLOG_ERR_OPEN,
61   JLOG_ERR_NOTDIR,
62   JLOG_ERR_CREATE_PATHLEN,
63   JLOG_ERR_CREATE_EXISTS,
64   JLOG_ERR_CREATE_MKDIR,
65   JLOG_ERR_CREATE_META,
66   JLOG_ERR_LOCK,
67   JLOG_ERR_IDX_OPEN,
68   JLOG_ERR_IDX_SEEK,
69   JLOG_ERR_IDX_CORRUPT,
70   JLOG_ERR_IDX_WRITE,
71   JLOG_ERR_IDX_READ,
72   JLOG_ERR_FILE_OPEN,
73   JLOG_ERR_FILE_SEEK,
74   JLOG_ERR_FILE_CORRUPT,
75   JLOG_ERR_FILE_READ,
76   JLOG_ERR_FILE_WRITE,
77   JLOG_ERR_META_OPEN,
78   JLOG_ERR_ILLEGAL_WRITE,
79   JLOG_ERR_ILLEGAL_CHECKPOINT,
80   JLOG_ERR_INVALID_SUBSCRIBER,
81   JLOG_ERR_ILLEGAL_LOGID,
82   JLOG_ERR_SUBSCRIBER_EXISTS,
83   JLOG_ERR_CHECKPOINT,
84   JLOG_ERR_NOT_SUPPORTED,
85 } jlog_err;
86
87 typedef void (*jlog_error_func) (void *ctx, const char *msg, ...);
88
89 JLOG_API(jlog_ctx *) jlog_new(const char *path);
90 JLOG_API(void)      jlog_set_error_func(jlog_ctx *ctx, jlog_error_func Func, void *ptr);
91 JLOG_API(size_t)    jlog_raw_size(jlog_ctx *ctx);
92 JLOG_API(int)       jlog_ctx_init(jlog_ctx *ctx);
93 JLOG_API(int)       jlog_get_checkpoint(jlog_ctx *ctx, const char *s, jlog_id *id);
94 JLOG_API(int)       jlog_ctx_list_subscribers_dispose(jlog_ctx *ctx, char **subs);
95 JLOG_API(int)       jlog_ctx_list_subscribers(jlog_ctx *ctx, char ***subs);
96
97 JLOG_API(int)       jlog_ctx_err(jlog_ctx *ctx);
98 JLOG_API(const char *) jlog_ctx_err_string(jlog_ctx *ctx);
99 JLOG_API(int)       jlog_ctx_errno(jlog_ctx *ctx);
100 JLOG_API(int)       jlog_ctx_open_writer(jlog_ctx *ctx);
101 JLOG_API(int)       jlog_ctx_open_reader(jlog_ctx *ctx, const char *subscriber);
102 JLOG_API(int)       jlog_ctx_close(jlog_ctx *ctx);
103
104 JLOG_API(int)       jlog_ctx_alter_mode(jlog_ctx *ctx, int mode);
105 JLOG_API(int)       jlog_ctx_alter_journal_size(jlog_ctx *ctx, size_t size);
106 JLOG_API(int)       jlog_ctx_alter_safety(jlog_ctx *ctx, jlog_safety safety);
107 JLOG_API(int)       jlog_ctx_add_subscriber(jlog_ctx *ctx, const char *subscriber,
108                                             jlog_position whence);
109 JLOG_API(int)       jlog_ctx_remove_subscriber(jlog_ctx *ctx, const char *subscriber);
110
111 JLOG_API(int)       jlog_ctx_write(jlog_ctx *ctx, const void *message, size_t mess_len);
112 JLOG_API(int)       jlog_ctx_write_message(jlog_ctx *ctx, jlog_message *msg, struct timeval *when);
113 JLOG_API(int)       jlog_ctx_read_interval(jlog_ctx *ctx,
114                                            jlog_id *first_mess, jlog_id *last_mess);
115 JLOG_API(int)       jlog_ctx_read_message(jlog_ctx *ctx, const jlog_id *, jlog_message *);
116 JLOG_API(int)       jlog_ctx_read_checkpoint(jlog_ctx *ctx, const jlog_id *checkpoint);
117 JLOG_API(int)       jlog_snprint_logid(char *buff, int n, const jlog_id *checkpoint);
118
119 JLOG_API(int)       __jlog_pending_readers(jlog_ctx *ctx, u_int32_t log);
120 JLOG_API(int)       jlog_ctx_last_log_id(jlog_ctx *ctx, jlog_id *id);
121
122 #endif
Note: See TracBrowser for help on using the browser.