@@ -632,8 +632,8 @@ global:
l_term_set_output;
l_term_set_output_stdout;
l_term_set_key_handler;
- l_term_open;
- l_term_close;
+ l_term_acquire;
+ l_term_release;
l_term_io_callback;
l_term_process;
l_term_putnstr;
@@ -126,7 +126,7 @@ struct l_term {
unsigned short num_row;
unsigned short num_col;
struct l_signal *sigwinch;
- bool is_running;
+ bool is_acquired;
char key_buf[8];
size_t key_len;
l_term_key_func_t key_handler;
@@ -145,7 +145,7 @@ LIB_EXPORT struct l_term *l_term_new(void)
term->out_fd = -1;
term->out_ops = NULL;
- term->is_running = false;
+ term->is_acquired = false;
return term;
}
@@ -241,7 +241,7 @@ static void sigwinch_handler(void *user_data)
&term->num_row, &term->num_col);
}
-LIB_EXPORT int l_term_open(struct l_term *term)
+LIB_EXPORT int l_term_acquire(struct l_term *term)
{
struct termios termios;
int retval = 0;
@@ -249,6 +249,9 @@ LIB_EXPORT int l_term_open(struct l_term *term)
if (!term)
return -EINVAL;
+ if (term->is_acquired)
+ return -EALREADY;
+
/* Missing input or output file descriptor is a non-recoverable
* situation at this point.
*/
@@ -317,19 +320,20 @@ LIB_EXPORT int l_term_open(struct l_term *term)
IO_HANDLER(term, term->in_fd, 1, 0);
IO_HANDLER(term, term->out_fd, 0, 1);
- term->is_running = true;
+ term->is_acquired = true;
return retval;
}
-LIB_EXPORT int l_term_close(struct l_term *term)
+LIB_EXPORT int l_term_release(struct l_term *term)
{
int retval = 0;
if (!term)
return -EINVAL;
- term->is_running = false;
+ if (!term->is_acquired)
+ return -EALREADY;
IO_HANDLER(term, term->in_fd, 0, 0);
IO_HANDLER(term, term->out_fd, 0, 0);
@@ -347,6 +351,8 @@ LIB_EXPORT int l_term_close(struct l_term *term)
if (retval < 0)
return retval;
+ term->is_acquired = false;
+
return retval;
}
@@ -44,8 +44,8 @@ typedef void (*l_term_key_func_t) (struct l_term *term, wint_t wch, void *user_d
int l_term_set_key_handler(struct l_term *term,
l_term_key_func_t handler, void *user_data);
-int l_term_open(struct l_term *term);
-int l_term_close(struct l_term *term);
+int l_term_acquire(struct l_term *term);
+int l_term_release(struct l_term *term);
bool l_term_io_callback(struct l_io *io, void *user_data);