/* Dummy (do-nothing) serial interface */

/*
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.  */

#include "defs.h"
#include "serial.h"

static int
ser_dummy_open (struct serial *scb ATTRIBUTE_UNUSED, const char *name ATTRIBUTE_UNUSED)
{
  scb->fd = -1;
  return 0;
}

void
ser_dummy_close (struct serial *scb ATTRIBUTE_UNUSED)
{
}

/* Wait for the output to drain away, as opposed to flushing (discarding) it */

serial_ttystate
ser_dummy_get_tty_state (struct serial *scb ATTRIBUTE_UNUSED)
{
  /* allocate a dummy */
  return (serial_ttystate) xmalloc (8);
}

int
ser_dummy_set_tty_state (struct serial *scb ATTRIBUTE_UNUSED, serial_ttystate ttystate ATTRIBUTE_UNUSED)
{
  return 0;
}

void
ser_dummy_go_raw (struct serial *scb ATTRIBUTE_UNUSED)
{
  return;			/* Always in raw mode */
}


int
ser_dummy_readchar (struct serial *scb ATTRIBUTE_UNUSED, int timeout ATTRIBUTE_UNUSED)
{
  return SERIAL_EOF;
}

int
ser_dummy_noflush_set_tty_state (struct serial *scb ATTRIBUTE_UNUSED,
				    serial_ttystate new_ttystate ATTRIBUTE_UNUSED,
				    serial_ttystate old_ttystate ATTRIBUTE_UNUSED)
{
  return 0;
}

void
ser_dummy_print_tty_state (struct serial *scb ATTRIBUTE_UNUSED, 
			      serial_ttystate ttystate ATTRIBUTE_UNUSED,
			      struct ui_file *stream ATTRIBUTE_UNUSED)
{
  /* Nothing to print.  */
  return;
}

int
ser_dummy_setbaudrate (struct serial *scb ATTRIBUTE_UNUSED, int rate ATTRIBUTE_UNUSED)
{
  return 0;			/* Never fails! */
}

int
ser_dummy_setstopbits (struct serial *scb ATTRIBUTE_UNUSED, int num ATTRIBUTE_UNUSED)
{
  return 0;			/* Never fails! */
}

int
ser_dummy_write (struct serial *scb ATTRIBUTE_UNUSED, const char *str ATTRIBUTE_UNUSED, int len ATTRIBUTE_UNUSED)
{
  return 0;
}

int
ser_dummy_flush_output (struct serial *scb ATTRIBUTE_UNUSED)
{
  return 0;
}

int
ser_dummy_flush_input (struct serial *scb ATTRIBUTE_UNUSED)
{
 return 0;
}

int
ser_dummy_send_break (struct serial *scb ATTRIBUTE_UNUSED)
{
  return 0;
}

static int
ser_dummy_drain_output (struct serial *scb ATTRIBUTE_UNUSED)
{
  return 0;
}

/* Put the SERIAL device into/out-of ASYNC mode.  */

void
ser_dummy_async (struct serial *scb ATTRIBUTE_UNUSED,
		int async_p ATTRIBUTE_UNUSED)
{
}

void
_initialize_dummy_ser_hardwire (void)
{
  struct serial_ops *ops = (struct serial_ops *) xmalloc (sizeof (struct serial_ops));
  memset (ops, sizeof (struct serial_ops), 0);
  ops->name = "hardwire";
  ops->next = 0;
  ops->open = ser_dummy_open;
  ops->close = ser_dummy_close;
  ops->readchar = ser_dummy_readchar;
  ops->write = ser_dummy_write;
  ops->flush_output = ser_dummy_flush_output;
  ops->flush_input = ser_dummy_flush_input;
  ops->send_break = ser_dummy_send_break;
  ops->go_raw = ser_dummy_go_raw;
  ops->get_tty_state = ser_dummy_get_tty_state;
  ops->set_tty_state = ser_dummy_set_tty_state;
  ops->print_tty_state = ser_dummy_print_tty_state;
  ops->noflush_set_tty_state = ser_dummy_noflush_set_tty_state;
  ops->setbaudrate = ser_dummy_setbaudrate;
  ops->setstopbits = ser_dummy_setstopbits;
  ops->drain_output = ser_dummy_drain_output;
  ops->async = ser_dummy_async;
  serial_add_interface (ops);
}
