Beispiel #1
0
/* this function returns the next available record read
 * if the input_queue (i.e. list of files connected from
 * an external source) or the reader_cqueue (i.e. list
 * of bgpdump currently open) are empty then it
 * triggers a mechanism to populate the queues or
 * return 0 if nothing is available
 */
int bgpstream_get_next_record(bgpstream_t *bs,
                              bgpstream_record_t *record) {
  bgpstream_debug("BS: get next");
  if(bs == NULL || (bs != NULL && bs->status != BGPSTREAM_STATUS_ON)) {
    return -1; // wrong status
  }


  int num_query_results = 0;
  bgpstream_input_t *bs_in = NULL;

  // if bs_record contains an initialized bgpdump entry we destroy it
  bgpstream_record_clear(record);

  while(bgpstream_reader_mgr_is_empty(bs->reader_mgr)) {
    bgpstream_debug("BS: reader mgr is empty");
    // get new data to process and set the reader_mgr
    while(bgpstream_input_mgr_is_empty(bs->input_mgr)) {
      bgpstream_debug("BS: input mgr is empty");
      /* query the external source and append new
       * input objects to the input_mgr queue */
      num_query_results =
        bgpstream_datasource_mgr_update_input_queue(bs->datasource_mgr,
                                                    bs->input_mgr);
      if(num_query_results == 0){
	bgpstream_debug("BS: no (more) data are available");
	return 0; // no (more) data are available
      }
      if(num_query_results < 0){
	bgpstream_debug("BS: error during datasource_mgr_update_input_queue");
	return -1; // error during execution
      }
      bgpstream_debug("BS: got results from datasource");
    }
    bgpstream_debug("BS: input mgr not empty");
    bs_in = bgpstream_input_mgr_get_queue_to_process(bs->input_mgr);
    bgpstream_reader_mgr_add(bs->reader_mgr, bs_in, bs->filter_mgr);
    bgpstream_input_mgr_destroy_queue(bs_in);
    bs_in = NULL;
  }
  bgpstream_debug("BS: reader mgr not empty");
  /* init the record with a pointer to bgpstream */
  record->bs = bs;
  return bgpstream_reader_mgr_get_next_record(bs->reader_mgr, record,
                                              bs->filter_mgr);
}
Beispiel #2
0
/* allocate memory for a bs_record */
bgpstream_record_t *bgpstream_record_create()
{
  bgpstream_debug("BS: create record start");
  bgpstream_record_t *bs_record;
  if ((bs_record = (bgpstream_record_t *)malloc(sizeof(bgpstream_record_t))) ==
      NULL) {
    return NULL; // can't allocate memory
  }

  bs_record->bs = NULL;
  bs_record->bd_entry = NULL;

  if ((bs_record->elem_generator = bgpstream_elem_generator_create()) == NULL) {
    bgpstream_record_destroy(bs_record);
    return NULL;
  }

  bgpstream_record_clear(bs_record);

  bgpstream_debug("BS: create record end");
  return bs_record;
}