xt_core_bool_t ta_identity_talk(ta_identity_t *identity, ta_phrase_t *phrase)
{
    assert(identity);
    assert(phrase);
    xt_core_bool_t success;
    xt_core_bool_t zap;

    if (xt_case_list_get_size(identity->phrases) >= MAX_PHRASES_SIZE) {
        zap = xt_core_bool_true;
    } else {
        zap = xt_core_bool_false;
    }

    xt_sync_qutex_lock_exclusive(identity->phrases_qutex);
    if (zap) {
        xt_case_list_clear(identity->phrases);
    }
    ta_phrase_set_id(phrase, xt_case_list_get_size(identity->phrases));
    if (xt_case_list_add_last(identity->phrases, phrase)) {
        xt_sync_qutex_unlock_exclusive(identity->phrases_qutex);
        success = xt_core_bool_true;
    } else {
        xt_sync_qutex_unlock_exclusive(identity->phrases_qutex);
        xt_core_log_enter(identity->log, " ta ", "xt_case_list_add_last");
        success = xt_core_bool_false;
    }

    return success;
}
Beispiel #2
0
Datei: csv.c Projekt: xtools/xt
xt_case_array_t *create_objects_array(xt_file_csv_t *csv,
    xt_file_basic_t *file, unsigned long start_object,
    unsigned long end_object)
{
  assert(csv);
  assert(file);
  xt_case_array_t *objects_array;
  xt_case_list_t *lines;
  xt_case_array_t *values;
  char *line;
  unsigned long total_object_index;
  unsigned long relative_object_index;
  unsigned long total_object_count;

  objects_array = NULL;

  lines = xt_file_basic_get_as_line_list(file);
  if (lines) {

    total_object_count = xt_case_list_get_size(lines) - 1;
    if ((0 == start_object) && (0 == end_object)) {
      end_object = total_object_count - 1;
    }
    csv->object_count = (end_object - start_object) + 1;

    objects_array = xt_case_array_create(csv->object_count,
        xt_case_array_compare, xt_case_array_copy,
        xt_case_array_destroy);
    if (objects_array) {
      xt_case_list_iterate_start(lines);
      xt_case_list_iterate_next(lines);
      total_object_index = 0;
      relative_object_index = 0;
      while ((line = xt_case_list_iterate_next(lines))) {
        if ((total_object_index >= start_object)
            && (total_object_index <= end_object)) {
          values = xt_case_array_create_strings_from_string(line, ",");
          if (values) {
            xt_case_array_add(objects_array, relative_object_index,
                values);
          } else {
            xt_core_trace("x_case_array_create_strings_from_string");
            xt_case_array_destroy(values);
          }
          relative_object_index++;
        }
        total_object_index++;
      }
    } else {
      xt_core_trace("x_case_array_create");
    }
    xt_case_list_destroy(lines);
  } else {
    xt_core_trace("x_file_basic_get_as_line_list");
  }

  return objects_array;
}
Beispiel #3
0
xt_case_list_t *ta_identity_listen(ta_identity_t *identity,
    unsigned long next_phrase_id)
{
  assert(identity);
  unsigned long i;
  xt_case_list_t *phrases;
  ta_phrase_t *phrase;
  ta_phrase_t *phrase_copy;
  unsigned long phrases_size;

  phrases = xt_case_list_create(ta_phrase_compare, ta_phrase_copy,
      ta_phrase_destroy);
  if (phrases) {
    xt_sync_qutex_lock_shared(identity->phrases_qutex);
    phrases_size = xt_case_list_get_size(identity->phrases);
    check_range_of_next_phrase_id(&next_phrase_id, phrases_size);
    for (i = next_phrase_id; i < phrases_size; i++) {
      phrase = xt_case_list_find_at(identity->phrases, i);
      assert(phrase);
      phrase_copy = ta_phrase_copy(phrase);
      if (phrase_copy) {
        if (!xt_case_list_add_last(phrases, phrase_copy)) {
          xt_core_log_trace(identity->log, " ta ", "xt_case_list_add_last");
          ta_phrase_destroy(phrase_copy);
          break;
        }
      } else {
        xt_core_log_trace(identity->log, " ta ", "ta_phrase_copy");
        break;
      }
    }
    xt_sync_qutex_unlock_shared(identity->phrases_qutex);
  } else {
    xt_core_log_trace(identity->log, " ta ", "xt_case_list_create");
  }

  return phrases;
}
Beispiel #4
0
unsigned long ta_identity_get_size(ta_identity_t *identity)
{
  return xt_case_list_get_size(identity->phrases);
}
Beispiel #5
0
Datei: csv.c Projekt: xtools/xt
xt_case_map_t *create_name_to_index_map(xt_file_csv_t *csv,
    xt_file_basic_t *file)
{
  assert(csv);
  assert(file);
  xt_case_list_t *line_list;
  xt_case_map_t *map;
  xt_case_list_t *field_names;
  char *first_line;
  char *name_object;
  unsigned long index;
  unsigned long *index_object;
  char *name;

  map = NULL;

  line_list = xt_file_basic_get_as_line_list(file);
  if (line_list) {
    first_line = xt_case_list_find_first(line_list);
    if (first_line) {
      field_names = xt_case_list_create_strings_from_string
        (first_line, ",");
      if (field_names) {
        csv->field_count = xt_case_list_get_size(field_names);
        map = xt_case_map_create(&xt_core_objects.string_iobject,
            &xt_core_objects.unsigned_long_iobject, XT_CASE_MAP_DESTROY);
        if (map) {
          index = 0;
          xt_case_list_iterate_start(field_names);
          while ((name = xt_case_list_iterate_next(field_names))) {
            name_object = xt_core_string_copy(name);
            if (name_object) {
              index_object = malloc(sizeof *index_object);
              if (index_object) {
                *index_object = index;
                if (!xt_case_map_add(map, name_object, index_object)) {
                  xt_core_trace("x_case_map_add");
                }
              } else {
                xt_core_trace("malloc");
              }
            } else {
              xt_core_trace("x_core_string_copy");
            }
            index++;
          }
        } else {
          xt_core_trace("x_case_map_create");
        }
        xt_case_list_destroy(field_names);
      } else {
        xt_core_trace("x_case_list_create_strings_from_string");
      }
    } else {
      xt_core_trace("x_case_list_find_first");
    }
    xt_case_list_destroy(line_list);
  } else {
    xt_core_trace("x_file_basic_get_as_line_list");
  }

  return map;
}