00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef ZOOKEEPER_H_
00018 #define ZOOKEEPER_H_
00019
00020 #include <sys/time.h>
00021 #include <stdio.h>
00022 #include "recordio.h"
00023 #include "zookeeper.jute.h"
00024
00055
00056
00057
00058 #ifdef DLL_EXPORT
00059 # define ZOOAPI __declspec(dllexport)
00060 #else
00061 # if defined(__CYGWIN__) && !defined(USE_STATIC_LIB)
00062 # define ZOOAPI __declspec(dllimport)
00063 # else
00064 # define ZOOAPI
00065 # endif
00066 #endif
00067
00070 #define ZOK 0
00071 #define ZSYSTEMERROR -1
00072 #define ZRUNTIMEINCONSISTENCY (ZSYSTEMERROR - 1)
00073 #define ZDATAINCONSISTENCY (ZSYSTEMERROR - 2)
00074 #define ZCONNECTIONLOSS (ZSYSTEMERROR - 3)
00075 #define ZMARSHALLINGERROR (ZSYSTEMERROR - 4)
00076 #define ZUNIMPLEMENTED (ZSYSTEMERROR - 5)
00077 #define ZOPERATIONTIMEOUT (ZSYSTEMERROR - 6)
00078 #define ZBADARGUMENTS (ZSYSTEMERROR - 7)
00079 #define ZINVALIDSTATE (ZSYSTEMERROR - 8)
00080 #define ZAPIERROR -100
00081 #define ZNONODE (ZAPIERROR - 1)
00082 #define ZNOAUTH (ZAPIERROR - 2)
00083 #define ZBADVERSION (ZAPIERROR - 3)
00084 #define ZNOCHILDRENFOREPHEMERALS (ZAPIERROR - 8)
00085 #define ZNODEEXISTS (ZAPIERROR - 10)
00086 #define ZNOTEMPTY (ZAPIERROR - 11)
00087 #define ZSESSIONEXPIRED (ZAPIERROR - 12)
00088 #define ZINVALIDCALLBACK (ZAPIERROR - 13)
00089 #define ZINVALIDACL (ZAPIERROR - 14)
00090 #define ZAUTHFAILED (ZAPIERROR - 15)
00091 #define ZCLOSING (ZAPIERROR - 16)
00092 #define ZNOTHING (ZAPIERROR - 17)
00093
00094 #ifdef __cplusplus
00095 extern "C" {
00096 #endif
00097
00101 typedef enum {LOG_LEVEL_ERROR=1,LOG_LEVEL_WARN=2,LOG_LEVEL_INFO=3,LOG_LEVEL_DEBUG=4} ZooLogLevel;
00105 extern ZOOAPI const int PERM_READ;
00106 extern ZOOAPI const int PERM_WRITE;
00107 extern ZOOAPI const int PERM_CREATE;
00108 extern ZOOAPI const int PERM_DELETE;
00109 extern ZOOAPI const int PERM_ADMIN;
00110 extern ZOOAPI const int PERM_ALL;
00111
00112 extern ZOOAPI struct Id ANYONE_ID_UNSAFE;
00113 extern ZOOAPI struct Id AUTH_IDS;
00114
00115 extern ZOOAPI struct ACL_vector OPEN_ACL_UNSAFE;
00116 extern ZOOAPI struct ACL_vector READ_ACL_UNSAFE;
00117 extern ZOOAPI struct ACL_vector CREATOR_ALL_ACL;
00118
00127
00128 extern ZOOAPI const int ZOOKEEPER_WRITE;
00129 extern ZOOAPI const int ZOOKEEPER_READ;
00130
00131
00138
00139 extern ZOOAPI const int EPHEMERAL;
00140 extern ZOOAPI const int SEQUENCE;
00141
00142
00150
00151 extern ZOOAPI const int EXPIRED_SESSION_STATE;
00152 extern ZOOAPI const int AUTH_FAILED_STATE;
00153 extern ZOOAPI const int CONNECTING_STATE;
00154 extern ZOOAPI const int ASSOCIATING_STATE;
00155 extern ZOOAPI const int CONNECTED_STATE;
00156
00157
00163
00170 extern ZOOAPI const int CREATED_EVENT;
00177 extern ZOOAPI const int DELETED_EVENT;
00184 extern ZOOAPI const int CHANGED_EVENT;
00191 extern ZOOAPI const int CHILD_EVENT;
00197 extern ZOOAPI const int SESSION_EVENT;
00198
00205 extern ZOOAPI const int NOTWATCHING_EVENT;
00206
00207
00215 typedef struct _zhandle zhandle_t;
00216
00224 typedef struct {
00225 int64_t client_id;
00226 char passwd[16];
00227 } clientid_t;
00228
00235 typedef void (*watcher_fn)(zhandle_t *, int type, int state, const char *path);
00236
00260 ZOOAPI zhandle_t *zookeeper_init(const char *host, watcher_fn fn,
00261 int recv_timeout, const clientid_t *clientid, void *context, int flags);
00262
00284 ZOOAPI int zookeeper_close(zhandle_t *zh);
00285
00289 ZOOAPI const clientid_t *zoo_client_id(zhandle_t *zh);
00290
00291 ZOOAPI int zoo_recv_timeout(zhandle_t *zh);
00292
00293 ZOOAPI const void *zoo_get_context(zhandle_t *zh);
00294
00295 ZOOAPI void zoo_set_context(zhandle_t *zh, void *context);
00296
00301 ZOOAPI watcher_fn zoo_set_watcher(zhandle_t *zh,watcher_fn newFn);
00302
00303 #ifndef THREADED
00304
00323 ZOOAPI int zookeeper_interest(zhandle_t *zh, int *fd, int *interest,
00324 struct timeval *tv);
00325
00343 ZOOAPI int zookeeper_process(zhandle_t *zh, int events);
00344 #endif
00345
00363 typedef void (*void_completion_t)(int rc, const void *data);
00364
00385 typedef void (*stat_completion_t)(int rc, const struct Stat *stat,
00386 const void *data);
00387
00412 typedef void (*data_completion_t)(int rc, const char *value, int value_len,
00413 const struct Stat *stat, const void *data);
00414
00436 typedef void (*strings_completion_t)(int rc,
00437 const struct String_vector *strings, const void *data);
00438
00457 typedef void
00458 (*string_completion_t)(int rc, const char *value, const void *data);
00459
00483 typedef void (*acl_completion_t)(int rc, struct ACL_vector *acl,
00484 struct Stat *stat, const void *data);
00485
00491 ZOOAPI int zoo_state(zhandle_t *zh);
00492
00525 ZOOAPI int zoo_acreate(zhandle_t *zh, const char *path, const char *value,
00526 int valuelen, const struct ACL_vector *acl, int flags,
00527 string_completion_t completion, const void *data);
00528
00552 ZOOAPI int zoo_adelete(zhandle_t *zh, const char *path, int version,
00553 void_completion_t completion, const void *data);
00554
00576 ZOOAPI int zoo_aexists(zhandle_t *zh, const char *path, int watch,
00577 stat_completion_t completion, const void *data);
00578
00599 ZOOAPI int zoo_aget(zhandle_t *zh, const char *path, int watch,
00600 data_completion_t completion, const void *data);
00601
00628 ZOOAPI int zoo_aset(zhandle_t *zh, const char *path, const char *buffer, int buflen,
00629 int version, stat_completion_t completion, const void *data);
00630
00651 ZOOAPI int zoo_aget_children(zhandle_t *zh, const char *path, int watch,
00652 strings_completion_t completion, const void *data);
00653
00673 ZOOAPI int zoo_async(zhandle_t *zh, const char *path, string_completion_t completion, const void *data);
00674
00675
00694 ZOOAPI int zoo_aget_acl(zhandle_t *zh, const char *path, acl_completion_t completion,
00695 const void *data);
00696
00719 ZOOAPI int zoo_aset_acl(zhandle_t *zh, const char *path, int version,
00720 struct ACL_vector *acl, void_completion_t, const void *data);
00721
00728 ZOOAPI const char* zerror(int c);
00729
00757 ZOOAPI int zoo_add_auth(zhandle_t *zh,const char* scheme,const char* cert,
00758 int certLen, void_completion_t completion, const void *data);
00759
00768 ZOOAPI int is_unrecoverable(zhandle_t *zh);
00769
00773 ZOOAPI void zoo_set_debug_level(ZooLogLevel logLevel);
00774
00782 ZOOAPI void zoo_set_log_stream(FILE* logStream);
00783
00793 ZOOAPI void zoo_deterministic_conn_order(int yesOrNo);
00794
00827 ZOOAPI int zoo_create(zhandle_t *zh, const char *path, const char *value,
00828 int valuelen, const struct ACL_vector *acl, int flags, char *realpath,
00829 int max_realpath_len);
00830
00851 ZOOAPI int zoo_delete(zhandle_t *zh, const char *path, int version);
00852
00853
00873 ZOOAPI int zoo_exists(zhandle_t *zh, const char *path, int watch, struct Stat *stat);
00874
00896 ZOOAPI int zoo_get(zhandle_t *zh, const char *path, int watch, char *buffer,
00897 int* buffer_len, struct Stat *stat);
00898
00899
00921 ZOOAPI int zoo_set(zhandle_t *zh, const char *path, const char *buffer, int buflen,
00922 int version);
00923
00924
00943 ZOOAPI int zoo_get_children(zhandle_t *zh, const char *path, int watch,
00944 struct String_vector *strings);
00962 ZOOAPI int zoo_get_acl(zhandle_t *zh, const char *path, struct ACL_vector *acl,
00963 struct Stat *stat);
00964
00984 ZOOAPI int zoo_set_acl(zhandle_t *zh, const char *path, int version,
00985 const struct ACL_vector *acl);
00986
00987 #ifdef __cplusplus
00988 }
00989 #endif
00990
00991 #endif