void reconstruct() {
	holger_time_start(1, "Reconstruction");

	memset(volume, 0, sizeof(unsigned char)*volume_w*volume_h*volume_n);

	printf("bscan_w/h: %d %d\n", bscan_w, bscan_h);
	printf("volume_w/h/n: %d %d %d\n", volume_w, volume_h, volume_n);
	printf("volume_spacing: %f\n", volume_spacing);
	printf("volume_origo: %f %f %f\n", volume_origo.x, volume_origo.y, volume_origo.z);
	printf("\n");

	holger_time(1, "Initialization");

	// Fill up queue
	for (int i = 0; i < BSCAN_WINDOW; i++) {
		shift_queues();
		wait_for_input();
		if (end_of_data()) break;
	}

	int counter = BSCAN_WINDOW;

	while(true) {
		// Retrieve ultrasound data and perform ye olde switcheroo
		shift_queues();
		wait_for_input();
		if (end_of_data()) break;

		holger_time(1, "Retrieve ultrasound data");
		printf("Reconstructing %d ...\n", counter);

		calibrate_pos_matrix(pos_matrices_queue[BSCAN_WINDOW-1], cal_matrix);
		holger_time(1, "Calibrate");
		printf("Calibrate\n");

		insert_plane_points(pos_matrices_queue[BSCAN_WINDOW-1]);
		holger_time(1, "Fill, transform and translate plane_points");
		printf("plane_points\n");

		insert_plane_eq();
		holger_time(1, "Fill bscan_plane_equation");
		printf("bscan_plane_equation\n");

		//int axis = find_orthogonal_axis(bscan_plane_equation);	// TODO: Function that finds axis most orthogonal to bscan plane
		int axis = 0;																							// Actually, turns out that the output is pretty much equal for any axis, 
																															// but the computation time varies (1X - 2X)

		int intersection_counter = find_intersections(axis);
		holger_time(1, "Find ray-plane intersections");
		printf("intersections\n");

		fill_voxels(intersection_counter);
		holger_time(1, "Fill voxels");
		printf("voxels\n");

		counter++;
	}

	holger_time_print(1);
}
示例#2
0
int
QLuaConsole::Private::getchar()
{
  // --- This runs from the console thread,
  //     mutex is unlocked.

  // is data available already?
  int fd = fileno(stdin);
  if (wait_for_input(1, &fd, false) >= 0)
    return fgetc(stdin);
  // we must wait
  QMutexLocker lock(&mutex);
  while (! killConsole)
    {
      int fds[3];
      int nfd = 0;
      if (! throttleActive)
        fds[nfd++] = stdoutPipe[0];
      fds[nfd++] = commandPipe[0];
      fds[nfd++] = fileno(stdin);
      lock.unlock();
      int fd = wait_for_input(nfd, fds);
      lock.relock();
      if (! throttleActive)
        copyout();
      if (fd == commandPipe[0])
        {
          char c = (char)NoCmd;
          if (::read(commandPipe[0], &c, 1) > 0)
            switch( (enum Command)c )
              {
              case HandlerCmd:
                sethandler();
                break;
              case DrainCmd:
                msleep(10);
                copyout(throttleActive = false);
                drain.wakeAll();
                break;
              case BreakCmd:
                if (lua && breakStopsLua) 
                  lua->stop();
                emit q->ttyBreak();
                break;
              case KillCmd:
                killConsole = true;
              case AbortCmd:
                rtty_status = RttyAbort;
              default:
                break;
              }
        }
      if (rtty_status == RttyAbort)
        break;
      if (fd == fileno(stdin))
        return fgetc(stdin);
    }
  return EOF;
}
int msgbox(char *message)
{
  int len = strlen(message);
  int x;

  attrset(COLOR_PAIR(COLOR_WHITE) | A_BOLD);

  for(x = -5; x < len + 5; x++) {
    mvaddch(MAP_YSIZE / 2 - 2, (MAP_XSIZE / 2) - (len / 2) + x, '+');
    mvaddch(MAP_YSIZE / 2 - 1, (MAP_XSIZE / 2) - (len / 2) + x, '+');
    mvaddch(MAP_YSIZE / 2 + 0, (MAP_XSIZE / 2) - (len / 2) + x, '+');
    mvaddch(MAP_YSIZE / 2 + 1, (MAP_XSIZE / 2) - (len / 2) + x, '+');
    mvaddch(MAP_YSIZE / 2 + 2, (MAP_XSIZE / 2) - (len / 2) + x, '+');
  }

  for(x = -3; x < len + 3; x++) {
    mvaddch(MAP_YSIZE / 2 - 1, (MAP_XSIZE / 2) - (len / 2) + x, ' ');
    mvaddch(MAP_YSIZE / 2 + 0, (MAP_XSIZE / 2) - (len / 2) + x, ' ');
    mvaddch(MAP_YSIZE / 2 + 1, (MAP_XSIZE / 2) - (len / 2) + x, ' ');
  }

  attrset(COLOR_PAIR(COLOR_WHITE) | A_NORMAL);

  mvprintw(MAP_YSIZE / 2 + 0, (MAP_XSIZE / 2) - (len / 2), "%s", message);

  attrset(A_NORMAL);

  return wait_for_input();
}
示例#4
0
文件: mu_13.cpp 项目: rdpoor/mu
int main() {
  mu::PlayerRt player_rt;
  mu::Transport transport;
  Metronome *metronome = new Metronome();
  RoomTone *room_tone = new RoomTone();
  Plucks2 *plucks2 = new Plucks2();
  Plucks3 *plucks3 = new Plucks3();
  mu::SumStream *mix = new mu::SumStream();

  printf("1 beat = %ld ticks\n", beat_to_tick(1));

  mix->add_source(room_tone->stream());
  mix->add_source(plucks2->setup());
  mix->add_source(plucks3->setup());
  mix->add_source(metronome->stream());

  printf("mix:\n%s\n", mix->inspect().c_str());

  transport.set_player(&player_rt);
  transport.set_source(mix);

  transport.run();
  wait_for_input();
  transport.stop();
  
  return 0;
}
示例#5
0
void
QLuaConsole::Private::readline()
{
  // --- This runs from the console thread,
  //     mutex is locked.
  int status = 0;
  QByteArray prompt = this->prompt;
  QByteArray ba;
  mutex.unlock();
  ba = rtty_readline(prompt.constData()); 
  mutex.lock();
  switch (rtty_status)
    {
    case RttyOk:
      emit q->ttyInput(ba);
      break;
    case RttyEof:
      emit q->ttyEndOfFile();
    case RttyAbort:
      // drain output
      clearerr(stdin);
      int fd = fileno(stdin);
      if (wait_for_input(1, &fd, false) >= 0)
        fgetc(stdin);
      break;
    }
}
示例#6
0
文件: fd.c 项目: krytarowski/mindy
static void maybe_read(struct thread *thread)
{
    obj_t *fp = thread->fp;
    int fd = fixnum_value(fp[-9]);
    int nfound, res;
    obj_t *old_sp;

    nfound = input_available(fd);
    if (nfound < 0) {
        old_sp = pop_linkage(thread);
        thread->sp = old_sp + 2;
        old_sp[0] = obj_False;
        old_sp[1] = make_fixnum(errno);
        do_return(thread, old_sp, old_sp);
    }
    else if (nfound == 0)
        wait_for_input(thread, fd, maybe_read);
    else {
        res = mindy_read(fd,
                         (char *)(buffer_data(fp[-8]) + fixnum_value(fp[-7])),
                         fixnum_value(fp[-6]));

        results(thread, pop_linkage(thread), res, make_fixnum(res));
    }
}
示例#7
0
static void frontend_ctr_deinit(void *data)
{
   (void)data;
#ifndef IS_SALAMANDER
   global_t *global   = global_get_ptr();
   global->verbosity = true;

#ifdef HAVE_FILE_LOGGER
   if (global->log_file)
      fclose(global->log_file);
   global->log_file = NULL;
#endif

   wait_for_input();

   csndExit();
   gfxExit();

#if 0
   sdmcExit();
   fsExit();
   hidExit();
   aptExit();
   srvExit();
#endif
#endif
}
示例#8
0
文件: get_line.c 项目: VannTen/42sh
int			getline(t_input *input, const int interactive, const int mode,
					size_t *state)
{
	t_term	*term;
	int		ret;

	term = &get_shell_data()->term;
	ret = 0;
	if (interactive == 1)
	{
		apply_termcaps("ks");
		set_shell_sigmode(e_shell_sigmode_line_editing);
		restore_custom_attr(term);
		if ((ret = wait_for_input(input, mode)) == MALLOC_FAIL)
			return (ret);
		apply_termcaps("ke");
		set_shell_sigmode(e_shell_sigmode_shell);
		restore_initial_attr(term);
	}
	else
	{
		if ((ret = get_line_from_file(input, state)) == MALLOC_FAIL)
			return (MALLOC_FAIL);
	}
	(ret == RETURN) ? ret = 0 : 0;
	return (ret);
}
示例#9
0
文件: revoco.c 项目: dolanor/revoco
static void wait_report(int fd, int timeout)
{
	struct hiddev_usage_ref uref;

	if (wait_for_input(fd, timeout) > 0)
		while (read(fd, &uref, sizeof(uref)) > 0)
			;
}
示例#10
0
/**
 * Presents information about the game to the player.
 */
