You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by mi...@apache.org on 2012/08/30 22:32:54 UTC
svn commit: r1379123 - in /zookeeper/trunk: CHANGES.txt src/c/src/cli.c
Author: michim
Date: Thu Aug 30 20:32:54 2012
New Revision: 1379123
URL: http://svn.apache.org/viewvc?rev=1379123&view=rev
Log:
ZOOKEEPER-1481 allow the C cli to run exists with a watcher (phunt via michim)
Modified:
zookeeper/trunk/CHANGES.txt
zookeeper/trunk/src/c/src/cli.c
Modified: zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1379123&r1=1379122&r2=1379123&view=diff
==============================================================================
--- zookeeper/trunk/CHANGES.txt (original)
+++ zookeeper/trunk/CHANGES.txt Thu Aug 30 20:32:54 2012
@@ -229,6 +229,8 @@ BUGFIXES:
ZOOKEEPER-1536 c client : memory leak in winport.c (brooklin via michim)
+ ZOOKEEPER-1481 allow the C cli to run exists with a watcher (phunt via michim)
+
IMPROVEMENTS:
ZOOKEEPER-1170. Fix compiler (eclipse) warnings: unused imports,
Modified: zookeeper/trunk/src/c/src/cli.c
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/c/src/cli.c?rev=1379123&r1=1379122&r2=1379123&view=diff
==============================================================================
--- zookeeper/trunk/src/c/src/cli.c (original)
+++ zookeeper/trunk/src/c/src/cli.c Thu Aug 30 20:32:54 2012
@@ -84,13 +84,30 @@ static const char* state2String(int stat
return "INVALID_STATE";
}
+static const char* type2String(int state){
+ if (state == ZOO_CREATED_EVENT)
+ return "CREATED_EVENT";
+ if (state == ZOO_DELETED_EVENT)
+ return "DELETED_EVENT";
+ if (state == ZOO_CHANGED_EVENT)
+ return "CHANGED_EVENT";
+ if (state == ZOO_CHILD_EVENT)
+ return "CHILD_EVENT";
+ if (state == ZOO_SESSION_EVENT)
+ return "SESSION_EVENT";
+ if (state == ZOO_NOTWATCHING_EVENT)
+ return "NOTWATCHING_EVENT";
+
+ return "UNKNOWN_EVENT_TYPE";
+}
+
void watcher(zhandle_t *zzh, int type, int state, const char *path,
void* context)
{
/* Be careful using zh here rather than zzh - as this may be mt code
* the client lib may call the watcher before zookeeper_init returns */
- fprintf(stderr, "Watcher %d state = %s", type, state2String(state));
+ fprintf(stderr, "Watcher %s state = %s", type2String(type), state2String(state));
if (path && strlen(path) > 0) {
fprintf(stderr, " for path %s", path);
}
@@ -298,6 +315,7 @@ void processline(char *line) {
fprintf(stderr, " ls2 <path>\n");
fprintf(stderr, " sync <path>\n");
fprintf(stderr, " exists <path>\n");
+ fprintf(stderr, " wexists <path>\n");
fprintf(stderr, " myid\n");
fprintf(stderr, " verbose\n");
fprintf(stderr, " addauth <id> <scheme>\n");
@@ -428,6 +446,23 @@ void processline(char *line) {
if (rc) {
fprintf(stderr, "Error %d for %s\n", rc, line);
}
+ } else if (startsWith(line, "wexists ")) {
+#ifdef THREADED
+ struct Stat stat;
+#endif
+ line += 8;
+ if (line[0] != '/') {
+ fprintf(stderr, "Path must start with /, found: %s\n", line);
+ return;
+ }
+#ifndef THREADED
+ rc = zoo_awexists(zh, line, watcher, (void*) 0, my_stat_completion, strdup(line));
+#else
+ rc = zoo_wexists(zh, line, watcher, (void*) 0, &stat);
+#endif
+ if (rc) {
+ fprintf(stderr, "Error %d for %s\n", rc, line);
+ }
} else if (startsWith(line, "exists ")) {
#ifdef THREADED
struct Stat stat;