From f09487681cbd5254a7eeda93efccb0cc9107057a Mon Sep 17 00:00:00 2001 From: Mike Smith Date: Thu, 20 Nov 2014 17:27:19 +0000 Subject: realised that states are sub of type, corrected watcher issues --- ZKTest/Debug/ZKTest | Bin 91991 -> 92551 bytes ZKTest/Debug/src/ZKTest.o | Bin 181256 -> 183264 bytes ZKTest/src/ZKTest.cpp | 82 ++++++++++++++++++++++++++++++++-------------- 3 files changed, 57 insertions(+), 25 deletions(-) (limited to 'ZKTest') diff --git a/ZKTest/Debug/ZKTest b/ZKTest/Debug/ZKTest index 1abce8b..c9ff7aa 100755 Binary files a/ZKTest/Debug/ZKTest and b/ZKTest/Debug/ZKTest differ diff --git a/ZKTest/Debug/src/ZKTest.o b/ZKTest/Debug/src/ZKTest.o index f4c4187..c0a0ed1 100644 Binary files a/ZKTest/Debug/src/ZKTest.o and b/ZKTest/Debug/src/ZKTest.o differ diff --git a/ZKTest/src/ZKTest.cpp b/ZKTest/src/ZKTest.cpp index 05691ba..7e22c21 100644 --- a/ZKTest/src/ZKTest.cpp +++ b/ZKTest/src/ZKTest.cpp @@ -71,9 +71,46 @@ void safeShutdown(zhandle_t *zzh) } } + +static const char* state2String(int state) +{ + if (state == 0) + return "CLOSED_STATE"; + if (state == ZOO_CONNECTING_STATE) + return "CONNECTING_STATE"; + if (state == ZOO_ASSOCIATING_STATE) + return "ASSOCIATING_STATE"; + if (state == ZOO_CONNECTED_STATE) + return "CONNECTED_STATE"; + if (state == ZOO_EXPIRED_SESSION_STATE) + return "EXPIRED_SESSION_STATE"; + if (state == ZOO_AUTH_FAILED_STATE) + return "AUTH_FAILED_STATE"; + + return "INVALID_STATE"; +} + +static const char* type2String(int type) +{ + if (type == ZOO_CREATED_EVENT) + return "CREATED_EVENT"; + if (type == ZOO_DELETED_EVENT) + return "DELETED_EVENT"; + if (type == ZOO_CHANGED_EVENT) + return "CHANGED_EVENT"; + if (type == ZOO_CHILD_EVENT) + return "CHILD_EVENT"; + if (type == ZOO_SESSION_EVENT) + return "SESSION_EVENT"; + if (type == ZOO_NOTWATCHING_EVENT) + return "NOTWATCHING_EVENT"; + + return "UNKNOWN_EVENT_TYPE"; +} void watcher(zhandle_t *zzh, int type, int state, const char *path, void *watcherCtx) { + cout << "New event incoming: " << type2String(type) << " " << state2String(state) << " " << path << endl; if (type == ZOO_SESSION_EVENT) { if (state == ZOO_CONNECTED_STATE) @@ -95,47 +132,42 @@ void watcher(zhandle_t *zzh, int type, int state, const char *path, std::cout<count; i++) { std::cout<count<data[i] , true, NULL); + responseCode = zoo_get_children(zk, path + '/' + *list_of_children->data[i] , true, NULL); } } + } + else if (type == ZOO_CHANGED_EVENT) + { + responseCode = zoo_exists(zk, path, true, NULL); + std::cout<