1
0
mirror of https://github.com/UzixLS/picocom.git synced 2025-07-19 07:21:18 +03:00

Add term init and fini methods

Added term_ops init and fini methods to abstract fd checks.
This commit is contained in:
David Leonard
2018-02-10 19:32:26 +10:00
committed by Nick Patavalis
parent 2a949e0568
commit ebc3566492
2 changed files with 15 additions and 0 deletions

13
term.c
View File

@ -420,6 +420,17 @@ term_new (int fd, const struct term_ops *ops)
memset(rval, 0, sizeof *rval);
rval->fd = fd;
rval->ops = ops;
if (ops->init) {
int r = ops->init(rval);
if ( r < 0 ) {
/* Failed to init, abandon allocation */
rval->fd = -1;
rval = NULL;
break;
}
}
} while (0);
return rval;
@ -432,6 +443,8 @@ term_free (int fd)
for (i = 0; i < MAX_TERMS; i++) {
if ( term[i].fd == fd ) {
if (term[i].ops->fini)
term[i].ops->fini(&term[i]);
term[i].fd = -1;
break;
}

View File

@ -15,6 +15,8 @@ struct term_s {
/* Operations on a term */
struct term_ops {
int (*init)(struct term_s *t);
void (*fini)(struct term_s *t);
int (*tcgetattr)(struct term_s *t, struct termios *termios_out);
int (*tcsetattr)(struct term_s *t, int when, const struct termios *termios);
int (*modem_get)(struct term_s *t, int *modem_out);