zookeeper-3.3.3
|
00001 00019 #ifndef ZOOKEEPER_H_ 00020 #define ZOOKEEPER_H_ 00021 00022 #include <stdlib.h> 00023 #include <sys/time.h> 00024 #include <stdio.h> 00025 #include <ctype.h> 00026 00027 #include "zookeeper_version.h" 00028 #include "recordio.h" 00029 #include "zookeeper.jute.h" 00030 00061 /* Support for building on various platforms */ 00062 00063 // on cygwin we should take care of exporting/importing symbols properly 00064 #ifdef DLL_EXPORT 00065 # define ZOOAPI __declspec(dllexport) 00066 #else 00067 # if defined(__CYGWIN__) && !defined(USE_STATIC_LIB) 00068 # define ZOOAPI __declspec(dllimport) 00069 # else 00070 # define ZOOAPI 00071 # endif 00072 #endif 00073 00076 enum ZOO_ERRORS { 00077 ZOK = 0, 00083 ZSYSTEMERROR = -1, 00084 ZRUNTIMEINCONSISTENCY = -2, 00085 ZDATAINCONSISTENCY = -3, 00086 ZCONNECTIONLOSS = -4, 00087 ZMARSHALLINGERROR = -5, 00088 ZUNIMPLEMENTED = -6, 00089 ZOPERATIONTIMEOUT = -7, 00090 ZBADARGUMENTS = -8, 00091 ZINVALIDSTATE = -9, 00099 ZAPIERROR = -100, 00100 ZNONODE = -101, 00101 ZNOAUTH = -102, 00102 ZBADVERSION = -103, 00103 ZNOCHILDRENFOREPHEMERALS = -108, 00104 ZNODEEXISTS = -110, 00105 ZNOTEMPTY = -111, 00106 ZSESSIONEXPIRED = -112, 00107 ZINVALIDCALLBACK = -113, 00108 ZINVALIDACL = -114, 00109 ZAUTHFAILED = -115, 00110 ZCLOSING = -116, 00111 ZNOTHING = -117, 00112 ZSESSIONMOVED = -118 00113 }; 00114 00115 #ifdef __cplusplus 00116 extern "C" { 00117 #endif 00118 00122 typedef enum {ZOO_LOG_LEVEL_ERROR=1,ZOO_LOG_LEVEL_WARN=2,ZOO_LOG_LEVEL_INFO=3,ZOO_LOG_LEVEL_DEBUG=4} ZooLogLevel; 00123 00127 extern ZOOAPI const int ZOO_PERM_READ; 00128 extern ZOOAPI const int ZOO_PERM_WRITE; 00129 extern ZOOAPI const int ZOO_PERM_CREATE; 00130 extern ZOOAPI const int ZOO_PERM_DELETE; 00131 extern ZOOAPI const int ZOO_PERM_ADMIN; 00132 extern ZOOAPI const int ZOO_PERM_ALL; 00133 00135 extern ZOOAPI struct Id ZOO_ANYONE_ID_UNSAFE; 00139 extern ZOOAPI struct Id ZOO_AUTH_IDS; 00140 00142 extern ZOOAPI struct ACL_vector ZOO_OPEN_ACL_UNSAFE; 00144 extern ZOOAPI struct ACL_vector ZOO_READ_ACL_UNSAFE; 00146 extern ZOOAPI struct ACL_vector ZOO_CREATOR_ALL_ACL; 00147 00156 // @{ 00157 extern ZOOAPI const int ZOOKEEPER_WRITE; 00158 extern ZOOAPI const int ZOOKEEPER_READ; 00159 // @} 00160 00167 // @{ 00168 extern ZOOAPI const int ZOO_EPHEMERAL; 00169 extern ZOOAPI const int ZOO_SEQUENCE; 00170 // @} 00171 00177 // @{ 00178 extern ZOOAPI const int ZOO_EXPIRED_SESSION_STATE; 00179 extern ZOOAPI const int ZOO_AUTH_FAILED_STATE; 00180 extern ZOOAPI const int ZOO_CONNECTING_STATE; 00181 extern ZOOAPI const int ZOO_ASSOCIATING_STATE; 00182 extern ZOOAPI const int ZOO_CONNECTED_STATE; 00183 // @} 00184 00190 // @{ 00197 extern ZOOAPI const int ZOO_CREATED_EVENT; 00204 extern ZOOAPI const int ZOO_DELETED_EVENT; 00211 extern ZOOAPI const int ZOO_CHANGED_EVENT; 00218 extern ZOOAPI const int ZOO_CHILD_EVENT; 00224 extern ZOOAPI const int ZOO_SESSION_EVENT; 00225 00232 extern ZOOAPI const int ZOO_NOTWATCHING_EVENT; 00233 // @} 00234 00242 typedef struct _zhandle zhandle_t; 00243 00251 typedef struct { 00252 int64_t client_id; 00253 char passwd[16]; 00254 } clientid_t; 00255 00282 typedef void (*watcher_fn)(zhandle_t *zh, int type, 00283 int state, const char *path,void *watcherCtx); 00284 00313 ZOOAPI zhandle_t *zookeeper_init(const char *host, watcher_fn fn, 00314 int recv_timeout, const clientid_t *clientid, void *context, int flags); 00315 00338 ZOOAPI int zookeeper_close(zhandle_t *zh); 00339 00344 ZOOAPI const clientid_t *zoo_client_id(zhandle_t *zh); 00345 00351 ZOOAPI int zoo_recv_timeout(zhandle_t *zh); 00352 00356 ZOOAPI const void *zoo_get_context(zhandle_t *zh); 00357 00361 ZOOAPI void zoo_set_context(zhandle_t *zh, void *context); 00362 00367 ZOOAPI watcher_fn zoo_set_watcher(zhandle_t *zh,watcher_fn newFn); 00368 00369 #ifndef THREADED 00370 00389 ZOOAPI int zookeeper_interest(zhandle_t *zh, int *fd, int *interest, 00390 struct timeval *tv); 00391 00409 ZOOAPI int zookeeper_process(zhandle_t *zh, int events); 00410 #endif 00411 00429 typedef void (*void_completion_t)(int rc, const void *data); 00430 00451 typedef void (*stat_completion_t)(int rc, const struct Stat *stat, 00452 const void *data); 00453 00478 typedef void (*data_completion_t)(int rc, const char *value, int value_len, 00479 const struct Stat *stat, const void *data); 00480 00502 typedef void (*strings_completion_t)(int rc, 00503 const struct String_vector *strings, const void *data); 00504 00530 typedef void (*strings_stat_completion_t)(int rc, 00531 const struct String_vector *strings, const struct Stat *stat, 00532 const void *data); 00533 00552 typedef void 00553 (*string_completion_t)(int rc, const char *value, const void *data); 00554 00578 typedef void (*acl_completion_t)(int rc, struct ACL_vector *acl, 00579 struct Stat *stat, const void *data); 00580 00586 ZOOAPI int zoo_state(zhandle_t *zh); 00587 00620 ZOOAPI int zoo_acreate(zhandle_t *zh, const char *path, const char *value, 00621 int valuelen, const struct ACL_vector *acl, int flags, 00622 string_completion_t completion, const void *data); 00623 00647 ZOOAPI int zoo_adelete(zhandle_t *zh, const char *path, int version, 00648 void_completion_t completion, const void *data); 00649 00671 ZOOAPI int zoo_aexists(zhandle_t *zh, const char *path, int watch, 00672 stat_completion_t completion, const void *data); 00673 00703 ZOOAPI int zoo_awexists(zhandle_t *zh, const char *path, 00704 watcher_fn watcher, void* watcherCtx, 00705 stat_completion_t completion, const void *data); 00706 00727 ZOOAPI int zoo_aget(zhandle_t *zh, const char *path, int watch, 00728 data_completion_t completion, const void *data); 00729 00756 ZOOAPI int zoo_awget(zhandle_t *zh, const char *path, 00757 watcher_fn watcher, void* watcherCtx, 00758 data_completion_t completion, const void *data); 00759 00786 ZOOAPI int zoo_aset(zhandle_t *zh, const char *path, const char *buffer, int buflen, 00787 int version, stat_completion_t completion, const void *data); 00788 00809 ZOOAPI int zoo_aget_children(zhandle_t *zh, const char *path, int watch, 00810 strings_completion_t completion, const void *data); 00811 00838 ZOOAPI int zoo_awget_children(zhandle_t *zh, const char *path, 00839 watcher_fn watcher, void* watcherCtx, 00840 strings_completion_t completion, const void *data); 00841 00864 ZOOAPI int zoo_aget_children2(zhandle_t *zh, const char *path, int watch, 00865 strings_stat_completion_t completion, const void *data); 00866 00895 ZOOAPI int zoo_awget_children2(zhandle_t *zh, const char *path, 00896 watcher_fn watcher, void* watcherCtx, 00897 strings_stat_completion_t completion, const void *data); 00898 00918 ZOOAPI int zoo_async(zhandle_t *zh, const char *path, 00919 string_completion_t completion, const void *data); 00920 00921 00940 ZOOAPI int zoo_aget_acl(zhandle_t *zh, const char *path, acl_completion_t completion, 00941 const void *data); 00942 00965 ZOOAPI int zoo_aset_acl(zhandle_t *zh, const char *path, int version, 00966 struct ACL_vector *acl, void_completion_t, const void *data); 00967 00974 ZOOAPI const char* zerror(int c); 00975 01003 ZOOAPI int zoo_add_auth(zhandle_t *zh,const char* scheme,const char* cert, 01004 int certLen, void_completion_t completion, const void *data); 01005 01014 ZOOAPI int is_unrecoverable(zhandle_t *zh); 01015 01019 ZOOAPI void zoo_set_debug_level(ZooLogLevel logLevel); 01020 01028 ZOOAPI void zoo_set_log_stream(FILE* logStream); 01029 01041 ZOOAPI void zoo_deterministic_conn_order(int yesOrNo); 01042 01080 ZOOAPI int zoo_create(zhandle_t *zh, const char *path, const char *value, 01081 int valuelen, const struct ACL_vector *acl, int flags, 01082 char *path_buffer, int path_buffer_len); 01083 01103 ZOOAPI int zoo_delete(zhandle_t *zh, const char *path, int version); 01104 01105 01124 ZOOAPI int zoo_exists(zhandle_t *zh, const char *path, int watch, struct Stat *stat); 01125 01150 ZOOAPI int zoo_wexists(zhandle_t *zh, const char *path, 01151 watcher_fn watcher, void* watcherCtx, struct Stat *stat); 01152 01173 ZOOAPI int zoo_get(zhandle_t *zh, const char *path, int watch, char *buffer, 01174 int* buffer_len, struct Stat *stat); 01175 01202 ZOOAPI int zoo_wget(zhandle_t *zh, const char *path, 01203 watcher_fn watcher, void* watcherCtx, 01204 char *buffer, int* buffer_len, struct Stat *stat); 01205 01228 ZOOAPI int zoo_set(zhandle_t *zh, const char *path, const char *buffer, 01229 int buflen, int version); 01230 01255 ZOOAPI int zoo_set2(zhandle_t *zh, const char *path, const char *buffer, 01256 int buflen, int version, struct Stat *stat); 01257 01275 ZOOAPI int zoo_get_children(zhandle_t *zh, const char *path, int watch, 01276 struct String_vector *strings); 01277 01301 ZOOAPI int zoo_wget_children(zhandle_t *zh, const char *path, 01302 watcher_fn watcher, void* watcherCtx, 01303 struct String_vector *strings); 01304 01325 ZOOAPI int zoo_get_children2(zhandle_t *zh, const char *path, int watch, 01326 struct String_vector *strings, struct Stat *stat); 01327 01354 ZOOAPI int zoo_wget_children2(zhandle_t *zh, const char *path, 01355 watcher_fn watcher, void* watcherCtx, 01356 struct String_vector *strings, struct Stat *stat); 01357 01374 ZOOAPI int zoo_get_acl(zhandle_t *zh, const char *path, struct ACL_vector *acl, 01375 struct Stat *stat); 01376 01395 ZOOAPI int zoo_set_acl(zhandle_t *zh, const char *path, int version, 01396 const struct ACL_vector *acl); 01397 01398 #ifdef __cplusplus 01399 } 01400 #endif 01401 01402 #endif /*ZOOKEEPER_H_*/