/[hurd]/hurd/console-client/console.c
ViewVC logotype

Diff of /hurd/console-client/console.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by marcus, Sun Mar 21 19:57:00 2004 UTC revision 1.5 by marco_g, Thu Jan 6 21:43:53 2005 UTC
# Line 1  Line 1 
1  /* console.c -- A pluggable console client.  /* console.c -- A pluggable console client.
2     Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.     Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
3     Written by Marcus Brinkmann.     Written by Marcus Brinkmann.
4    
5     This program is free software; you can redistribute it and/or     This program is free software; you can redistribute it and/or
# Line 34  Line 34 
34    
35  #include "driver.h"  #include "driver.h"
36  #include "timer.h"  #include "timer.h"
37    #include "trans.h"
38    
39  const char *cons_client_name = "console";  const char *cons_client_name = "console";
40  const char *cons_client_version = HURD_VERSION;  const char *cons_client_version = HURD_VERSION;
41    
42    /* The default node on which the console node is started.  */
43    #define DEFAULT_CONSOLE_NODE    "/dev/cons"
44    
45    
46  /* The global lock protects the active_vcons variable, and thus all  /* The global lock protects the active_vcons variable, and thus all
47     operations on the virtual console that is currently active.  */     operations on the virtual console that is currently active.  */
# Line 47  static struct mutex global_lock; Line 51  static struct mutex global_lock;
51     displayed.  */     displayed.  */
52  static vcons_t active_vcons = NULL;  static vcons_t active_vcons = NULL;
53    
54    /* Contains the VT id when switched away.  */
55    static int saved_id = 0;
56    
57    /* The console, used to switch back.  */
58    static cons_t saved_cons;
59    
60    /* The pathname of the node on which the translator is set.  */
61    static char *consnode_path;
62    
63    
64  /* Callbacks for input source drivers.  */  /* Callbacks for input source drivers.  */
65    
# Line 121  console_input (char *buf, size_t size) Line 134  console_input (char *buf, size_t size)
134  }  }
135    
136    
137    /* Report the mouse event EV to the currently active console.  This
138       can be called by the input driver at any time.  */
139    error_t
140    console_move_mouse (mouse_event_t ev)
141    {
142      error_t err;
143      vcons_t vcons;
144    
145      mutex_lock (&global_lock);
146      
147      vcons = active_vcons;
148      if (!vcons)
149        {
150          mutex_unlock (&global_lock);
151          return EINVAL;
152        }
153      ports_port_ref (vcons);
154      mutex_unlock (&global_lock);
155    
156      if (vcons)
157        {
158          err = cons_vcons_move_mouse (vcons, ev);
159          ports_port_deref (vcons);
160        }
161    
162      mutex_unlock (&global_lock);
163    
164      return 0;
165    }
166    
167    
168  /* Scroll the active console by TYPE and VALUE as specified by  /* Scroll the active console by TYPE and VALUE as specified by
169     cons_vcons_scrollback.  */     cons_vcons_scrollback.  */
170  int  int
# Line 148  console_scrollback (cons_scroll_t type, Line 192  console_scrollback (cons_scroll_t type,
192  }  }
193    
194    
195    /* Switch away from the console an external use of the console like
196       XFree.  */
197    void
198    console_switch_away (void)
199    {
200      mutex_lock (&global_lock);
201    
202      driver_iterate
203        if (driver->ops->save_status)
204          driver->ops->save_status (driver->handle);
205    
206      saved_id = active_vcons->id;
207      saved_cons = active_vcons->cons;
208      cons_vcons_close (active_vcons);
209      active_vcons = NULL;
210      mutex_unlock (&global_lock);
211    }
212    
213    /* Switch back to the console client from an external user of the
214       console like XFree.  */
215    void
216    console_switch_back (void)
217    {
218      vcons_list_t conslist;
219      mutex_lock (&global_lock);
220    
221      driver_iterate
222        if (driver->ops->restore_status)
223          driver->ops->restore_status (driver->handle);
224      
225      if (saved_cons)
226        {
227          error_t err;
228    
229          err = cons_lookup (saved_cons, saved_id, 1, &conslist);
230          if (err)
231            {
232              mutex_unlock (&global_lock);
233              return;
234            }
235    
236          err = cons_vcons_open (saved_cons, conslist, &active_vcons);
237          if (err)
238            {
239              mutex_unlock (&global_lock);
240              return;
241            }
242            
243          conslist->vcons = active_vcons;
244          saved_cons = NULL;
245          mutex_unlock (&active_vcons->lock);
246        }
247      mutex_unlock (&global_lock);
248    }
249    
250    
251  /* Exit the console client.  Does not return.  */  /* Exit the console client.  Does not return.  */
252  void  void
253  console_exit (void)  console_exit (void)
# Line 371  cons_vcons_set_dimension (vcons_t vcons, Line 471  cons_vcons_set_dimension (vcons_t vcons,
471    return 0;    return 0;
472  }  }
473    
474    
475    error_t
476    cons_vcons_set_mousecursor_pos (vcons_t vcons, float x, float y)
477    {
478      mutex_lock (&global_lock);
479      if (vcons == active_vcons)
480        display_iterate
481          if (display->ops->set_mousecursor_pos)
482            display->ops->set_mousecursor_pos (display->handle, x, y);
483      mutex_unlock (&global_lock);
484      return 0;
485    }
486    
487    
488    error_t
489    cons_vcons_set_mousecursor_status (vcons_t vcons, int status)
490    {
491      mutex_lock (&global_lock);
492      if (vcons == active_vcons)
493        display_iterate
494          if (display->ops->set_mousecursor_status)
495            display->ops->set_mousecursor_status (display->handle, status);
496      mutex_unlock (&global_lock);
497      return 0;
498    
499    }
500    
501    
502  /* Console-specific options.  */  /* Console-specific options.  */
503  static const struct argp_option  static const struct argp_option
# Line 378  options[] = Line 505  options[] =
505    {    {
506      {"driver-path", 'D', "PATH", 0, "Specify search path for driver modules" },      {"driver-path", 'D', "PATH", 0, "Specify search path for driver modules" },
507      {"driver", 'd', "NAME", 0, "Add driver NAME to the console" },      {"driver", 'd', "NAME", 0, "Add driver NAME to the console" },
508        {"console-node", 'c', "FILE", OPTION_ARG_OPTIONAL,
509         "Set a translator on the node FILE (default: " DEFAULT_CONSOLE_NODE ")" },
510      {0}      {0}
511    };    };
512    
# Line 426  parse_opt (int key, char *arg, struct ar Line 555  parse_opt (int key, char *arg, struct ar
555        devcount++;        devcount++;
556        break;        break;
557    
558        case 'c':
559          consnode_path = arg ? arg : DEFAULT_CONSOLE_NODE;
560          if (!consnode_path)
561            return ENOMEM;
562          break;
563          
564      case ARGP_KEY_SUCCESS:      case ARGP_KEY_SUCCESS:
565        if (!devcount)        if (!devcount)
566          {          {
# Line 477  main (int argc, char *argv[]) Line 612  main (int argc, char *argv[])
612        error (1, err, "Timer thread initialization failed");        error (1, err, "Timer thread initialization failed");
613      }      }
614    
615      if (consnode_path)
616        console_setup_node (consnode_path);
617      
618    cons_server_loop ();    cons_server_loop ();
619    
620    /* Never reached.  */    /* Never reached.  */

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26