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:

committed by
Nick Patavalis

parent
2a949e0568
commit
ebc3566492
13
term.c
13
term.c
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user