00001
00019 #ifndef ZOOKEEPER_H_
00020 #define ZOOKEEPER_H_
00021
00022 #include <sys/time.h>
00023 #include <stdio.h>
00024
00025 #include "zookeeper_version.h"
00026 #include "recordio.h"
00027 #include "zookeeper.jute.h"
00028
00059
00060
00061
00062 #ifdef DLL_EXPORT
00063 # define ZOOAPI __declspec(dllexport)
00064 #else
00065 # if defined(__CYGWIN__) && !defined(USE_STATIC_LIB)
00066 # define ZOOAPI __declspec(dllimport)
00067 # else
00068 # define ZOOAPI
00069 # endif
00070 #endif
00071
00074 enum ZOO_ERRORS {
00075 ZOK = 0,
00081 ZSYSTEMERROR = -1,
00082 ZRUNTIMEINCONSISTENCY = -2,
00083 ZDATAINCONSISTENCY = -3,
00084 ZCONNECTIONLOSS = -4,
00085 ZMARSHALLINGERROR = -5,
00086 ZUNIMPLEMENTED = -6,
00087 ZOPERATIONTIMEOUT = -7,
00088 ZBADARGUMENTS = -8,
00089 ZINVALIDSTATE = -9,
00097 ZAPIERROR = -100,
00098 ZNONODE = -101,
00099 ZNOAUTH = -102,
00100 ZBADVERSION = -103,
00101 ZNOCHILDRENFOREPHEMERALS = -108,
00102 ZNODEEXISTS = -110,
00103 ZNOTEMPTY = -111,
00104 ZSESSIONEXPIRED = -112,
00105 ZINVALIDCALLBACK = -113,
00106 ZINVALIDACL = -114,
00107 ZAUTHFAILED = -115,
00108 ZCLOSING = -116,
00109 ZNOTHING = -117,
00110 ZSESSIONMOVED = -118
00111 };
00112
00113 #ifdef __cplusplus
00114 extern "C" {
00115 #endif
00116
00120 typedef enum {ZOO_LOG_LEVEL_ERROR=1,ZOO_LOG_LEVEL_WARN=2,ZOO_LOG_LEVEL_INFO=3,ZOO_LOG_LEVEL_DEBUG=4} ZooLogLevel;
00121
00125 extern ZOOAPI const int ZOO_PERM_READ;
00126 extern ZOOAPI const int ZOO_PERM_WRITE;
00127 extern ZOOAPI const int ZOO_PERM_CREATE;
00128 extern ZOOAPI const int ZOO_PERM_DELETE;
00129 extern ZOOAPI const int ZOO_PERM_ADMIN;
00130 extern ZOOAPI const int ZOO_PERM_ALL;
00131
00133 extern ZOOAPI struct Id ZOO_ANYONE_ID_UNSAFE;
00137 extern ZOOAPI struct Id ZOO_AUTH_IDS;
00138
00140 extern ZOOAPI struct ACL_vector ZOO_OPEN_ACL_UNSAFE;
00142 extern ZOOAPI struct ACL_vector ZOO_READ_ACL_UNSAFE;
00144 extern ZOOAPI struct ACL_vector ZOO_CREATOR_ALL_ACL;
00145
00154
00155 extern ZOOAPI const int ZOOKEEPER_WRITE;
00156 extern ZOOAPI const int ZOOKEEPER_READ;
00157
00158
00165
00166 extern ZOOAPI const int ZOO_EPHEMERAL;
00167 extern ZOOAPI const int ZOO_SEQUENCE;
00168
00169
00175
00176 extern ZOOAPI const int ZOO_EXPIRED_SESSION_STATE;
00177 extern ZOOAPI const int ZOO_AUTH_FAILED_STATE;
00178 extern ZOOAPI const int ZOO_CONNECTING_STATE;
00179 extern ZOOAPI const int ZOO_ASSOCIATING_STATE;
00180 extern ZOOAPI const int ZOO_CONNECTED_STATE;
00181
00182
00188
00195 extern ZOOAPI const int ZOO_CREATED_EVENT;
00202 extern ZOOAPI const int ZOO_DELETED_EVENT;
00209 extern ZOOAPI const int ZOO_CHANGED_EVENT;
00216 extern ZOOAPI const int ZOO_CHILD_EVENT;
00222 extern ZOOAPI const int ZOO_SESSION_EVENT;
00223
00230 extern ZOOAPI const int ZOO_NOTWATCHING_EVENT;
00231
00232
00240 typedef struct _zhandle zhandle_t;
00241
00249 typedef struct {
00250 int64_t client_id;
00251 char passwd[16];
00252 } clientid_t;
00253
00280 typedef void (*watcher_fn)(zhandle_t *zh, int type,
00281 int state, const char *path,void *watcherCtx);
00282
00311 ZOOAPI zhandle_t *zookeeper_init(const char *host, watcher_fn fn,
00312 int recv_timeout, const clientid_t *clientid, void *context, int flags);
00313
00336 ZOOAPI int zookeeper_close(zhandle_t *zh);
00337
00342 ZOOAPI const clientid_t *zoo_client_id(zhandle_t *zh);
00343
00344 ZOOAPI int zoo_recv_timeout(zhandle_t *zh);
00345
00346 ZOOAPI const void *zoo_get_context(zhandle_t *zh);
00347
00348 ZOOAPI void zoo_set_context(zhandle_t *zh, void *context);
00349
00354 ZOOAPI watcher_fn zoo_set_watcher(zhandle_t *zh,watcher_fn newFn);
00355
00356 #ifndef THREADED
00357
00376 ZOOAPI int zookeeper_interest(zhandle_t *zh, int *fd, int *interest,
00377 struct timeval *tv);
00378
00396 ZOOAPI int zookeeper_process(zhandle_t *zh, int events);
00397 #endif
00398
00416 typedef void (*void_completion_t)(int rc, const void *data);
00417
00438 typedef void (*stat_completion_t)(int rc, const struct Stat *stat,
00439 const void *data);
00440
00465 typedef void (*data_completion_t)(int rc, const char *value, int value_len,
00466 const struct Stat *stat, const void *data);
00467
00489 typedef void (*strings_completion_t)(int rc,
00490 const struct String_vector *strings, const void *data);
00491
00510 typedef void
00511 (*string_completion_t)(int rc, const char *value, const void *data);
00512
00536 typedef void (*acl_completion_t)(int rc, struct ACL_vector *acl,
00537 struct Stat *stat, const void *data);
00538
00544 ZOOAPI int zoo_state(zhandle_t *zh);
00545
00578 ZOOAPI int zoo_acreate(zhandle_t *zh, const char *path, const char *value,
00579 int valuelen, const struct ACL_vector *acl, int flags,
00580 string_completion_t completion, const void *data);
00581
00605 ZOOAPI int zoo_adelete(zhandle_t *zh, const char *path, int version,
00606 void_completion_t completion, const void *data);
00607
00629 ZOOAPI int zoo_aexists(zhandle_t *zh, const char *path, int watch,
00630 stat_completion_t completion, const void *data);
00631
00661 ZOOAPI int zoo_awexists(zhandle_t *zh, const char *path,
00662 watcher_fn watcher, void* watcherCtx,
00663 stat_completion_t completion, const void *data);
00664
00685 ZOOAPI int zoo_aget(zhandle_t *zh, const char *path, int watch,
00686 data_completion_t completion, const void *data);
00687
00714 ZOOAPI int zoo_awget(zhandle_t *zh, const char *path,
00715 watcher_fn watcher, void* watcherCtx,
00716 data_completion_t completion, const void *data);
00717
00744 ZOOAPI int zoo_aset(zhandle_t *zh, const char *path, const char *buffer, int buflen,
00745 int version, stat_completion_t completion, const void *data);
00746
00767 ZOOAPI int zoo_aget_children(zhandle_t *zh, const char *path, int watch,
00768 strings_completion_t completion, const void *data);
00769
00796 ZOOAPI int zoo_awget_children(zhandle_t *zh, const char *path,
00797 watcher_fn watcher, void* watcherCtx,
00798 strings_completion_t completion, const void *data);
00799
00819 ZOOAPI int zoo_async(zhandle_t *zh, const char *path,
00820 string_completion_t completion, const void *data);
00821
00822
00841 ZOOAPI int zoo_aget_acl(zhandle_t *zh, const char *path, acl_completion_t completion,
00842 const void *data);
00843
00866 ZOOAPI int zoo_aset_acl(zhandle_t *zh, const char *path, int version,
00867 struct ACL_vector *acl, void_completion_t, const void *data);
00868
00875 ZOOAPI const char* zerror(int c);
00876
00904 ZOOAPI int zoo_add_auth(zhandle_t *zh,const char* scheme,const char* cert,
00905 int certLen, void_completion_t completion, const void *data);
00906
00915 ZOOAPI int is_unrecoverable(zhandle_t *zh);
00916
00920 ZOOAPI void zoo_set_debug_level(ZooLogLevel logLevel);
00921
00929 ZOOAPI void zoo_set_log_stream(FILE* logStream);
00930
00940 ZOOAPI void zoo_deterministic_conn_order(int yesOrNo);
00941
00980 ZOOAPI int zoo_create(zhandle_t *zh, const char *path, const char *value,
00981 int valuelen, const struct ACL_vector *acl, int flags,
00982 char *path_buffer, int path_buffer_len);
00983
01003 ZOOAPI int zoo_delete(zhandle_t *zh, const char *path, int version);
01004
01005
01024 ZOOAPI int zoo_exists(zhandle_t *zh, const char *path, int watch, struct Stat *stat);
01025
01050 ZOOAPI int zoo_wexists(zhandle_t *zh, const char *path,
01051 watcher_fn watcher, void* watcherCtx, struct Stat *stat);
01052
01073 ZOOAPI int zoo_get(zhandle_t *zh, const char *path, int watch, char *buffer,
01074 int* buffer_len, struct Stat *stat);
01075
01102 ZOOAPI int zoo_wget(zhandle_t *zh, const char *path,
01103 watcher_fn watcher, void* watcherCtx,
01104 char *buffer, int* buffer_len, struct Stat *stat);
01105
01128 ZOOAPI int zoo_set(zhandle_t *zh, const char *path, const char *buffer,
01129 int buflen, int version);
01130
01155 ZOOAPI int zoo_set2(zhandle_t *zh, const char *path, const char *buffer,
01156 int buflen, int version, struct Stat *stat);
01157
01175 ZOOAPI int zoo_get_children(zhandle_t *zh, const char *path, int watch,
01176 struct String_vector *strings);
01177
01201 ZOOAPI int zoo_wget_children(zhandle_t *zh, const char *path,
01202 watcher_fn watcher, void* watcherCtx,
01203 struct String_vector *strings);
01204
01221 ZOOAPI int zoo_get_acl(zhandle_t *zh, const char *path, struct ACL_vector *acl,
01222 struct Stat *stat);
01223
01242 ZOOAPI int zoo_set_acl(zhandle_t *zh, const char *path, int version,
01243 const struct ACL_vector *acl);
01244
01245 #ifdef __cplusplus
01246 }
01247 #endif
01248
01249 #endif