watcher_object_list_t *collectWatchers(zhandle_t *zh,int type, char *path) { struct watcher_object_list *list = create_watcher_object_list(0); if(type==ZOO_SESSION_EVENT) { watcher_object_t defWatcher; defWatcher.watcher=zh->watcher; defWatcher.context=zh->context; add_to_list(&list, &defWatcher, 1); collect_session_watchers(zh, &list); return list; } switch(type) { case CREATED_EVENT_DEF: case CHANGED_EVENT_DEF: // look up the watchers for the path and move them to a delivery list add_for_event(zh->active_node_watchers,path,&list); add_for_event(zh->active_exist_watchers,path,&list); break; case CHILD_EVENT_DEF: // look up the watchers for the path and move them to a delivery list add_for_event(zh->active_child_watchers,path,&list); break; case DELETED_EVENT_DEF: // look up the watchers for the path and move them to a delivery list add_for_event(zh->active_node_watchers,path,&list); add_for_event(zh->active_exist_watchers,path,&list); add_for_event(zh->active_child_watchers,path,&list); break; } return list; }
static int do_insert_watcher_object(zk_hashtable *ht, const char *path, watcher_object_t* wo) { int res=1; watcher_object_list_t* wl; wl=hashtable_search(ht->ht,(void*)path); if(wl==0) { int res; /* inserting a new path element */ res=hashtable_insert(ht->ht,strdup(path),create_watcher_object_list(wo)); assert(res); } else { /* path already exists; check if the watcher already exists */ res = add_to_list(&wl, wo, 1); } return res; }
static int do_insert_watcher_object(zk_hashtable *ht, const char *path, watcher_object_t* wo) { int res=1; watcher_object_list_t* wl; wl=hashtable_search(ht->ht,(void*)path); if(wl==0){ int res; /* inserting a new path element */ res=hashtable_insert(ht->ht,strdup(path),create_watcher_object_list(wo)); assert(res); }else{ /* * Path already exists; check if the watcher already exists. * Don't clone the watcher since it's allocated on the heap --- avoids * a memory leak and saves a clone operation (calloc + copy). */ res = add_to_list(&wl, wo, 0); } return res; }