From a75fff7251f44c334b492350316a46a11755d490 Mon Sep 17 00:00:00 2001 From: Mike Smith Date: Mon, 24 Nov 2014 11:44:15 +0000 Subject: added recursive child discovery to the system infinate levels may now be discovered correctly --- ZKTest/.cproject | 7 ++++- ZKTest/Debug/ZKTest | Bin 92551 -> 132947 bytes ZKTest/Debug/src/ZKTest.o | Bin 183264 -> 250712 bytes ZKTest/Debug/src/subdir.mk | 2 +- ZKTest/src/ZKTest.cpp | 77 +++++++++++++++++++++++++++++++-------------- 5 files changed, 61 insertions(+), 25 deletions(-) diff --git a/ZKTest/.cproject b/ZKTest/.cproject index 4f3143f..ca9760d 100644 --- a/ZKTest/.cproject +++ b/ZKTest/.cproject @@ -26,6 +26,10 @@ + @@ -101,7 +105,7 @@ - @@ -155,4 +159,5 @@ + diff --git a/ZKTest/Debug/ZKTest b/ZKTest/Debug/ZKTest index c9ff7aa..be25bfa 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 c0a0ed1..df5a147 100644 Binary files a/ZKTest/Debug/src/ZKTest.o and b/ZKTest/Debug/src/ZKTest.o differ diff --git a/ZKTest/Debug/src/subdir.mk b/ZKTest/Debug/src/subdir.mk index 3451882..4bbeba4 100644 --- a/ZKTest/Debug/src/subdir.mk +++ b/ZKTest/Debug/src/subdir.mk @@ -17,7 +17,7 @@ CPP_DEPS += \ src/%.o: ../src/%.cpp @echo 'Building file: $<' @echo 'Invoking: GCC C++ Compiler' - g++ -I/usr/include/zookeeper -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" + g++ -D__GXX_EXPERIMENTAL_CXX0X__ -I/usr/include/zookeeper -O0 -g3 -Wall -c -fmessage-length=0 -std=c++0x -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" @echo 'Finished building: $<' @echo ' ' diff --git a/ZKTest/src/ZKTest.cpp b/ZKTest/src/ZKTest.cpp index 7e22c21..7fd87a0 100644 --- a/ZKTest/src/ZKTest.cpp +++ b/ZKTest/src/ZKTest.cpp @@ -7,6 +7,8 @@ //============================================================================ #include +#include +#include #include #include #include @@ -18,13 +20,15 @@ using namespace std; static zhandle_t *zk; static const clientid_t *session_id; -struct String_vector *list_of_children; +struct String_vector list_of_children = {0}; int timeout = 3000; int responseCode = 0; +std::mutex mutex_lock; void safeShutdown(zhandle_t *zzh); void watcher(zhandle_t *zzh, int type, int state, const char *path, void *watcherCtx); +void discoverChildren(const char* path); int main(int argc, char **argv) { @@ -49,10 +53,20 @@ int main(int argc, char **argv) while (zk) { - + /* + * mutex used to make the main program loop wait until there is feedback + * from zookeeper. initially locks, then loops around. thread cannot lock + * again until the current lock has been unlocked. + */ + mutex_lock.lock(); + + /* + * debug test to show that the loop does not continue until watcher + * is called + */ + std::cout<<"loop locked"<count; i++) - { - std::cout<count<data[i] , true, NULL); - } - } + std::cout<