mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-06-30 19:12:48 -05:00
Turn Backend into a sensible classoid.
Nearly every part of the code that ever handles a full backend structure has historically done it using a pair of pointer variables, one pointing at a constant struct full of function pointers, and the other pointing to a 'void *' state object that's passed to each of those. While I'm modernising the rest of the code, this seems like a good time to turn that into the same more or less type-safe and less cumbersome system as I'm using for other parts of the code, such as Socket, Plug, BinaryPacketProtocol and so forth: the Backend structure contains a vtable pointer, and a system of macro wrappers handles dispatching through that vtable.
This commit is contained in:
52
unix/uxser.c
52
unix/uxser.c
@ -23,6 +23,7 @@ typedef struct serial_backend_data {
|
||||
int finished;
|
||||
int inbufsize;
|
||||
bufchain output_data;
|
||||
Backend backend;
|
||||
} *Serial;
|
||||
|
||||
/*
|
||||
@ -287,7 +288,7 @@ static const char *serial_configure(Serial serial, Conf *conf)
|
||||
* Also places the canonical host name into `realhost'. It must be
|
||||
* freed by the caller.
|
||||
*/
|
||||
static const char *serial_init(void *frontend_handle, void **backend_handle,
|
||||
static const char *serial_init(void *frontend_handle, Backend **backend_handle,
|
||||
Conf *conf,
|
||||
const char *host, int port, char **realhost,
|
||||
int nodelay, int keepalive)
|
||||
@ -297,7 +298,8 @@ static const char *serial_init(void *frontend_handle, void **backend_handle,
|
||||
char *line;
|
||||
|
||||
serial = snew(struct serial_backend_data);
|
||||
*backend_handle = serial;
|
||||
serial->backend.vt = &serial_backend;
|
||||
*backend_handle = &serial->backend;
|
||||
|
||||
serial->frontend = frontend_handle;
|
||||
serial->finished = FALSE;
|
||||
@ -345,9 +347,9 @@ static void serial_close(Serial serial)
|
||||
}
|
||||
}
|
||||
|
||||
static void serial_free(void *handle)
|
||||
static void serial_free(Backend *be)
|
||||
{
|
||||
Serial serial = (Serial) handle;
|
||||
Serial serial = FROMFIELD(be, struct serial_backend_data, backend);
|
||||
|
||||
serial_close(serial);
|
||||
|
||||
@ -356,9 +358,9 @@ static void serial_free(void *handle)
|
||||
sfree(serial);
|
||||
}
|
||||
|
||||
static void serial_reconfig(void *handle, Conf *conf)
|
||||
static void serial_reconfig(Backend *be, Conf *conf)
|
||||
{
|
||||
Serial serial = (Serial) handle;
|
||||
Serial serial = FROMFIELD(be, struct serial_backend_data, backend);
|
||||
|
||||
/*
|
||||
* FIXME: what should we do if this returns an error?
|
||||
@ -460,9 +462,9 @@ static void serial_try_write(Serial serial)
|
||||
/*
|
||||
* Called to send data down the serial connection.
|
||||
*/
|
||||
static int serial_send(void *handle, const char *buf, int len)
|
||||
static int serial_send(Backend *be, const char *buf, int len)
|
||||
{
|
||||
Serial serial = (Serial) handle;
|
||||
Serial serial = FROMFIELD(be, struct serial_backend_data, backend);
|
||||
|
||||
if (serial->fd < 0)
|
||||
return 0;
|
||||
@ -476,16 +478,16 @@ static int serial_send(void *handle, const char *buf, int len)
|
||||
/*
|
||||
* Called to query the current sendability status.
|
||||
*/
|
||||
static int serial_sendbuffer(void *handle)
|
||||
static int serial_sendbuffer(Backend *be)
|
||||
{
|
||||
Serial serial = (Serial) handle;
|
||||
Serial serial = FROMFIELD(be, struct serial_backend_data, backend);
|
||||
return bufchain_size(&serial->output_data);
|
||||
}
|
||||
|
||||
/*
|
||||
* Called to set the size of the window
|
||||
*/
|
||||
static void serial_size(void *handle, int width, int height)
|
||||
static void serial_size(Backend *be, int width, int height)
|
||||
{
|
||||
/* Do nothing! */
|
||||
return;
|
||||
@ -494,9 +496,9 @@ static void serial_size(void *handle, int width, int height)
|
||||
/*
|
||||
* Send serial special codes.
|
||||
*/
|
||||
static void serial_special(void *handle, Telnet_Special code)
|
||||
static void serial_special(Backend *be, Telnet_Special code)
|
||||
{
|
||||
Serial serial = (Serial) handle;
|
||||
Serial serial = FROMFIELD(be, struct serial_backend_data, backend);
|
||||
|
||||
if (serial->fd >= 0 && code == TS_BRK) {
|
||||
tcsendbreak(serial->fd, 0);
|
||||
@ -510,7 +512,7 @@ static void serial_special(void *handle, Telnet_Special code)
|
||||
* Return a list of the special codes that make sense in this
|
||||
* protocol.
|
||||
*/
|
||||
static const struct telnet_special *serial_get_specials(void *handle)
|
||||
static const struct telnet_special *serial_get_specials(Backend *be)
|
||||
{
|
||||
static const struct telnet_special specials[] = {
|
||||
{"Break", TS_BRK},
|
||||
@ -519,24 +521,24 @@ static const struct telnet_special *serial_get_specials(void *handle)
|
||||
return specials;
|
||||
}
|
||||
|
||||
static int serial_connected(void *handle)
|
||||
static int serial_connected(Backend *be)
|
||||
{
|
||||
return 1; /* always connected */
|
||||
}
|
||||
|
||||
static int serial_sendok(void *handle)
|
||||
static int serial_sendok(Backend *be)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void serial_unthrottle(void *handle, int backlog)
|
||||
static void serial_unthrottle(Backend *be, int backlog)
|
||||
{
|
||||
Serial serial = (Serial) handle;
|
||||
Serial serial = FROMFIELD(be, struct serial_backend_data, backend);
|
||||
serial->inbufsize = backlog;
|
||||
serial_uxsel_setup(serial);
|
||||
}
|
||||
|
||||
static int serial_ldisc(void *handle, int option)
|
||||
static int serial_ldisc(Backend *be, int option)
|
||||
{
|
||||
/*
|
||||
* Local editing and local echo are off by default.
|
||||
@ -544,19 +546,19 @@ static int serial_ldisc(void *handle, int option)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void serial_provide_ldisc(void *handle, Ldisc *ldisc)
|
||||
static void serial_provide_ldisc(Backend *be, Ldisc *ldisc)
|
||||
{
|
||||
/* This is a stub. */
|
||||
}
|
||||
|
||||
static void serial_provide_logctx(void *handle, LogContext *logctx)
|
||||
static void serial_provide_logctx(Backend *be, LogContext *logctx)
|
||||
{
|
||||
/* This is a stub. */
|
||||
}
|
||||
|
||||
static int serial_exitcode(void *handle)
|
||||
static int serial_exitcode(Backend *be)
|
||||
{
|
||||
Serial serial = (Serial) handle;
|
||||
Serial serial = FROMFIELD(be, struct serial_backend_data, backend);
|
||||
if (serial->fd >= 0)
|
||||
return -1; /* still connected */
|
||||
else
|
||||
@ -567,12 +569,12 @@ static int serial_exitcode(void *handle)
|
||||
/*
|
||||
* cfg_info for Serial does nothing at all.
|
||||
*/
|
||||
static int serial_cfg_info(void *handle)
|
||||
static int serial_cfg_info(Backend *be)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
Backend serial_backend = {
|
||||
const struct Backend_vtable serial_backend = {
|
||||
serial_init,
|
||||
serial_free,
|
||||
serial_reconfig,
|
||||
|
Reference in New Issue
Block a user