summaryrefslogtreecommitdiff
path: root/libcons/cons-lookup.c
diff options
context:
space:
mode:
authorMarcus Brinkmann <marcus@gnu.org>2002-09-08 21:55:59 +0000
committerMarcus Brinkmann <marcus@gnu.org>2002-09-08 21:55:59 +0000
commit18cfa8b70ce9a6a3572908115f98211f3fa9a367 (patch)
tree42fd94dea9b27bb7020154a39a834429e936a560 /libcons/cons-lookup.c
parent187b5b4b28eba6990f7e43a5288a71b62a271dd9 (diff)
libcons/
2002-09-09 Marcus Brinkmann <marcus@gnu.org> * vcons-remove.c: New file. * Makefile (SRCS): Add vcons-destroy.c. * cons.h: New type vcons_list_t. (struct vcons_list): New structure. (struct cons_notify): Remove VCONS member. (struct vcons): Remove members NEXT, PREV and NOTIFY. Add the notify structure to the top to make it possible to use a vcons as a port. New member VCONS_ENTRY. (struct cons): Change type of members vcons_list and vcons_last to vcons_list_t. Remove member active. (cons_vcons_add): Change prototype to match new definition. (cons_vcons_remove): Likewise. (cons_switch): Likewise. (cons_lookup): Likewise. (cons_vcons_open): Likewise. (cons_vcons_destroy): New prototype. * cons-lookup.c (cons_lookup): Change type of R_VCONS argument vcons_list_t. Change type of previous_vcons and vcons variables to vcons_list_t. Append _entry to all these variables. Don't allocate and initialize a vcons_t, but a vcons_list_t. After this has been added to the list, call cons_vcons_add. * cons-switch.c: Do not include <error.h> (cons_switch): Add arguments ACTIVE_ID and R_VCONS. New variable ERR and VCONS_ENTRY. Remove variable ACTIVE. Do not keep track of active console. Instead, look it up using ACTIVE_ID. Lock the returned console. Call cons_vcons_open, not cons_vcons_activate. * dir-changed.c (add_one): Change VCONS to VCONS_ENTRY and its type from vcons_t to vcons_list_t to follow cons_lookup change. (lookup_one): Likewise. (cons_S_dir_changed): Likewise. * file-changed.c (cons_S_file_changed): Cast NOTIFY to VCONS. Check that NOTIFY->cons is not set instead that NOTIFY->vcons is. * init-init.c (cons_init): Pass cons_vcons_destroy as clean_routine to ports_create_class. Don't initialize CONS->active, nor DIR_NOTIFY_PORT->vcons. * vcons-add.c (cons_vcons_add): Change argument VCONS to CONS and VCONS_ENTRY. Don't do anything here (the user must implement it all). * vcons-close.c: Don't include <errno.h>, <unistd.h>, <stdio.h>, <sys/mman.h>, <sys/fcntl.h>, <mach.h>. Include <assert.h>, <hurd/ports.h> and <cthreads.h>. (cons_vcons_close): Clear VCONS->vcons_entry->vcons. Derefence and destroy VCONS. * vcons-open.c (cons_vcons_open): Change arguments from VCONS to CONS, VCONS_ENTRY and R_VCONS. New variable VCONS. Set up VCONS as a port, and request notification messages on that. * vcons-remove.c: Do not include <errno.h>. (cons_vcons_remove): Assert that VCONS_ENTRY does not have an open VCONS. utils/ 2002-09-09 Marcus Brinkmann <marcus@gnu.org> * console-ncurses.c: New global variable global_lock. (main): Initialize global_lock. (cons_vcons_activate): Removed. (console_switch): New function. (cons_vcons_add): New function. (input_loop): Call console_switch, not cons_switch. Do not take active_vcons lock but global_lock. (cons_vcons_update): Take global lock. (cons_vcons_set_cursor_pos): Likewise. (cons_vcons_set_cursor_status): Likewise. (cons_vcons_scroll): Likewise. (cons_vcons_write): Likewise. (cons_vcons_beep): Likewise. (cons_vcons_flash): Likewise.
Diffstat (limited to 'libcons/cons-lookup.c')
-rw-r--r--libcons/cons-lookup.c97
1 files changed, 35 insertions, 62 deletions
diff --git a/libcons/cons-lookup.c b/libcons/cons-lookup.c
index f3bdabef..d91cc3ce 100644
--- a/libcons/cons-lookup.c
+++ b/libcons/cons-lookup.c
@@ -24,16 +24,16 @@
#include "cons.h"
-/* Lookup the virtual console with number ID in the console CONS,
- acquire a reference for it, and return it in R_VCONS. If CREATE is
- true, the virtual console will be created if it doesn't exist yet.
- If CREATE is true, and ID 0, the first free virtual console id is
+/* Lookup the virtual console entry with number ID in the console
+ CONS, and return it in R_VCONS_ENTRY. If CREATE is true, the
+ virtual console entry will be created if it doesn't exist yet. If
+ CREATE is true, and ID 0, the first free virtual console id is
used. CONS must be locked. */
error_t
-cons_lookup (cons_t cons, int id, int create, vcons_t *r_vcons)
+cons_lookup (cons_t cons, int id, int create, vcons_list_t *r_vcons_entry)
{
- vcons_t previous_vcons = 0;
- vcons_t vcons;
+ vcons_list_t previous_vcons_entry = 0;
+ vcons_list_t vcons_entry;
if (!id && !create)
return EINVAL;
@@ -42,13 +42,13 @@ cons_lookup (cons_t cons, int id, int create, vcons_t *r_vcons)
{
if (cons->vcons_list && cons->vcons_list->id <= id)
{
- previous_vcons = cons->vcons_list;
- while (previous_vcons->next && previous_vcons->next->id <= id)
- previous_vcons = previous_vcons->next;
- if (previous_vcons->id == id)
+ previous_vcons_entry = cons->vcons_list;
+ while (previous_vcons_entry->next
+ && previous_vcons_entry->next->id <= id)
+ previous_vcons_entry = previous_vcons_entry->next;
+ if (previous_vcons_entry->id == id)
{
- /* previous_vcons->refcnt++; */
- *r_vcons = previous_vcons;
+ *r_vcons_entry = previous_vcons_entry;
return 0;
}
}
@@ -60,75 +60,48 @@ cons_lookup (cons_t cons, int id, int create, vcons_t *r_vcons)
id = 1;
if (cons->vcons_list && cons->vcons_list->id == 1)
{
- previous_vcons = cons->vcons_list;
- while (previous_vcons && previous_vcons->id == id)
+ previous_vcons_entry = cons->vcons_list;
+ while (previous_vcons_entry && previous_vcons_entry->id == id)
{
id++;
- previous_vcons = previous_vcons->next;
+ previous_vcons_entry = previous_vcons_entry->next;
}
}
}
- vcons = calloc (1, sizeof (struct vcons));
- if (!vcons)
- {
- mutex_unlock (&vcons->cons->lock);
- return ENOMEM;
- }
- vcons->cons = cons;
- /* vcons->refcnt = 1; */
- vcons->id = id;
- mutex_init (&vcons->lock);
- vcons->input = -1;
- vcons->display = MAP_FAILED;
- vcons->notify = NULL;
+ vcons_entry = calloc (1, sizeof (struct vcons_list));
+ if (!vcons_entry)
+ return ENOMEM;
-#if 0
- err = display_create (&vcons->display, cons->encoding ?: DEFAULT_ENCODING,
- cons->foreground, cons->background);
- if (err)
- {
- free (vcons->name);
- free (vcons);
- return err;
- }
-
- err = input_create (&vcons->input, cons->encoding ?: DEFAULT_ENCODING);
- if (err)
- {
- display_destroy (vcons->display);
- free (vcons->name);
- free (vcons);
- return err;
- }
-#endif
-
- cons_vcons_add (vcons);
+ vcons_entry->id = id;
+ vcons_entry->vcons = NULL;
/* Insert the virtual console into the doubly linked list. */
- if (previous_vcons)
+ if (previous_vcons_entry)
{
- vcons->prev = previous_vcons;
- if (previous_vcons->next)
+ vcons_entry->prev = previous_vcons_entry;
+ if (previous_vcons_entry->next)
{
- previous_vcons->next->prev = vcons;
- vcons->next = previous_vcons->next;
+ previous_vcons_entry->next->prev = vcons_entry;
+ vcons_entry->next = previous_vcons_entry->next;
}
else
- cons->vcons_last = vcons;
- previous_vcons->next = vcons;
+ cons->vcons_last = vcons_entry;
+ previous_vcons_entry->next = vcons_entry;
}
else
{
if (cons->vcons_list)
{
- cons->vcons_list->prev = vcons;
- vcons->next = cons->vcons_list;
+ cons->vcons_list->prev = vcons_entry;
+ vcons_entry->next = cons->vcons_list;
}
else
- cons->vcons_last = vcons;
- cons->vcons_list = vcons;
+ cons->vcons_last = vcons_entry;
+ cons->vcons_list = vcons_entry;
}
- *r_vcons = vcons;
+
+ cons_vcons_add (cons, vcons_entry);
+ *r_vcons_entry = vcons_entry;
return 0;
}