예제 #1
0
/*
 * This is where buffered asynchronous commands are
 * processed. Some of them turn directly into timestamped
 * events right here.
 */
static void _run_commands(void)
{
	int d = hold_until - get_time();
	if(labs(d) > 1000)
		hold_until = get_time();
	else if(d > 0)
		return;

	while(sfifo_used(&commands) >= sizeof(command_t))
	{
		command_t cmd;
		if(sfifo_read(&commands, &cmd, (unsigned)sizeof(cmd)) < 0)
		{
			log_printf(ELOG, "audio.c: Engine failure!\n");
			_audio_running = 0;
			return;
		}
		switch(cmd.action)
		{
		  case CMD_STOP:
			DBG2(log_printf(D3LOG, "%d: CMD_STOP\n", get_time());)
			(void)ce_stop(channeltab + cmd.cid, 0, cmd.tag, 32768);
			break;
		  case CMD_STOP_ALL:
			DBG2(log_printf(D3LOG, "%d: CMD_STOP_ALL\n", get_time());)
			channel_stop_all();
			break;
		  case CMD_PLAY:
			DBG2(log_printf(D3LOG, "%d: CMD_PLAY\n", get_time());)
예제 #2
0
파일: classify.c 프로젝트: seangeo/winnow
static int classify_file(ClassificationEngine * engine, const char * tag) {
  ClassificationJob *job = ce_add_classification_job(engine, tag);
  ce_stop(engine);
  if (job->state != CJOB_STATE_COMPLETE) {
    char buffer[512];
    cjob_error_msg(job, buffer, 512);
    printf("Job not complete: %s\n", buffer);
    return EXIT_FAILURE;
  }
  
  return EXIT_SUCCESS;
}
} END_TEST

START_TEST(resuming_suspended_engine_processes_jobs) {
  ce_add_classification_job(ce, TAG_ID);
  ce_add_classification_job(ce, TAG_ID);
  assert_equal(2, ce_num_waiting_jobs(ce));
  int suspended = ce_suspend(ce);
  assert_true(suspended);
  ce_start(ce);
  ce_resume(ce);
  ce_stop(ce);
  assert_equal(0, ce_num_waiting_jobs(ce));
} END_TEST
} END_TEST

START_TEST(cancelling_a_job_removes_it_from_the_system_once_a_worker_gets_to_it) {
  ClassificationJob *job = ce_add_classification_job(ce, TAG_ID);
  char job_id[64];
  strncpy(job_id, job->id, 64);

  assert_equal(1, ce_num_waiting_jobs(ce));
  cjob_cancel(job);
  assert_equal(1, ce_num_waiting_jobs(ce));
  ce_start(ce);
  sleep(1);
  ce_stop(ce);
  assert_equal(0, ce_num_waiting_jobs(ce));
  assert_equal(0, ce_num_jobs_in_system(ce));

  ClassificationJob *j2 = ce_fetch_classification_job(ce, job_id);
  assert_null(j2);
} END_TEST
} END_TEST

START_TEST(test_engine_starting_and_stopping) {
  ItemCache *item_cache;
  item_cache_create(&item_cache, "/tmp/valid-copy", &item_cache_options);
  item_cache_load(item_cache);
  tagger_cache = create_tagger_cache(item_cache, NULL);

  ClassificationEngine *engine = create_classification_engine(item_cache, tagger_cache, &opts);
  assert_not_null(engine);
  int start_code = ce_start(engine);
  assert_equal(1, start_code);
  assert_true(ce_is_running(engine));
  assert_equal(0, ce_num_jobs_in_system(engine));
  int stop_code = ce_stop(engine);
  assert_equal(1, stop_code);
  assert_false(ce_is_running(engine));
  free_classification_engine(engine);
} END_TEST
예제 #6
0
파일: classify.c 프로젝트: seangeo/winnow
static int classify_directory(ClassificationEngine * engine, const char * directory) {
  struct dirent **entries;  
  int num_entries = scandir(directory, &entries, select_atom_files, alphasort);
  
  if (num_entries > -1) {
    int i;    
    
    for (i = 0; i < num_entries; i++) {
      char buffer[MAXPATHLEN];
      snprintf(buffer, MAXPATHLEN, "file:%s/%s", directory, entries[i]->d_name);
      ce_add_classification_job(engine, buffer);
      free(entries[i]);
    }
    free(entries);
    ce_stop(engine);
    
    return EXIT_SUCCESS;
  }
  
  return EXIT_FAILURE;
}