コード例 #1
0
ファイル: ramp.c プロジェクト: jrwilson/substrate
void
ramp_request_proxy (void* state, void* param, bid_t bid)
{
  ramp_t* ramp = state;
  assert (ramp != NULL);

  assert (buffer_size (bid) == sizeof (proxy_request_t));

  const proxy_request_t* request = buffer_read_ptr (bid);
  ramp_proxy_t* ramp_proxy = malloc (sizeof (ramp_proxy_t));
  ramp_proxy->request = *request;
  assert (automan_declare (ramp->automan,
			   &ramp_proxy->composed,
			   ramp_proxy,
			   ramp_declared,
			   ramp_proxy) == 0);
  assert (automan_create (ramp->automan,
			  &ramp_proxy->aid,
			  &ramp_proxy_descriptor,
			  NULL,
			  ramp_proxy_created,
			  ramp_proxy) == 0);
  assert (automan_compose (ramp->automan,
			   &ramp_proxy->composed,
			   &ramp->self,
			   ramp_integer_out,
			   ramp_proxy,
			   &ramp_proxy->aid,
			   ramp_proxy_integer_in,
			   NULL,
			   NULL,
			   NULL) == 0);
  assert (schedule_system_output () == 0);
}
コード例 #2
0
ファイル: composer.c プロジェクト: jrwilson/substrate
void
composer_input2 (void* state, void* param, bid_t bid)
{
  assert (bid != -1);
  assert (buffer_size (bid) == sizeof (counter_output_t));

  const counter_output_t* output = buffer_read_ptr (bid);
  printf ("count(2) = %d\n", output->count);
}
コード例 #3
0
ファイル: composer.c プロジェクト: jrwilson/substrate
static void
composer_system_input (void* state, void* param, bid_t bid)
{
  printf ("composer_system_input\n");
  assert (state != NULL);
  composer_t* composer = state;

  assert (bid != -1);
  assert (buffer_size (bid) == sizeof (receipt_t));
  const receipt_t* receipt = buffer_read_ptr (bid);

  automan_apply (composer->automan, receipt);
}
コード例 #4
0
ファイル: counter.c プロジェクト: jrwilson/substrate
static void
counter_system_input (void* state, void* param, bid_t bid)
{
  printf ("counter_system_input\n");
  assert (state != NULL);
  assert (bid != -1);
  assert (buffer_size (bid) == sizeof (receipt_t));

  const receipt_t* receipt = buffer_read_ptr (bid);
  if (receipt->type == SELF_CREATED) {
    assert (schedule_internal (counter_internal, NULL) == 0);
  }
}
コード例 #5
0
ファイル: display.c プロジェクト: jrwilson/substrate
static void
display_system_input (void* state, void* param, bid_t bid)
{
  display_t* display = state;
  assert (display != NULL);

  assert (bid != -1);
  assert (buffer_size (bid) == sizeof (receipt_t));
  const receipt_t* receipt = buffer_read_ptr (bid);

  if (receipt->type == SELF_CREATED) {
    assert (schedule_read_input (display->fd) == 0);
  }
}
コード例 #6
0
ファイル: ramp.c プロジェクト: jrwilson/substrate
static void
ramp_system_input (void* state, void* param, bid_t bid)
{
  ramp_t* ramp = state;
  assert (ramp != NULL);

  assert (bid != -1);
  assert (buffer_size (bid) == sizeof (receipt_t));
  const receipt_t* receipt = buffer_read_ptr (bid);

  automan_apply (ramp->automan, receipt);

  if (receipt->type == SELF_CREATED) {
    /* Schedule output. */
    assert (schedule_alarm_input (1, 0) == 0);
  }
}
コード例 #7
0
//The main telnet task
void telnet_task_main(void)
{
/*
	commands[0].command="help";
	commands[0].exec = &telnet_help;

	commands[1].command="echo";
	commands[1].exec = &telnet_echo;

	commands[2].command="time";
	commands[2].exec = &telnet_time;

	commands[3].command="quit";
	commands[3].exec = &telnet_quit;

	commands[4].command="memdump";
	commands[4].exec = &telnet_memdump;
*/
	connection_event.event_mask = ReadableOrException;
	telnet_handle = FILE_INVALID_HANDLE;
	socket_listen(HTONS(23), &telnet_connect_accept );

	unsigned short pos = 0;
	while(1)
	{
restart:
		while( ! file_get_next_event( &telnet_handle, 1, &connection_event) )
		{
			task_yield();
		}
		if( connection_event.event & Exception )
		{
//#ifdef __DEBUG
			puts("\r\nTelnet: Closing connection");
//#endif
			file_close( telnet_handle );
			telnet_handle = FILE_INVALID_HANDLE;
			pos = 0;
			optneg_mode = 0;
			goto restart;
		}

		unsigned short avail = buffer_available(&telnet_receive_buffer);
		char* rd_buf = buffer_read_ptr(&telnet_receive_buffer);
		while( pos < avail)//if avail == 1, rd_buf[0] is the last char we can read
		{
			unsigned char c = rd_buf[pos];
			if( pos == REC_BUF_SIZE-1 )
			{
				//buffer is full, but no CR/LF seen yet... what to do?
				//either discard line, or pretend the last char was \r ??
				c = '\r';
			}

			switch(c)
			{
				case TELNET_IAC:
					if( avail - pos > 2 )
					{
						//buf[pos+1] = will/wont/do/dont
						//buf[pos+2] = option
						switch( (unsigned char) rd_buf[pos+2] )
						{
							case TELNET_ECHO:
								switch( (unsigned char) rd_buf[pos+1] )
								{
									case TELNET_DO:
										//other end wants us to echo
										telnet_mode |= MODE_ECHO;
										break;
									case TELNET_DONT:
										//other end demands we don't echo
										telnet_mode &= ~MODE_ECHO;
										break;
								}
								break;
						}
						//remove 3 chars from buffer
						buffer_unwrite(&telnet_receive_buffer, &rd_buf[pos], 3 );
						avail -= 3;
					}
					else
					{
						task_yield();
					}
					break;
				case '\r': // could be \r\n , \r\0 or just \r on its own
					pos++;
					if( telnet_mode & MODE_ECHO)
					{
						file_puts(CRLF, telnet_handle);
					}
					//if there's a following character, and it's \n or \0, chomp it too.
					if( pos < avail && (rd_buf[pos+1] == '\n' || rd_buf[pos+1] == '\0')) pos++; 
					exec_line( rd_buf, rd_buf+pos ); //if read rd_buf[0], pos == 1 -> end = (rd_ptr + 1)

					buffer_seek( &telnet_receive_buffer, pos ); //free buffer
					rd_buf = buffer_read_ptr(&telnet_receive_buffer);

					pos = 0;
					avail = buffer_available(&telnet_receive_buffer);
					file_putchar('>', telnet_handle);
					break;
				case '\b':
				case 0x7f:
					puts("\r\ntel:backspace");
					if( pos > 0 ) //not the first character
					{
						if( telnet_mode & MODE_ECHO)
						{
							file_putchar('\b', telnet_handle);
							file_putchar(' ', telnet_handle);
							file_putchar('\b', telnet_handle);
						}
						buffer_unwrite(&telnet_receive_buffer, &rd_buf[pos-1], 2 );
						avail-=2;
						pos--;
					}
					else
					{
						buffer_unwrite(&telnet_receive_buffer, &rd_buf[pos], 1 );
						avail--;
					}
					break;
				default:
					if( c >= ' ' && c <='~' )
					{
						if( telnet_mode & MODE_ECHO)
						{
							file_putchar(c, telnet_handle);
							pos++;
						}
					}
					else
					{
						buffer_unwrite(&telnet_receive_buffer, &rd_buf[pos], 1 );
						avail--;
					}
			}//end switch
		}//end while loop

		task_yield();
	}//end outer while
}