zookeeper-3.4.2
|
00001 00019 #ifndef ZOOKEEPER_H_ 00020 #define ZOOKEEPER_H_ 00021 00022 #include <stdlib.h> 00023 #ifndef WIN32 00024 #include <sys/socket.h> 00025 #include <sys/time.h> 00026 #else 00027 #include "winconfig.h" 00028 #endif 00029 #include <stdio.h> 00030 #include <ctype.h> 00031 00032 #include "proto.h" 00033 #include "zookeeper_version.h" 00034 #include "recordio.h" 00035 #include "zookeeper.jute.h" 00036 00065 /* Support for building on various platforms */ 00066 00067 // on cygwin we should take care of exporting/importing symbols properly 00068 #ifdef DLL_EXPORT 00069 # define ZOOAPI __declspec(dllexport) 00070 #else 00071 # if (defined(__CYGWIN__) || defined(WIN32)) && !defined(USE_STATIC_LIB) 00072 # define ZOOAPI __declspec(dllimport) 00073 # else 00074 # define ZOOAPI 00075 # endif 00076 #endif 00077 00080 enum ZOO_ERRORS { 00081 ZOK = 0, 00087 ZSYSTEMERROR = -1, 00088 ZRUNTIMEINCONSISTENCY = -2, 00089 ZDATAINCONSISTENCY = -3, 00090 ZCONNECTIONLOSS = -4, 00091 ZMARSHALLINGERROR = -5, 00092 ZUNIMPLEMENTED = -6, 00093 ZOPERATIONTIMEOUT = -7, 00094 ZBADARGUMENTS = -8, 00095 ZINVALIDSTATE = -9, 00103 ZAPIERROR = -100, 00104 ZNONODE = -101, 00105 ZNOAUTH = -102, 00106 ZBADVERSION = -103, 00107 ZNOCHILDRENFOREPHEMERALS = -108, 00108 ZNODEEXISTS = -110, 00109 ZNOTEMPTY = -111, 00110 ZSESSIONEXPIRED = -112, 00111 ZINVALIDCALLBACK = -113, 00112 ZINVALIDACL = -114, 00113 ZAUTHFAILED = -115, 00114 ZCLOSING = -116, 00115 ZNOTHING = -117, 00116 ZSESSIONMOVED = -118 00117 }; 00118 00119 #ifdef __cplusplus 00120 extern "C" { 00121 #endif 00122 00126 typedef enum {ZOO_LOG_LEVEL_ERROR=1,ZOO_LOG_LEVEL_WARN=2,ZOO_LOG_LEVEL_INFO=3,ZOO_LOG_LEVEL_DEBUG=4} ZooLogLevel; 00127 00131 extern ZOOAPI const int ZOO_PERM_READ; 00132 extern ZOOAPI const int ZOO_PERM_WRITE; 00133 extern ZOOAPI const int ZOO_PERM_CREATE; 00134 extern ZOOAPI const int ZOO_PERM_DELETE; 00135 extern ZOOAPI const int ZOO_PERM_ADMIN; 00136 extern ZOOAPI const int ZOO_PERM_ALL; 00137 00139 extern ZOOAPI struct Id ZOO_ANYONE_ID_UNSAFE; 00143 extern ZOOAPI struct Id ZOO_AUTH_IDS; 00144 00146 extern ZOOAPI struct ACL_vector ZOO_OPEN_ACL_UNSAFE; 00148 extern ZOOAPI struct ACL_vector ZOO_READ_ACL_UNSAFE; 00150 extern ZOOAPI struct ACL_vector ZOO_CREATOR_ALL_ACL; 00151 00160 // @{ 00161 extern ZOOAPI const int ZOOKEEPER_WRITE; 00162 extern ZOOAPI const int ZOOKEEPER_READ; 00163 // @} 00164 00171 // @{ 00172 extern ZOOAPI const int ZOO_EPHEMERAL; 00173 extern ZOOAPI const int ZOO_SEQUENCE; 00174 // @} 00175 00181 // @{ 00182 extern ZOOAPI const int ZOO_EXPIRED_SESSION_STATE; 00183 extern ZOOAPI const int ZOO_AUTH_FAILED_STATE; 00184 extern ZOOAPI const int ZOO_CONNECTING_STATE; 00185 extern ZOOAPI const int ZOO_ASSOCIATING_STATE; 00186 extern ZOOAPI const int ZOO_CONNECTED_STATE; 00187 // @} 00188 00194 // @{ 00201 extern ZOOAPI const int ZOO_CREATED_EVENT; 00208 extern ZOOAPI const int ZOO_DELETED_EVENT; 00215 extern ZOOAPI const int ZOO_CHANGED_EVENT; 00222 extern ZOOAPI const int ZOO_CHILD_EVENT; 00228 extern ZOOAPI const int ZOO_SESSION_EVENT; 00229 00236 extern ZOOAPI const int ZOO_NOTWATCHING_EVENT; 00237 // @} 00238 00246 typedef struct _zhandle zhandle_t; 00247 00255 typedef struct { 00256 int64_t client_id; 00257 char passwd[16]; 00258 } clientid_t; 00259 00269 typedef struct zoo_op { 00270 int type; 00271 union { 00272 // CREATE 00273 struct { 00274 const char *path; 00275 const char *data; 00276 int datalen; 00277 char *buf; 00278 int buflen; 00279 const struct ACL_vector *acl; 00280 int flags; 00281 } create_op; 00282 00283 // DELETE 00284 struct { 00285 const char *path; 00286 int version; 00287 } delete_op; 00288 00289 // SET 00290 struct { 00291 const char *path; 00292 const char *data; 00293 int datalen; 00294 int version; 00295 struct Stat *stat; 00296 } set_op; 00297 00298 // CHECK 00299 struct { 00300 const char *path; 00301 int version; 00302 } check_op; 00303 }; 00304 } zoo_op_t; 00305 00330 void zoo_create_op_init(zoo_op_t *op, const char *path, const char *value, 00331 int valuelen, const struct ACL_vector *acl, int flags, 00332 char *path_buffer, int path_buffer_len); 00333 00346 void zoo_delete_op_init(zoo_op_t *op, const char *path, int version); 00347 00363 void zoo_set_op_init(zoo_op_t *op, const char *path, const char *buffer, 00364 int buflen, int version, struct Stat *stat); 00365 00377 void zoo_check_op_init(zoo_op_t *op, const char *path, int version); 00378 00385 typedef struct zoo_op_result { 00386 int err; 00387 char *value; 00388 int valuelen; 00389 struct Stat *stat; 00390 } zoo_op_result_t; 00391 00418 typedef void (*watcher_fn)(zhandle_t *zh, int type, 00419 int state, const char *path,void *watcherCtx); 00420 00449 ZOOAPI zhandle_t *zookeeper_init(const char *host, watcher_fn fn, 00450 int recv_timeout, const clientid_t *clientid, void *context, int flags); 00451 00474 ZOOAPI int zookeeper_close(zhandle_t *zh); 00475 00480 ZOOAPI const clientid_t *zoo_client_id(zhandle_t *zh); 00481 00487 ZOOAPI int zoo_recv_timeout(zhandle_t *zh); 00488 00492 ZOOAPI const void *zoo_get_context(zhandle_t *zh); 00493 00497 ZOOAPI void zoo_set_context(zhandle_t *zh, void *context); 00498 00503 ZOOAPI watcher_fn zoo_set_watcher(zhandle_t *zh,watcher_fn newFn); 00504 00510 ZOOAPI struct sockaddr* zookeeper_get_connected_host(zhandle_t *zh, 00511 struct sockaddr *addr, socklen_t *addr_len); 00512 00513 #ifndef THREADED 00514 00533 #ifdef WIN32 00534 ZOOAPI int zookeeper_interest(zhandle_t *zh, SOCKET *fd, int *interest, 00535 struct timeval *tv); 00536 #else 00537 ZOOAPI int zookeeper_interest(zhandle_t *zh, int *fd, int *interest, 00538 struct timeval *tv); 00539 #endif 00540 00558 ZOOAPI int zookeeper_process(zhandle_t *zh, int events); 00559 #endif 00560 00578 typedef void (*void_completion_t)(int rc, const void *data); 00579 00600 typedef void (*stat_completion_t)(int rc, const struct Stat *stat, 00601 const void *data); 00602 00627 typedef void (*data_completion_t)(int rc, const char *value, int value_len, 00628 const struct Stat *stat, const void *data); 00629 00651 typedef void (*strings_completion_t)(int rc, 00652 const struct String_vector *strings, const void *data); 00653 00679 typedef void (*strings_stat_completion_t)(int rc, 00680 const struct String_vector *strings, const struct Stat *stat, 00681 const void *data); 00682 00701 typedef void 00702 (*string_completion_t)(int rc, const char *value, const void *data); 00703 00727 typedef void (*acl_completion_t)(int rc, struct ACL_vector *acl, 00728 struct Stat *stat, const void *data); 00729 00735 ZOOAPI int zoo_state(zhandle_t *zh); 00736 00769 ZOOAPI int zoo_acreate(zhandle_t *zh, const char *path, const char *value, 00770 int valuelen, const struct ACL_vector *acl, int flags, 00771 string_completion_t completion, const void *data); 00772 00796 ZOOAPI int zoo_adelete(zhandle_t *zh, const char *path, int version, 00797 void_completion_t completion, const void *data); 00798 00820 ZOOAPI int zoo_aexists(zhandle_t *zh, const char *path, int watch, 00821 stat_completion_t completion, const void *data); 00822 00852 ZOOAPI int zoo_awexists(zhandle_t *zh, const char *path, 00853 watcher_fn watcher, void* watcherCtx, 00854 stat_completion_t completion, const void *data); 00855 00876 ZOOAPI int zoo_aget(zhandle_t *zh, const char *path, int watch, 00877 data_completion_t completion, const void *data); 00878 00905 ZOOAPI int zoo_awget(zhandle_t *zh, const char *path, 00906 watcher_fn watcher, void* watcherCtx, 00907 data_completion_t completion, const void *data); 00908 00935 ZOOAPI int zoo_aset(zhandle_t *zh, const char *path, const char *buffer, int buflen, 00936 int version, stat_completion_t completion, const void *data); 00937 00958 ZOOAPI int zoo_aget_children(zhandle_t *zh, const char *path, int watch, 00959 strings_completion_t completion, const void *data); 00960 00987 ZOOAPI int zoo_awget_children(zhandle_t *zh, const char *path, 00988 watcher_fn watcher, void* watcherCtx, 00989 strings_completion_t completion, const void *data); 00990 01013 ZOOAPI int zoo_aget_children2(zhandle_t *zh, const char *path, int watch, 01014 strings_stat_completion_t completion, const void *data); 01015 01044 ZOOAPI int zoo_awget_children2(zhandle_t *zh, const char *path, 01045 watcher_fn watcher, void* watcherCtx, 01046 strings_stat_completion_t completion, const void *data); 01047 01067 ZOOAPI int zoo_async(zhandle_t *zh, const char *path, 01068 string_completion_t completion, const void *data); 01069 01070 01089 ZOOAPI int zoo_aget_acl(zhandle_t *zh, const char *path, acl_completion_t completion, 01090 const void *data); 01091 01114 ZOOAPI int zoo_aset_acl(zhandle_t *zh, const char *path, int version, 01115 struct ACL_vector *acl, void_completion_t, const void *data); 01116 01133 ZOOAPI int zoo_amulti(zhandle_t *zh, int count, const zoo_op_t *ops, 01134 zoo_op_result_t *results, void_completion_t, const void *data); 01135 01142 ZOOAPI const char* zerror(int c); 01143 01171 ZOOAPI int zoo_add_auth(zhandle_t *zh,const char* scheme,const char* cert, 01172 int certLen, void_completion_t completion, const void *data); 01173 01182 ZOOAPI int is_unrecoverable(zhandle_t *zh); 01183 01187 ZOOAPI void zoo_set_debug_level(ZooLogLevel logLevel); 01188 01196 ZOOAPI void zoo_set_log_stream(FILE* logStream); 01197 01209 ZOOAPI void zoo_deterministic_conn_order(int yesOrNo); 01210 01248 ZOOAPI int zoo_create(zhandle_t *zh, const char *path, const char *value, 01249 int valuelen, const struct ACL_vector *acl, int flags, 01250 char *path_buffer, int path_buffer_len); 01251 01271 ZOOAPI int zoo_delete(zhandle_t *zh, const char *path, int version); 01272 01273 01292 ZOOAPI int zoo_exists(zhandle_t *zh, const char *path, int watch, struct Stat *stat); 01293 01318 ZOOAPI int zoo_wexists(zhandle_t *zh, const char *path, 01319 watcher_fn watcher, void* watcherCtx, struct Stat *stat); 01320 01341 ZOOAPI int zoo_get(zhandle_t *zh, const char *path, int watch, char *buffer, 01342 int* buffer_len, struct Stat *stat); 01343 01370 ZOOAPI int zoo_wget(zhandle_t *zh, const char *path, 01371 watcher_fn watcher, void* watcherCtx, 01372 char *buffer, int* buffer_len, struct Stat *stat); 01373 01396 ZOOAPI int zoo_set(zhandle_t *zh, const char *path, const char *buffer, 01397 int buflen, int version); 01398 01423 ZOOAPI int zoo_set2(zhandle_t *zh, const char *path, const char *buffer, 01424 int buflen, int version, struct Stat *stat); 01425 01443 ZOOAPI int zoo_get_children(zhandle_t *zh, const char *path, int watch, 01444 struct String_vector *strings); 01445 01469 ZOOAPI int zoo_wget_children(zhandle_t *zh, const char *path, 01470 watcher_fn watcher, void* watcherCtx, 01471 struct String_vector *strings); 01472 01493 ZOOAPI int zoo_get_children2(zhandle_t *zh, const char *path, int watch, 01494 struct String_vector *strings, struct Stat *stat); 01495 01522 ZOOAPI int zoo_wget_children2(zhandle_t *zh, const char *path, 01523 watcher_fn watcher, void* watcherCtx, 01524 struct String_vector *strings, struct Stat *stat); 01525 01542 ZOOAPI int zoo_get_acl(zhandle_t *zh, const char *path, struct ACL_vector *acl, 01543 struct Stat *stat); 01544 01563 ZOOAPI int zoo_set_acl(zhandle_t *zh, const char *path, int version, 01564 const struct ACL_vector *acl); 01565 01577 ZOOAPI int zoo_multi(zhandle_t *zh, int count, const zoo_op_t *ops, zoo_op_result_t *results); 01578 01579 #ifdef __cplusplus 01580 } 01581 #endif 01582 01583 #endif /*ZOOKEEPER_H_*/