static int on_accepted(const struct jbxm_initconf_st* iconf, struct jbxm_callback_if_st* cbif) { assert(iconf); assert(cbif); assert(cbif->type == JBXM_CBT_ACCEPTED); bool success = false; struct UserData_st* ud = calloc(1, sizeof(struct UserData_st)); if (! ud) { fprintf(stderr, "error: calloc (errno=%d)\n", errno); goto EXIT_LABEL; } // set ud members ud->headers = hm_init(19); if (! ud->headers) { fprintf(stderr, "error: hm_init\n"); goto EXIT_LABEL; } ud->body_chunks = ll_init(free_varmem); if (! ud->body_chunks) { fprintf(stderr, "error: ll_init\n"); goto EXIT_LABEL; } // save to memory dbSET0(cbif, "user-data", ud); success = true; EXIT_LABEL: if (! success) { if (ud) { hm_free(ud->headers); ll_free(ud->body_chunks); free(ud); } return -1; } return 0; }
int main(void) { // watchdog is still enabled after a software reset and needs to be cleared immediately MCUSR = 0; wdt_disable(); //uart_init(UART_BAUD_SELECT_DOUBLE_SPEED(57600, F_CPU)); buttons_leds_init(); dimmer_init(); hm_init(); sei(); while(1) { hm_task(); } }
static int cbif_service_db_set_(void* cbif_handle, const char* key, void* val, void** old_val) { if (cbif_handle && key) { struct connection_st* conn = cbif_handle; if (! conn->db) { conn->db = hm_init(0); if (! conn->db) { return -1; } } return hm_set(conn->db, key, val, old_val); } return -1; }
int rehash ( hashmap_t *oldhm ) { int curfactor = 1; int i; hashmap_t *newhm; entry_t *tmp; curfactor = oldhm->capacity / INITIAL_SIZE; newhm = hm_init ( ++curfactor ); for ( i = 0; i < oldhm->capacity; i++ ) { if ( oldhm->buckets[i] != NULL ) { tmp = oldhm->buckets[i]->entries; do { hm_set ( newhm, tmp->key, tmp->value ); } while ( ( tmp = tmp->next ) != NULL ); } } return EXIT_SUCCESS; }