CHFSNP_MGR *chfsnp_mgr_create(const uint8_t chfsnp_model, const uint32_t chfsnp_max_num, const uint8_t chfsnp_1st_chash_algo_id, const uint8_t chfsnp_2nd_chash_algo_id, const uint32_t chfsnp_bucket_max_num, const CSTRING *chfsnp_db_root_dir) { CHFSNP_MGR *chfsnp_mgr; uint32_t chfsnp_item_max_num; uint32_t chfsnp_id; if(EC_FALSE == chfsnp_model_item_max_num(chfsnp_model , &chfsnp_item_max_num)) { sys_log(LOGSTDOUT, "error:chfsnp_mgr_create: invalid chfsnp model %u\n", chfsnp_model); return (NULL_PTR); } chfsnp_mgr = chfsnp_mgr_new(); CHFSNP_MGR_NP_MODEL(chfsnp_mgr) = chfsnp_model; CHFSNP_MGR_NP_1ST_CHASH_ALGO_ID(chfsnp_mgr) = chfsnp_1st_chash_algo_id; CHFSNP_MGR_NP_2ND_CHASH_ALGO_ID(chfsnp_mgr) = chfsnp_2nd_chash_algo_id; CHFSNP_MGR_NP_ITEM_MAX_NUM(chfsnp_mgr) = chfsnp_item_max_num; CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr) = chfsnp_max_num; cstring_clone(chfsnp_db_root_dir, CHFSNP_MGR_DB_ROOT_DIR(chfsnp_mgr)); for(chfsnp_id = 0; chfsnp_id < chfsnp_max_num; chfsnp_id ++) { const char *np_root_dir; CHFSNP *chfsnp; np_root_dir = (const char *)cstring_get_str(chfsnp_db_root_dir);/*Oops! int the same dire*/ chfsnp = chfsnp_create(np_root_dir, chfsnp_id, chfsnp_model, chfsnp_1st_chash_algo_id, chfsnp_2nd_chash_algo_id, chfsnp_bucket_max_num); if(NULL_PTR == chfsnp) { sys_log(LOGSTDOUT, "error:chfsnp_mgr_create: create np %u failed\n", chfsnp_id); return (NULL_PTR); } chfsnp_close(chfsnp); cvector_push_no_lock(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr), (void *)NULL_PTR); cvector_push_no_lock(CHFSNP_MGR_NP_VEC(chfsnp_mgr), (void *)NULL_PTR); } if(EC_FALSE == chfsnp_mgr_create_db(chfsnp_mgr, chfsnp_db_root_dir)) { sys_log(LOGSTDOUT, "error:chfsnp_mgr_create: create cfg db failed in root dir %s\n", (char *)cstring_get_str(chfsnp_db_root_dir)); chfsnp_mgr_free(chfsnp_mgr); return (NULL_PTR); } //chfsnp_mgr_free(chfsnp_mgr); return (chfsnp_mgr); }
EC_BOOL chfsnp_mgr_load(CHFSNP_MGR *chfsnp_mgr, const CSTRING *chfsnp_db_root_dir) { cstring_clean(CHFSNP_MGR_DB_ROOT_DIR(chfsnp_mgr)); cstring_clone(chfsnp_db_root_dir, CHFSNP_MGR_DB_ROOT_DIR(chfsnp_mgr)); if(EC_FALSE == chfsnp_mgr_load_db(chfsnp_mgr)) { sys_log(LOGSTDOUT, "error:chfsnp_mgr_load: load cfg db failed from dir %s\n", (char *)cstring_get_str(chfsnp_db_root_dir)); return (EC_FALSE); } return (EC_TRUE); }
EC_BOOL cnetcard_has_macstr(const CSET *cnetcard_set, const CSTRING *macstr) { CNETCARD cnetcard; cnetcard_init(&cnetcard); cstring_clone(macstr, CNETCARD_MACSTR(&cnetcard)); if(NULL_PTR == cset_search(cnetcard_set, (void *)&cnetcard, (CSET_DATA_CMP)cnetcard_cmp_macstr)) { cnetcard_clean(&cnetcard); return (EC_FALSE); } cnetcard_clean(&cnetcard); return (EC_TRUE); }
EC_BOOL cnetcard_has_name(const CSET *cnetcard_set, const CSTRING *name) { CNETCARD cnetcard; cnetcard_init(&cnetcard); cstring_clone(name, CNETCARD_NAME(&cnetcard)); if(NULL_PTR == cset_search(cnetcard_set, (void *)&cnetcard, (CSET_DATA_CMP)cnetcard_cmp_name)) { cnetcard_clean(&cnetcard); return (EC_FALSE); } cnetcard_clean(&cnetcard); return (EC_TRUE); }