ftl_status_t internal_ftl_ingest_destroy()

in libftl/ftl-sdk.c [275:334]


ftl_status_t internal_ftl_ingest_destroy(ftl_stream_configuration_private_t *ftl) {

  if (ftl != NULL) {

    ftl_clear_state(ftl, FTL_STATUS_QUEUE);
    //if a thread is waiting send a destroy event
    if (ftl->status_q.thread_waiting) {
      ftl_status_msg_t status;
      status.type = FTL_STATUS_EVENT;
      status.msg.event.reason = FTL_STATUS_EVENT_REASON_API_REQUEST;
      status.msg.event.type = FTL_STATUS_EVENT_TYPE_DESTROYED;
      status.msg.event.error_code = FTL_SUCCESS;
      enqueue_status_msg(ftl, &status);
    }

    //wait a few ms for the thread to pull that last message and exit
    
    int  wait_retries = 5;
    while (ftl->status_q.thread_waiting && wait_retries-- > 0) {
      sleep_ms(20);
    };

    if (ftl->status_q.thread_waiting) {
      fprintf(stderr, "Thread is still waiting in ftl_ingest_get_status()\n");
    }

    os_lock_mutex(&ftl->status_q.mutex);

    status_queue_elmt_t *elmt;
    while (ftl->status_q.head != NULL) {
      elmt = ftl->status_q.head;
      ftl->status_q.head = elmt->next;
      free(elmt);
      ftl->status_q.count--;
    }

    os_unlock_mutex(&ftl->status_q.mutex);
    os_delete_mutex(&ftl->status_q.mutex);

    os_semaphore_delete(&ftl->status_q.sem);

    ingest_release(ftl);

    if (ftl->key != NULL) {
      free(ftl->key);
    }

    if (ftl->ingest_hostname != NULL) {
      free(ftl->ingest_hostname);
    }

  if (ftl->param_ingest_hostname != NULL) {
    free(ftl->param_ingest_hostname);
  }

    free(ftl);
  }

  return FTL_SUCCESS;
}