Code info(SDL_Renderer *renderer, CommandTable *table) {
  char buffer[ABOUT_PAGE_BUFFER_SIZE];
  Code code = read_characters(ABOUT_PAGE_PATH, buffer, ABOUT_PAGE_BUFFER_SIZE);
  if (code != CODE_OK) {
    log_message("Failed to read the text.");
    return code;
  }
  print_long_text(buffer, renderer);
  return wait_for_input(table);
}
示例#11
0
文件: ftpsend.c 项目: casualuser/yafc
static int FILE_recv_binary(FILE *in, FILE *out)
{
	size_t n;
	char *buf;
	time_t then = time(0) - 1;
	time_t now;

	ftp_set_close_handler();

	if(foo_hookf)
		foo_hookf(&ftp->ti);
	ftp->ti.begin = false;

	clearerr(in);
	clearerr(out);

	buf = (char *)xmalloc(FTP_BUFSIZ);
	while(!feof(in)) {

		if(wait_for_input() != 0) {
			ftp_trace("wait_for_input() returned non-zero\n");
			break;
		}
#ifdef SECFTP
		n = sec_read(fileno(in), buf, FTP_BUFSIZ);
#else
		n = fread(buf, sizeof(char), FTP_BUFSIZ, in);
#endif
		if(n <= 0)
			break;

		if(ftp_sigints() > 0) {
			ftp_trace("break due to sigint\n");
			break;
		}

		if(fwrite(buf, sizeof(char), n, out) != n)
			break;

		ftp->ti.size += n;

		if(foo_hookf) {
			now = time(0);
			if(now > then) {
				foo_hookf(&ftp->ti);
				then = now;
			}
		}
	}

	free(buf);
	ftp_set_close_handler();

	return maybe_abort(in, out);
}
示例#12
0
文件: tnvm2.cpp 项目: rdpoor/mu
int main() {
  mu::RenderStream *kick_rs = make_perc_kick_rs();
  mu::Transport transport;
  mu::PlayerRt player_rt;

  transport.set_source(kick_rs);
  transport.set_player(&player_rt);

  transport.run();
  wait_for_input();
  return 0;
}
示例#13
0
void
QLuaConsole::Private::run()
{
  // --- This runs from the console thread.
  // accept signals in this thread.
  set_sigint_handler(SIG_DFL);
  release_signals(&savedSigSet);
  // loop
  while (! killConsole)
    {
      int fds[2];
      int nfd = 0;
      if (! throttleActive)
        fds[nfd++] = stdoutPipe[0];
      fds[nfd++] = commandPipe[0];
      int fd = wait_for_input(nfd, fds);
      mutex.lock();
      if (! throttleActive)
        copyout();
      if (fd == commandPipe[0])
        {
          char c = (char)NoCmd;
          if (::read(commandPipe[0], &c, 1) > 0)
            switch( (enum Command)c )
              {
              case HandlerCmd:
                sethandler();
                break;
              case DrainCmd:
                msleep(10);
                copyout(throttleActive = false);
                drain.wakeAll();
                break;
              case BreakCmd:
                if (lua && breakStopsLua) 
                  lua->stop();
                emit q->ttyBreak();
                break;
              case ReadlineCmd:
                readline();
                break;
              case KillCmd:
                killConsole = true;
              default:
                break;
              }
        }
      pulse.wakeAll();
      mutex.unlock();
    }
  // reset signals
  set_sigint_handler(SIG_DFL);
}
示例#14
0
int             main()
{

    init_array();

    init_matrix();

    init_rc_arr();

    iniz(w, b);

    wait_for_input();
}
示例#15
0
文件: ftpsend.c 项目: casualuser/yafc
static int FILE_recv_ascii(FILE *in, FILE *out)
{
	char *buf = (char *)xmalloc(FTP_BUFSIZ);
	int c;
	time_t then = time(0) - 1;
	time_t now;

	ftp_set_close_handler();

	if(foo_hookf)
		foo_hookf(&ftp->ti);
	ftp->ti.begin = false;

	clearerr(in);
	clearerr(out);

	while((c = krb_getc(in)) != EOF) {
		if(ftp_sigints() > 0)
			break;

		if(wait_for_input() != 0)
			break;

		if(c == '\n')
			ftp->ti.barelfs++;
		else if(c == '\r') {
			c = krb_getc(in);
			if(c == EOF)
				break;
			if(c != '\n') {
				ungetc(c, in);
				c = '\r';
			}
		}
		if(fputc(c, out) == EOF)
			break;

		ftp->ti.size++;
		if(foo_hookf) {
			now = time(0);
			if(now > then) {
				foo_hookf(&ftp->ti);
				then = now;
			}
		}
	}

	free(buf);

	return maybe_abort(in, out);
}
示例#16
0
MINDY_NORETURN
static void getc_or_wait(struct thread *thread)
{
    // if (FBUFEMPTYP(stdin) && !feof(stdin)) {
    if (!feof(stdin)) {
        int fd = fileno(stdin);
        int nfound = input_available(fd);

        if (nfound < 0) {
            switch (errno) {
              case EBADF:
                error("Tried to getc with stdin broken.");
              case EINTR:
                wait_for_input(thread, fd, getc_or_wait);
              case EINVAL:
                lose("select failed with EINVAL?");
            }
        }
        else if (nfound == 0)
            wait_for_input(thread, fd, getc_or_wait);
    }

    {
        obj_t *old_sp;
        int c = mindy_getchar();

        old_sp = pop_linkage(thread);

        if (c != EOF)
            *old_sp = int_char(c);
        else
            *old_sp = obj_False;

        thread->sp = old_sp + 1;

        do_return(thread, old_sp, old_sp);
    }
}
示例#17
0
文件: mlock.c 项目: razvand/snippets
int main(void)
{
	void *addr;
	size_t map_len = NUM_PAGES * getpagesize();
	size_t i;
	int rc;
	struct rlimit r;

	rc = getrlimit(RLIMIT_MEMLOCK, &r);
	if (rc < 0) {
		perror("getrlimit");
		exit(EXIT_FAILURE);
	}
	printf("memlock limit: %zu (current), %zu (maximum)\n",
			r.rlim_cur, r.rlim_max);
	printf("map_len: %zu\n", NUM_PAGES * map_len);
	wait_for_input("Call mmap()");
	addr = mmap(NULL, NUM_PAGES * map_len, PROT_READ | PROT_WRITE,
			MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
	if (addr == MAP_FAILED) {
		perror("mmap");
		exit(EXIT_FAILURE);
	}

	wait_for_input("Access mapped page");
	for (i = 0; i < NUM_PAGES; i++)
		memcpy(addr + i*getpagesize(), "anaaremere", 10);
	wait_for_input("Call mlock()");
	rc = mlock(addr, NUM_PAGES * map_len);
	if (rc < 0) {
		perror("mlock");
		exit(EXIT_FAILURE);
	}
	wait_for_input("mlock() has been called");

	return 0;
}
示例#18
0
文件: ftpsend.c 项目: sebastinas/yafc
static int FILE_recv_binary(Socket* in, FILE *out)
{
	time_t then = time(0) - 1;
	time_t now;

	ftp_set_close_handler();

	if(foo_hookf)
		foo_hookf(&ftp->ti);
	ftp->ti.begin = false;

	sock_clearerr_in(in);
	clearerr(out);

	char* buf = xmalloc(FTP_BUFSIZ);
	while (!sock_eof(in)) {
		if(wait_for_input() != 0) {
			ftp_trace("wait_for_input() returned non-zero\n");
			break;
		}

    const ssize_t n = sock_read(in, buf, FTP_BUFSIZ);
		if (n <= 0)
			break;

		if(ftp_sigints() > 0) {
			ftp_trace("break due to sigint\n");
			break;
		}

		if(fwrite(buf, sizeof(char), n, out) != n)
			break;

		ftp->ti.size += n;

		if(foo_hookf) {
			now = time(0);
			if(now > then) {
				foo_hookf(&ftp->ti);
				then = now;
			}
		}
	}

	free(buf);
	ftp_set_close_handler();

	return maybe_abort_in(in, out);
}
示例#19
0
文件: mu_05.cpp 项目: rdpoor/mu
int main() {
  mu::Transport transport;
  mu::PlayerRt player_rt;
  mu::FileReadStream *file_read_stream = new mu::FileReadStream();
  mu::CropStream *crop_stream = new mu::CropStream();
  mu::LoopStream *loop_stream = new mu::LoopStream();
  mu::SequenceStream *sequence_stream = new mu::SequenceStream();

  file_read_stream->set_file_name(EXAMPLE_DIRECTORY "thump.wav");
  mu::MuTick n_frames = file_read_stream->duration();
  crop_stream->set_source(file_read_stream);
  crop_stream->set_source_start(0);
  crop_stream->set_source_end(n_frames);

  mu::MuTick ticks_per_beat = 44100 / 16;

  std::cout << "================" << std::endl;
  std::cout << crop_stream->inspect() << std::endl << std::endl;
  std::cout << "================" << std::endl;

  for (int i=0; i<12; i++) {
    double relative_frequency = pow(2.0, (i - 12.0)/12.0);
    PitchShifter *pitch_shifter = new PitchShifter();
    pitch_shifter->set_shift(relative_frequency);
    mu::CropStream *c2 = crop_stream->clone();
    printf("=== crop_stream_copy = %p, crop_stream_copy->source() = %p\n", c2, c2->source());
    pitch_shifter->set_source(c2);
    sequence_stream->add_source(pitch_shifter->stream(),
                                i * ticks_per_beat,
                                1.0);
  }
    

  loop_stream->set_source_start(0);
  loop_stream->set_source_end(12 * ticks_per_beat);
  loop_stream->set_interval(12 * ticks_per_beat);
  loop_stream->set_source(sequence_stream);

  std::cout << loop_stream->inspect() << std::endl;

  transport.set_source(loop_stream);
  transport.set_player(&player_rt);

  transport.run();
  wait_for_input();
  transport.stop();

  return 0;
}
示例#20
0
int PollGuard::wait_for_input_in_loop(int wait_time, bool forceSend)
{
  int ret_val;
  m_clnt->do_forceSend(forceSend ? 1 : 0);

  NDB_TICKS curr_time = NdbTick_CurrentNanosecond();
  /* Use nanosecond wait_time for max_time calculation */
  NDB_TICKS max_time = curr_time + ((NDB_TICKS)wait_time * 1000000);
  const int maxsleep = (wait_time == -1 || wait_time > 10) ? 10 : wait_time;
  do
  {
    wait_for_input(maxsleep);
    NDB_TICKS start_time_nanos = curr_time;
    curr_time = NdbTick_CurrentNanosecond();
    m_clnt->recordWaitTimeNanos(curr_time - start_time_nanos);
    Uint32 state= m_waiter->get_state();
    if (state == NO_WAIT)
    {
      return 0;
    }
    else if (state == WAIT_NODE_FAILURE)
    {
      ret_val= -2;
      break;
    }
    if (wait_time == -1)
    {
#ifdef NOT_USED
      ndbout << "Waited WAITFOR_RESPONSE_TIMEOUT, continuing wait" << endl;
#endif
      continue;
    }
    if (curr_time >= max_time)
    {
#ifdef VM_TRACE
      ndbout << "Time-out state is " << m_waiter->get_state() << endl;
#endif
      m_waiter->set_state(WST_WAIT_TIMEOUT);
      ret_val= -1;
      break;
    }
  } while (1);
#ifdef VM_TRACE
  ndbout << "ERR: receiveResponse - theImpl->theWaiter.m_state = ";
  ndbout << m_waiter->get_state() << endl;
#endif
  m_waiter->set_state(NO_WAIT);
  return ret_val;
}
示例#21
0
int ctr_request_update(void)
{
   gfxInit(GSP_BGR8_OES,GSP_RGB565_OES,false);
   gfxSet3D(false);
   consoleInit(GFX_BOTTOM, NULL);

   printf("\n\nunsupported version\n\n");
   printf("Please update your playload\n");

   wait_for_input();

   gfxExit();

   return 0;
}
示例#22
0
int core::run() {
  // writes the config and process id to file
  write_state();

  quit_mainloop=0;

  while (!quit_mainloop && term_signal==0 && quit_signal==0) {
      // wait for a job to run...
      job * this_job=NULL;
      result* this_result=NULL;
      try {
	  this_job=wait_for_input();
      }
      catch (job_exception je) {
	  this_result=new error_result(job_counter,je);
      }
      
      if (quit_mainloop!=0 || term_signal!=0) {
	  if (this_job!=NULL) delete this_job;
	  break;
      }
      // do the work ...
      if (this_job!=NULL) {
	  this_result=do_the_job(*this_job);
	  if (term_signal!=0) {
	      delete this_job;
	      if (this_result!=NULL) delete this_result;
	      break;
	  }
      }
      else
	this_job=new job(job_counter);
      if (this_result==NULL) {
	  this_result=new error_result(job_counter,"unexpected: did not get any result");
      }
      // tell them...
      write_to_output(*this_job,*this_result);
      delete this_result;
      delete this_job;
      job_counter++;
  }

  // deletes config file
  remove_state();

  return 0;
}
示例#23
0
void factoroids_level_message(int wave)
{
    SDL_Rect rect;
    SDL_Surface *bgsurf=NULL;
    int nwave;

    char objs_str[PRIME_MAX_LIMIT][MAX_CHAR_MSG] =
    {
        N_("Powers of 2"),
        N_("Products of 2 and 3"),
        N_("Products of 2, 3 and 5"),
        N_("Products of 2, 3, 5 and 7"),
        N_("Products of 2, 3, 5, 7, and 11"),
        N_("Products of 2, 3, 5, 7, 11 and 13")
    };

    char hints_str[PRIME_MAX_LIMIT][MAX_CHAR_MSG] =
    {
        N_("All multiples of 2 end in 2, 4, 6, 8, or 0"),
        N_("The digits of a multiple of 3 add up to a multiple of 3"),
        N_("All multiples of 5 end in 0 or 5"),
        N_("Sorry - there is no simple rule to identify multiples of 7."),
        N_("Under 100, multiples of 11 have equal digits, such as 55 or 88."),
        N_("Sorry - there is no simple rule to identify multiples of 13."),
    };

    rect.x = (screen->w/2)-(LVL_WIDTH_MSG/2);
    rect.y = (screen->h/2)-(LVL_HEIGHT_MSG/2);

    bgsurf = T4K_CreateButton(LVL_WIDTH_MSG,LVL_HEIGHT_MSG,12,19,19,96,96);

    if(bgsurf)
    {
        SDL_BlitSurface(bgsurf, NULL, screen, &rect );
        SDL_FreeSurface(bgsurf);
    }

    nwave = (wave > PRIME_MAX_LIMIT) ? PRIME_MAX_LIMIT : wave;

    factoroids_level_objs_hints(_("Objectives:"), _(objs_str[nwave-1]), rect.x+LVL_OBJ_X_OFFSET, rect.y+LVL_OBJ_Y_OFFSET);
    factoroids_level_objs_hints(_("Hints:"), _(hints_str[nwave-1]), rect.x+LVL_HINT_X_OFFSET, rect.y+LVL_HINT_Y_OFFSET);

    SDL_Flip(screen);

    wait_for_input();
}
示例#24
0
int main(void)
{
	int fd1, fd2, rc;

	wait_for_input("beginning");

	/* opening files */
	fd1 = open("tmp1.txt", O_CREAT | O_RDWR, 0644);
	DIE(fd1 < 0, "open tmp1.txt");
	wait_for_input("created tmp1.txt");

	fd2 = open("Makefile", O_RDONLY);
	DIE(fd2 < 0, "open Makefile");
	wait_for_input("opened Makefile");
	
	/* redirect sterr to fd1 */
	rc = close(STDERR_FILENO);
	DIE(rc < 0, "close stderr");
	wait_for_input("closed stderr");

	rc = dup(fd1);
	DIE(rc < 0, "dup fd1");
	wait_for_input("dup - redirected stderr to fd1");

	
	rc = close(fd1);
	DIE(rc < 0, "close fd1");
	wait_for_input("closed fd1");

	/* redirect stderr to fd2 */
	rc = dup2(fd2, STDERR_FILENO);
	DIE(rc < 0, "dup2 fd2");
	wait_for_input("dup2 - redirected stderr to fd2");

	rc = close(fd2);
	DIE(rc < 0, "close fd2");
	wait_for_input("closed fd2");

	return 0;
}
示例#25
0
static void frontend_ctr_deinit(void *data)
{
   extern PrintConsole* currentConsole;
   Handle lcd_handle;
   u8 not_2DS;
   (void)data;
#ifndef IS_SALAMANDER
   global_t *global   = global_get_ptr();
   global->verbosity = true;

#ifdef HAVE_FILE_LOGGER
   if (global->log_file)
      fclose(global->log_file);
   global->log_file = NULL;
#endif

   if(gfxBottomFramebuffers[0] == (u8*)currentConsole->frameBuffer)
      wait_for_input();

   CFGU_GetModelNintendo2DS(&not_2DS);
   if(not_2DS && srvGetServiceHandle(&lcd_handle, "gsp::Lcd") >= 0)
   {
      u32 *cmdbuf = getThreadCommandBuffer();
      cmdbuf[0] = 0x00110040;
      cmdbuf[1] = 2;
      svcSendSyncRequest(lcd_handle);
      svcCloseHandle(lcd_handle);
   }

   exitCfgu();
   csndExit();
   gfxExit();

#if 0
   sdmcExit();
   fsExit();
   hidExit();
   aptExit();
   srvExit();
#endif
#endif
}
示例#26
0
void
QLuaConsole::Private::copyout(bool throttle)
{
  // --- This runs from the console thread,
  //     mutex is locked.
  char buffer[1024];
  int fd = stdoutPipe[0];
  while (!throttleActive && wait_for_input(1, &fd, false) >= 0)
    {
      int sz = ::read(fd, buffer, sizeof(buffer));
      if (sz < 0)
        return;
      QByteArray ba(buffer, sz);
      emit sigConsoleOutput(ba);
      if (++throttleCount > 16)
        throttleActive = throttle;
      if (printCapturedOutput)
        fwrite(buffer, 1, sz, trueStdout);
    }
}
示例#27
0
文件: mu_04.cpp 项目: rdpoor/mu
int main() {
  mu::Transport transport;
  mu::PlayerRt player_rt;
  mu::FileReadStream *file_read_stream = new mu::FileReadStream();
  mu::LoopStream *loop_stream = new mu::LoopStream();

  file_read_stream->set_file_name(EXAMPLE_DIRECTORY "purple.wav");

  mu::MuTick n_frames = file_read_stream->duration();
  loop_stream->set_source_start(0);
  loop_stream->set_source_end(n_frames);
  loop_stream->set_interval(n_frames);

  loop_stream->set_source(file_read_stream);
  transport.set_source(loop_stream);
  transport.set_player(&player_rt);

  transport.run();
  wait_for_input();
  transport.stop();

  return 0;
}
示例#28
0
文件: mu_07.cpp 项目: rdpoor/mu
int main() {
  mu::Transport transport;
  mu::PlayerRt player_rt;
  mu::LoopStream *loop_stream = new mu::LoopStream();
  Boop boop;

  boop.add_boop(beat_to_tick(0), beat_to_tick(1), mu::MuUtils::midi_pitch_to_frequency(69));
  boop.add_boop(beat_to_tick(4), beat_to_tick(1.75), mu::MuUtils::midi_pitch_to_frequency(69+4));
  boop.add_boop(beat_to_tick(8), beat_to_tick(2.5), mu::MuUtils::midi_pitch_to_frequency(69+7));
  boop.add_boop(beat_to_tick(12), beat_to_tick(3.25), mu::MuUtils::midi_pitch_to_frequency(69+12));
  
  loop_stream->set_source(boop.sink());
  loop_stream->set_interval(beat_to_tick(12));
  loop_stream->set_source_end(beat_to_tick(16));

  transport.set_source(loop_stream);
  transport.set_player(&player_rt);
  
  transport.run();
  wait_for_input();
  transport.stop();

  return 0;
}
示例#29
0
文件: main.c 项目: cukupupas/sngrep
/**
 * @brief Main function logic
 *
 * Parse command line options and start running threads
 */
int
main(int argc, char* argv[])
{
    int opt, idx, limit, only_calls, no_incomplete, i;
    const char *device, *outfile;
    char bpf[512];
    const char *keyfile;
    const char *match_expr;
    int match_insensitive = 0, match_invert = 0;
    int no_interface = 0, quiet = 0, rtp_capture = 0;
    vector_t *infiles = vector_create(0, 1);

    // Program otptions
    static struct option long_options[] = {
        { "help", no_argument, 0, 'h' },
        { "version", no_argument, 0, 'V' },
        { "device", required_argument, 0, 'd' },
        { "input", required_argument, 0, 'I' },
        { "output", required_argument, 0, 'O' },
#if defined(WITH_GNUTLS) || defined(WITH_OPENSSL)
        { "keyfile", required_argument, 0, 'k' },
#endif
        { "calls", no_argument, 0, 'c' },
        { "rtp", no_argument, 0, 'r' },
        { "limit", no_argument, 0, 'l' },
        { "icase", no_argument, 0, 'i' },
        { "invert", no_argument, 0, 'v' },
        { "no-interface", no_argument, 0, 'N' },
        { "dump-config", no_argument, 0, 'D' },
#ifdef USE_EEP
        { "eep-listen", required_argument, 0, 'L' },
        { "eep-send", required_argument, 0, 'H' },
#endif
        { "quiet", no_argument, 0, 'q' },
    };

    // Initialize configuration options
    init_options();

    // Get initial values for configurable arguments
    device = setting_get_value(SETTING_CAPTURE_DEVICE);
    outfile = setting_get_value(SETTING_CAPTURE_OUTFILE);
    keyfile = setting_get_value(SETTING_CAPTURE_KEYFILE);
    limit = setting_get_intvalue(SETTING_CAPTURE_LIMIT);
    only_calls = setting_enabled(SETTING_SIP_CALLS);
    no_incomplete = setting_enabled(SETTING_SIP_NOINCOMPLETE);
    rtp_capture = setting_enabled(SETTING_CAPTURE_RTP);

    // Parse command line arguments
    opterr = 0;
    char *options = "hVd:I:O:pqtW:k:crl:ivNqDL:H:";
    while ((opt = getopt_long(argc, argv, options, long_options, &idx)) != -1) {
        switch (opt) {
        case 'h':
            usage();
            return 0;
        case 'V':
            version();
            return 0;
        case 'd':
            device = optarg;
            break;
        case 'I':
            vector_append(infiles, optarg);
            break;
        case 'O':
            outfile = optarg;
            break;
        case 'l':
            if(!(limit = atoi(optarg))) {
                fprintf(stderr, "Invalid limit value.\n");
                return 0;
            }
            break;
#if defined(WITH_GNUTLS) || defined(WITH_OPENSSL)
        case 'k':
            keyfile = optarg;
            break;
#endif
        case 'c':
            only_calls = 1;
            setting_set_value(SETTING_SIP_CALLS, SETTING_ON);
            break;
        case 'r':
            rtp_capture = 1;
            setting_set_value(SETTING_CAPTURE_RTP, SETTING_ON);
            break;
        case 'i':
            match_insensitive++;
            break;
        case 'v':
            match_invert++;
            break;
        case 'N':
            no_interface = 1;
            setting_set_value(SETTING_CAPTURE_STORAGE, "none");
            break;
        case 'q':
            quiet = 1;
            break;
        case 'D':
            key_bindings_dump();
            settings_dump();
            return 0;
        // Dark options for dummy ones
        case 'p':
        case 't':
        case 'W':
            break;
#ifdef USE_EEP
        case 'L':
            capture_eep_set_server_url(optarg);
            break;
        case 'H':
            capture_eep_set_client_url(optarg);
            break;
#endif
        case '?':
            if (strchr(options, optopt)) {
                fprintf(stderr, "-%c option requires an argument.\n", optopt);
            } else if (isprint(optopt)) {
                fprintf(stderr, "Unknown option -%c.\n", optopt);
            } else {
                fprintf(stderr, "Unknown option character '\\x%x'.\n", optopt);
            }
            return 1;
        default:
            break;
        }
    }

#if defined(WITH_GNUTLS) || defined(WITH_OPENSSL)
    // Set capture decrypt key file
    capture_set_keyfile(keyfile);
    // Check if we have a keyfile and is valid
    if (keyfile && !tls_check_keyfile(keyfile)) {
        fprintf(stderr, "%s does not contain a valid RSA private key.\n", keyfile);
        return 1;
    }
#endif

    // Check if given argument is a file
    if (argc == 2 && (access(argv[1], F_OK) == 0)) {
        // Old legacy option to open pcaps without other arguments
        printf("%s seems to be a file: You forgot -I flag?\n", argv[1]);
        return 0;
    }

    // Initialize SIP Messages Storage
    sip_init(limit, only_calls, no_incomplete);

    // Set capture options
    capture_init(limit, rtp_capture);

#ifdef USE_EEP
    // Initialize EEP if enabled
    capture_eep_init();
#endif

    // If we have an input file, load it
    if (vector_count(infiles)) {
        for (i = 0; i < vector_count(infiles); i++) {
            // Try to load file
            if (capture_offline(vector_item(infiles, i), outfile) != 0)
                return 1;
        }
    } else {
        // Check if all capture data is valid
        if (capture_online(device, outfile) != 0)
            return 1;
    }

    // Remove Input files vector
    vector_destroy(infiles);

    // More arguments pending!
    if (argv[optind]) {
        // Assume first pending argument is  match expression
        match_expr = argv[optind++];

        // Try to build the bpf filter string with the rest
        memset(bpf, 0, sizeof(bpf));
        for (i = optind; i < argc; i++)
            sprintf(bpf + strlen(bpf), "%s ", argv[i]);

        // Check if this BPF filter is valid
        if (capture_set_bpf_filter(bpf) != 0) {
            // BPF Filter invalid, check incluiding match_expr
            match_expr = 0;    // There is no need to parse all payload at this point


            // Build the bpf filter string
            memset(bpf, 0, sizeof(bpf));
            for (i = optind - 1; i < argc; i++)
                sprintf(bpf + strlen(bpf), "%s ", argv[i]);

            // Check bpf filter is valid again
            if (capture_set_bpf_filter(bpf) != 0) {
                fprintf(stderr, "Couldn't install filter %s: %s\n", bpf, capture_last_error());
                return 1;
            }
        }

        // Set the capture filter
        if (match_expr)
            if (sip_set_match_expression(match_expr, match_insensitive, match_invert)) {
                fprintf(stderr, "Unable to parse expression %s\n", match_expr);
                return 1;
            }
    }

    // Start a capture thread
    if (capture_launch_thread() != 0) {
        ncurses_deinit();
        fprintf(stderr, "Failed to launch capture thread.\n");
        return 1;
    }

    if (!no_interface) {
        // Initialize interface
        ncurses_init();
        // This is a blocking call.
        // Create the first panel and wait for user input
        ui_create_panel(PANEL_CALL_LIST);
        wait_for_input();
    } else {
        setbuf(stdout, NULL);
        while(capture_get_status() != CAPTURE_OFFLINE) {
            if (!quiet)
                printf("\rDialog count: %d", sip_calls_count());
            usleep(500 * 1000);
        }
        if (!quiet)
            printf("\rDialog count: %d\n", sip_calls_count());
    }

    // Capture deinit
    capture_deinit();

    // Deinitialize interface
    ncurses_deinit();

    // Deinitialize configuration options
    deinit_options();

    // Deallocate sip stored messages
    sip_deinit();

    // Leaving!
    return 0;
}
示例#30
0
文件: revoco.c 项目: dolanor/revoco
static void configure(int handle, int argc, char **argv)
{
	int i, arg1, arg2;

	for (i = 1; i < argc; ++i)
	{
		int perm = 0x80;
		char *cmd = argv[i];

		if (strneq(cmd, "temp-", 5))
			perm = 0, cmd += 5;

		if (streq(cmd, "free"))
		{
			mx_cmd(handle, perm + 1, 0, 0);
		}
		else if (streq(cmd, "click"))
		{
			mx_cmd(handle, perm + 2, 0, 0);
		}
		else if (strneq(cmd, "manual", 6))
		{
			twoargs(cmd + 6, &arg1, &arg2, 0, 0, 15);
			if (arg1 != arg2)
				mx_cmd(handle, perm + 7, arg1 * 16 + arg2, 0);
			else
				mx_cmd(handle, perm + 8, arg1, 0);
		}
		else if (strneq(cmd, "auto", 4))
		{
			twoargs(cmd + 4, &arg1, &arg2, 0, 0, 50);
			mx_cmd(handle, perm + 5, arg1, arg2);
		}
		else if (strneq(argv[i], "soft-free", 9))
		{
			twoargs(argv[i] + 9, &arg1, &arg2, 0, 0, 255);
			mx_cmd(handle, 3, arg1, arg2);
		}
		else if (strneq(argv[i], "soft-click", 10))
		{
			twoargs(argv[i] + 10, &arg1, &arg2, 0, 0, 255);
			mx_cmd(handle, 4, arg1, arg2);
		}
		else if (strneq(argv[i], "reconnect", 9))
		{
			static const int cmd[] = { 0xff, 0x80, 0xb2, 1, 0, 0 };

			twoargs(argv[i] + 9, &arg1, &arg2, 0, 0, 255);
			send_report(handle, 0x10, cmd, 6);
			printf("Reconnection initiated\n");
			printf(" - Turn off the mouse\n");
			printf(" - Press and hold the left mouse button\n");
			printf(" - Turn on the mouse\n");
			printf(" - Press the right button 5 times\n");
			printf(" - Release the left mouse button\n");
			wait_report(handle, 60000);
		}
		else if (strneq(argv[i], "mode", 4))
		{
			int buf[6];

			if (mx_query(handle, 0x08, buf))
			{
				if (buf[5] & 1)
					printf("click-by-click\n");
			else
				printf("free spinning\n");
			}
		}
		else if (strneq(argv[i], "battery", 7))
		{
			int buf[6];

			if (mx_query(handle, 0x0d, buf))
			{
				char str[32], *st;

				switch (buf[5])
				{
					case 0x30:	st = "running on battery";	break;
					case 0x50:	st = "charging";		break;
					case 0x90:	st = "fully charged";		break;
					default:	sprintf(st = str, "status %02x", buf[5]);
				}
				printf("battery level %d%%, %s\n", buf[3], st);
			}
		}
		
		/*** debug commands ***/
		else if (strneq(argv[i], "raw", 3))
		{
			int buf[256], n;

			n = nargs(argv[i] + 3, buf, 256, 0, 0, 255);
			send_report(handle, buf[0], buf+1, n-1);
		}
		else if (strneq(argv[i], "query", 5))
		{
			int buf[256], j;

			twoargs(argv[i] + 5, &arg1, &arg2, -1, 0, 255);
			if (arg1 == -1)
				arg1 = 0x10, arg2 = 6;
			query_report(handle, arg1, buf, arg2);

			printf("report %02x:", arg1);
			for (j = 0; j < arg2; ++j)
				printf(" %02x", buf[j]);
			printf("\n");
		}
		else if (strneq(argv[i], "dump", 4))
		{
			twoargs(cmd + 4, &arg1, &arg2, 3, -1, 24*60*60);
			if (arg1 > 0)
				arg1 *= 1000;
			while (wait_for_input(handle, arg1) > 0)
			{
				struct hiddev_usage_ref uref;

				if (read(handle, &uref, sizeof(uref)) == sizeof(uref))
					printf("read: type=%u, id=%u, field=%08x, usage=%08x,"
						" code=%08x, value=%u\n",
						uref.report_type, uref.report_id, uref.field_index,
						uref.usage_index, uref.usage_code, uref.value);
			}
		}
		else if (strneq(argv[i], "sleep", 5))
		{
			twoargs(argv[i] + 5, &arg1, &arg2, 1, 0, 255);
			sleep(arg1);
		}
		else
			fatal("unknown option `%s'", argv[i]);
	}
}