Exemplo n.º 1
0
Arquivo: shell.c Projeto: uoaerg/wise
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_process, ev, data)
{
  static struct process *started_process;
  struct shell_input *input;
  int ret;
  PROCESS_BEGIN();

  /* Let the system start up before showing the prompt. */
  PROCESS_PAUSE();
 
  shell_start();
 
  while(1) {
    
    PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input);
    {
      input = data;
      ret = shell_start_command(input->data1, input->len1, NULL,
				&started_process);

      if(started_process != NULL &&
	 ret == SHELL_FOREGROUND &&
	 process_is_running(started_process)) {
	front_process = started_process;
	PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_EXITED &&
				 data == started_process);
      }
      front_process = &shell_process;
    }
    shell_prompt(shell_prompt_text);
  }
  
  PROCESS_END();
}
Exemplo n.º 2
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_netcmd_server_process, ev, data)
{
  static struct process *child_command;
  int err;
  PROCESS_BEGIN();

  /* XXX: direct output to null. */
  printf("netcmd server got command string '%s'\n", (char *)data);
  err = shell_start_command(data, strlen((char * )data), NULL, &child_command);
  if(err == SHELL_FOREGROUND && process_is_running(child_command)) {
    PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_EXIT ||
			     (ev == PROCESS_EVENT_EXITED &&
			      data == child_command));
    if(ev == PROCESS_EVENT_EXIT) {
      process_exit(child_command);
    }
  }

  PROCESS_END();
}
Exemplo n.º 3
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_repeat_server_process, ev, data)
{
  static char *command;
  static struct process *started_process;
  char command_copy[MAX_COMMANDLENGTH];
  int ret;

  if(ev == shell_event_input) {
    goto exit;
  }
  
  PROCESS_BEGIN();

  command = data;
  
  PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_CONTINUE &&
			   data == &shell_repeat_process);
  {
    strncpy(command_copy, command, MAX_COMMANDLENGTH);
    ret = shell_start_command(command_copy, (int)strlen(command_copy),
			      &repeat_command, &started_process);
    
    if(started_process != NULL &&
       process_is_running(started_process)) {
      PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_EXITED &&
			       data == started_process);
    }
  }

  /*  PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input);
  
  printf("haha \n");
  if(repeat_command.child != NULL &&
     process_is_running(repeat_command.child->process)) {
    process_post_synch(repeat_command.child->process, ev, data);
    }*/
 exit:
  ;
  PROCESS_END();
}
Exemplo n.º 4
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_randwait_process, ev, data)
{
  static int maxwait;
  static char command[MAX_COMMANDLENGTH];
  static struct etimer etimer;
  static struct process *started_process;
  const char *args, *next;
  int ret;

  /*  if(ev == shell_event_input) {
    struct shell_input *input;
    input = data;
    printf("shell randwait input %d %d\n", input->len1, input->len2);
    if(input->len1 + input->len2 != 0) {
      shell_output(&randwait_command, input->data1, input->len1,
		   input->data2, input->len2);
    }
    }*/

  
  PROCESS_BEGIN();

  args = data;

  if(args == NULL) {
    shell_output_str(&randwait_command, "usage 0", "");
    PROCESS_EXIT();
  }
  
  maxwait = shell_strtolong(args, &next);
  if(next == args) {
    shell_output_str(&randwait_command, "usage 1", "");
    PROCESS_EXIT();
  }
  args = next;

  while(*args == ' ') {
    args++;
  }
  
  strncpy(command, args, MAX_COMMANDLENGTH);
  if(strlen(command) == 0) {
    shell_output_str(&repeat_command, "usage 3", "");
    PROCESS_EXIT();
  }

  /*  printf("randwait %d command '%s'\n",
      maxwait, command);*/

  etimer_set(&etimer, random_rand() % (CLOCK_SECOND * maxwait));
  PROCESS_WAIT_UNTIL(etimer_expired(&etimer));

/*   printf("Starting '%s' child %p (%s)\n", command, randwait_command.child, */
/* 	 randwait_command.child == NULL? "null": randwait_command.child->command); */
  
  ret = shell_start_command(command, (int)strlen(command),
			    randwait_command.child, &started_process);
  
  if(started_process != NULL &&
     process_is_running(started_process)) {
    PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_EXITED &&
			     data == started_process);
  }

  PROCESS_END();
}