tier2_message::state_change tier2_message::handle_state_change(tier2_message::request_state_t new_state) { state_change rv = PROCEED; /* we copy the handler list before traversing it as the list may change as a 'side effect' of invoking the handler->process() method! */ state_change_handler_set_t h_set(m_state_change_handlers); for (size_t i = 0; i < h_set.size(); i++) { tier2_message_state_change_handler *h = h_set[i]; assert(h); switch (h->process(*this, new_state)) { default: case ERROR_OCCURRED: rv = ERROR_OCCURRED; break; case DONT_CHANGE: rv = DONT_CHANGE; break; case PROCEED: continue; } break; } return rv; }
Symbol intern(const char *str) { Symbol symbol = (Symbol)h_get(symbol_table, str); if (!symbol) { symbol = (Symbol)estrdup(str); h_set(symbol_table, (void *)symbol, (void *)symbol); } return symbol; }
Symbol intern_and_free(char *str) { Symbol symbol = (Symbol)h_get(symbol_table, str); if (!symbol) { symbol = (Symbol)str; h_set(symbol_table, str, str); } else { free(str); } return symbol; }
static OutStream *ram_new_output(Store *store, const char *filename) { RAMFile *rf = (RAMFile *)h_get(store->dir.ht, filename); OutStream *os = os_new(); if (rf == NULL) { rf = rf_new(filename); h_set(store->dir.ht, rf->name, rf); } REF(rf); os->pointer = 0; os->file.rf = rf; os->m = &RAM_OUT_STREAM_METHODS; return os; }
static void ram_rename(Store *store, const char *from, const char *to) { RAMFile *rf = (RAMFile *)h_rem(store->dir.ht, from, false); RAMFile *tmp; if (rf == NULL) { RAISE(IO_ERROR, "couldn't rename \"%s\" to \"%s\". \"%s\"" " doesn't exist", from, to, from); } free(rf->name); rf->name = estrdup(to); /* clean up the file we are overwriting */ tmp = (RAMFile *)h_get(store->dir.ht, to); if (tmp != NULL) { DEREF(tmp); } h_set(store->dir.ht, rf->name, rf); }
Hash *h_clone(Hash *self, h_clone_ft clone_key, h_clone_ft clone_value) { void *key, *value; HashEntry *he; int i = self->size; Hash *ht_clone; ht_clone = h_new(self->hash_i, self->eq_i, self->free_key_i, self->free_value_i); for (he = self->table; i > 0; he++) { if (he->key && he->key != dummy_key) { /* active entry */ key = clone_key ? clone_key(he->key) : he->key; value = clone_value ? clone_value(he->value) : he->value; h_set(ht_clone, key, value); i--; } } return ht_clone; }
Store *open_fs_store(const char *pathname) { Store *store = NULL; mutex_lock(&stores_mutex); if (!stores) { stores = h_new_str(NULL, (free_ft)fs_destroy); register_for_cleanup(stores, (free_ft)h_destroy); } store = (Store *)h_get(stores, pathname); if (store) { mutex_lock(&store->mutex); store->ref_cnt++; mutex_unlock(&store->mutex); } else { store = fs_store_new(pathname); h_set(stores, store->dir.path, store); } mutex_unlock(&stores_mutex); return store; }
Store *open_cmpd_store(Store *store, const char *name) { int count, i; off_t offset; char *fname; FileEntry *entry = NULL; Store *new_store = NULL; CompoundStore *volatile cmpd = NULL; InStream *volatile is = NULL; TRY cmpd = ALLOC_AND_ZERO(CompoundStore); cmpd->store = store; cmpd->name = name; cmpd->entries = h_new_str(&free, &free); is = cmpd->stream = store->open_input(store, cmpd->name); /* read the directory and init files */ count = is_read_vint(is); entry = NULL; for (i = 0; i < count; i++) { offset = (off_t)is_read_i64(is); fname = is_read_string(is); if (entry != NULL) { /* set length of the previous entry */ entry->length = offset - entry->offset; } entry = ALLOC(FileEntry); entry->offset = offset; h_set(cmpd->entries, fname, entry); } XCATCHALL if (is) is_close(is); if (cmpd->entries) h_destroy(cmpd->entries); free(cmpd); XENDTRY /* set the length of the final entry */ if (entry != NULL) { entry->length = is_length(is) - entry->offset; } new_store = store_new(); new_store->dir.cmpd = cmpd; new_store->touch = &cmpd_touch; new_store->exists = &cmpd_exists; new_store->remove = &cmpd_remove; new_store->rename = &cmpd_rename; new_store->count = &cmpd_count; new_store->clear = &cmpd_clear; new_store->length = &cmpd_length; new_store->each = &cmpd_each; new_store->close_i = &cmpd_close_i; new_store->new_output = &cmpd_new_output; new_store->open_input = &cmpd_open_input; new_store->open_lock_i = &cmpd_open_lock_i; new_store->close_lock_i = &cmpd_close_lock_i; return new_store; }
static void ram_touch(Store *store, const char *filename) { if (h_get(store->dir.ht, filename) == NULL) { h_set(store->dir.ht, filename, rf_new(filename)); } }