ta_identity_t *ta_identity_create(char *name, xt_core_log_t *log) { assert(name); assert(log); ta_identity_t *identity; xt_core_bool_t so_far_so_good; identity = malloc(sizeof *identity); if (identity) { identity->log = log; identity->phrases_qutex = NULL; identity->phrases = NULL; identity->name = xt_core_string_copy(name); if (identity->name) { so_far_so_good = xt_core_bool_true; } else { so_far_so_good = xt_core_bool_false; xt_core_log_trace(log, " ta ", "xt_core_string_copy"); } } else { so_far_so_good = xt_core_bool_false; xt_core_log_trace(log, " ta ", "malloc"); } if (so_far_so_good) { identity->phrases = xt_case_list_create(ta_phrase_compare, ta_phrase_copy, ta_phrase_destroy); if (identity->phrases) { so_far_so_good = xt_core_bool_true; xt_case_list_set_size_limit(identity->phrases, MAX_PHRASES_SIZE); } else { so_far_so_good = xt_core_bool_false; xt_core_log_enter(log, " ta ", "xt_case_list_create"); } } if (so_far_so_good) { identity->phrases_qutex = xt_sync_qutex_create(); if (!identity->phrases_qutex) { so_far_so_good = xt_core_bool_false; xt_core_log_enter(log, " ta ", "xt_sync_qutex_create"); } } if (identity && !so_far_so_good) { if (identity->name) { xt_core_string_destroy(identity->name); } if (identity->phrases) { xt_case_list_destroy(identity->phrases); } if (identity->phrases_qutex) { xt_sync_qutex_destroy(identity->phrases_qutex); } free(identity); identity = NULL; } return identity; }
xt_case_cache_t *xt_case_cache_create(xt_core_object_compare_f compare, xt_core_object_copy_f copy, xt_core_object_destroy_f destroy, xt_core_object_evaluate_condition_f remove_condition) { xt_case_cache_t *cache; xt_core_bool_t so_far_so_good; cache = malloc(sizeof *cache); if (cache) { cache->remove_condition = remove_condition; cache->objects_qutex = NULL; xt_core_iobject_init(&cache->objects_iobject, compare, XT_CORE_OBJECT_NO_COMPARE_EQUAL_F, copy, destroy, XT_CORE_OBJECT_NO_GET_AS_STRING_F, XT_CORE_OBJECT_NO_MOD_F); cache->objects = xt_case_set_create(&cache->objects_iobject); if (cache->objects) { so_far_so_good = xt_core_bool_true; } else { so_far_so_good = xt_core_bool_false; xt_core_trace("x_case_set_create"); } } else { so_far_so_good = xt_core_bool_false; xt_core_trace("malloc() failed"); } if (so_far_so_good) { cache->objects_qutex = xt_sync_qutex_create(); if (!cache->objects_qutex) { so_far_so_good = xt_core_bool_false; xt_core_trace("x_core_qutex_create"); } } if (!so_far_so_good) { if (cache->objects) { xt_case_set_destroy(cache->objects); } if (cache->objects_qutex) { xt_sync_qutex_destroy(cache->objects_qutex); } free(cache); cache = NULL; } return cache; }