1 /** @file
2   Utilities for Interactive I/O Functions.
3 
4   The functions assume that isatty() is TRUE at the time they are called.
5 
6   Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
7   This program and the accompanying materials are licensed and made available
8   under the terms and conditions of the BSD License which accompanies this
9   distribution.  The full text of the license may be found at
10   http://opensource.org/licenses/bsd-license.php.
11 
12   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 **/
15 #ifndef _IIO_UTILITIES_H
16 #define _IIO_UTILITIES_H
17 
18 #include  <sys/EfiSysCall.h>
19 
20 __BEGIN_DECLS
21 
22 /** Get the low-level UEFI protocol associated with an open file.
23 
24     @param[in]    fd    File descriptor for an open file.
25     @param[out]   filp  NULL, or a pointer to where a pointer to the file's
26                         file descriptor structure is to be stored.
27 
28     @return   Returns NULL if fd is not a valid file descriptor, otherwise
29               a pointer to the file's associated UEFI protocol is returned.
30 **/
31 void *
32 EFIAPI
33 IIO_GetDeviceProto (
34   int                 fd,
35   struct __filedes  **filp    // Optional - filp == NULL if unused
36   );
37 
38 /** Get a character either from the input buffer or from hardware.
39 
40     @param[in]    filp      Pointer to a file descriptor structure.
41     @param[in]    First     Set to TRUE to identify the initial read.
42 
43     @return   Returns a character read from either the input buffer
44               or from the open file (device) identified by filp.
45               A return value of WEOF indicates an error has occurred.
46 **/
47 wint_t
48 EFIAPI
49 IIO_GetInChar (
50   struct __filedes *filp,
51   BOOLEAN           First
52   );
53 
54 /** Get the current cursor position.
55 
56     @param[in]      fd      File descriptor for an open file.
57     @param[out]     Column  Pointer to where the current cursor column is to be stored.
58     @param[out]     Row     Pointer to where the current cursor row is to be stored.
59 
60     @retval   -1    fd is not an IIO output device.
61     @retval    0    Cursor position retrieved, Cursor is Not Visible.
62     @retval    1    Cursor position retrieved, Cursor is Visible.
63 **/
64 int
65 EFIAPI
66 IIO_GetCursorPosition (
67   int       fd,
68   UINT32   *Column,
69   UINT32   *Row
70   );
71 
72 /** Set the cursor position.
73 
74     @param[in]    filp    Pointer to the output device's file descriptor structure.
75     @param[in]    StartXY Pointer to a cursor coordinate (XY) structure indicating
76                           the desired coordinate to move the cursor to.
77 
78     @retval   -1    fd is not an IIO output device
79     @retval    0    Cursor position set successfully.
80 **/
81 int
82 EFIAPI
83 IIO_SetCursorPosition (
84   struct __filedes *filp,
85   CURSOR_XY        *StartXY
86   );
87 
88 /** Get Output screen size and mode.
89 
90     @param[in]    fd    File descriptor of the output device.
91     @param[out]   Col   Pointer to where to store the MAX Column, or NULL.
92     @param[out]   Row   Pointer to where to store the MAX Row, or NULL.
93 
94     @retval   <0    An error occurred.  The reason is in errno and EFIerrno.
95                       * EIO     UEFI QueryMode failed
96                       * ENOTTY  fd does not refer to an interactive output device
97     @retval   >=0   Current output mode
98 **/
99 int
100 EFIAPI
101 IIO_GetOutputSize (
102   int       fd,
103   UINTN    *Col,
104   UINTN    *Row
105 );
106 
107 /** Calculate the number of character positions between two X/Y coordinate pairs.
108 
109     Using the current output device characteristics, calculate the number of
110     characters between two coordinates.
111 
112     @param[in]      This      Pointer to the IIO instance to be examined.
113     @param[in]      StartXY   Pointer to the starting coordinate pair.
114     @param[in]      EndXY     Pointer to the ending coordinate pair.
115 
116     @return   Returns the difference between the starting and ending coordinates.
117               The return value is positive if the coordinates contained in EndXY
118               are larger than StartXY, otherwise the return value is negative.
119 **/
120 int
121 EFIAPI
122 IIO_CursorDelta (
123   cIIO         *This,
124   CURSOR_XY    *StartXY,
125   CURSOR_XY    *EndXY
126   );
127 
128 __END_DECLS
129 #endif  /* _IIO_UTILITIES_H */
130