Esempio n. 1
0
void ms_async_process(MediaScan *s) {
  if (s->thread) {
    enum event_type type;
    void *data;

    thread_signal_read(s->thread->respipe);

    // Pull events from the thread's queue, events contain their type
    // and a data pointer (Result/Error/Progress) for that callback
    // A callback may call ms_destroy, so we check for s->thread every time through the loop
    while (s->thread != NULL && (type = thread_get_next_event(s->thread, &data))) {
      LOG_DEBUG("Got thread event, type %d @ %p\n", type, data);
      switch (type) {
        case EVENT_TYPE_RESULT:
          s->on_result(s, (MediaScanResult *)data, s->userdata);
          result_destroy((MediaScanResult *)data);
          break;

        case EVENT_TYPE_PROGRESS:
          s->on_progress(s, (MediaScanProgress *)data, s->userdata);
          progress_destroy((MediaScanProgress *)data);  // freeing a copy of progress
          break;

        case EVENT_TYPE_ERROR:
          s->on_error(s, (MediaScanError *)data, s->userdata);
          error_destroy((MediaScanError *)data);
          break;

        case EVENT_TYPE_FINISH:
          s->on_finish(s, s->userdata);
          break;
      }
    }
  }
}
Esempio n. 2
0
int
main(int argc, char *argv[])
{
    prog_t p;
    int i;

    fprintf(stderr, "foo  ");
    progress_create(&p, 70);
    for (i = 1; i <= 100000000L; i++)
        progress_update(p, (double)i/100000000L);
    progress_destroy(p);
    exit(0);
}
Esempio n. 3
0
File: tst-pro.c Progetto: hfuCN/ltpb
int main(int argc, char *argv[] )
{
        progress_t bar;
        // progress_init(&bar, "", 50, PROGRESS_NUM_STYLE);
        // progress_init(&bar, "", 50, PROGRESS_CHR_STYLE);
        progress_init(&bar, "", 50, PROGRESS_BGC_STYLE);

        int i;
        for (i = 0; i <= 50; i++) {
                progress_show(&bar, i / 50.0f);
                sleep(1);
        }
        printf("\n+-Done\n");

        progress_destroy(&bar);

        return 0;
}
Esempio n. 4
0
void ms_destroy(MediaScan *s) {
  int i;

  if (s->thread) {
    // A thread is running, tell it to abort
    ms_abort(s);

    // thread_destroy will wait until the thread exits cleanly
    thread_destroy(s->thread);
    s->thread = NULL;
  }

  for (i = 0; i < s->npaths; i++) {
    free(s->paths[i]);
  }

  for (i = 0; i < s->nignore_exts; i++) {
    free(s->ignore_exts[i]);
  }

  for (i = 0; i < s->nignore_sdirs; i++) {
    free(s->ignore_sdirs[i]);
  }

  for (i = 0; i < s->nthumbspecs; i++) {
    free(s->thumbspecs[i]);
  }

  progress_destroy(s->progress);

  free(s->_dirq);
  free(s->_dlna);

  if (s->cachedir)
    free(s->cachedir);

  /* When we're done with the database, close it. */
  bdb_destroy(s);

  LOG_MEM("destroy MediaScan @ %p\n", s);
  free(s);
}                               /* ms_destroy() */