1 /** @file
2 NonCanonical Interactive Input Function.
3
4 The functions assume that isatty() is TRUE at the time they are called.
5 If _S_IWTTY is set, the device returns WIDE characters.
6
7 Copyright (c) 2012 - 2014, Intel Corporation. All rights reserved.<BR>
8 This program and the accompanying materials are licensed and made available
9 under the terms and conditions of the BSD License which accompanies this
10 distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php.
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 **/
16 #include <LibConfig.h>
17
18 #include <sys/syslimits.h>
19 #include <sys/termios.h>
20 #include <Containers/Fifo.h>
21 #include <Device/IIO.h>
22
23 /** Perform a noncanonical read of input.
24
25 @param[in] filp Pointer to a file descriptor structure.
26 @param[in] BufferSize Maximum number of bytes to return.
27
28 @retval -1 An error has occurred. Reason in errno.
29 @retval -1 No data returned. None was ready.
30 @retval >0 The number of elements returned
31 **/
32 ssize_t
IIO_NonCanonRead(struct __filedes * filp)33 IIO_NonCanonRead (
34 struct __filedes *filp
35 )
36 {
37 cIIO *This;
38 cFIFO *InBuf;
39 struct termios *Termio;
40 EFI_STATUS Status;
41 ssize_t NumRead;
42 cc_t tioMin;
43 cc_t tioTime;
44 UINT32 InputType;
45 wchar_t InChar; // Intermediate character buffer
46
47 NumRead = -1;
48 InChar = 0; // Initialize so compilers don't complain.
49 This = filp->devdata;
50 Termio = &This->Termio;
51 InBuf = This->InBuf;
52 tioMin = Termio->c_cc[VMIN];
53 tioTime = Termio->c_cc[VTIME];
54
55 if(tioMin >= MAX_INPUT) {
56 tioMin = MAX_INPUT;
57 }
58 /* There are four types of processing that may be done, based on
59 the values of tioMin and tioTime.
60 Min Time Type
61 --- ---- ----
62 0 0 0 Return buffer contents or 1 new char
63 0 >0 1 Return 0 or 1 character depending on timeout
64 >0 0 2 Buffer Min chars. Return BufferSize chars.
65 >0 >0 3 Return up to Min chars. Unless the inter-byte timer expires.
66
67 Currently, only type 0 is implemented.
68 */
69 InputType = 0;
70 if(tioMin != 0) InputType = 2;
71 if(tioTime != 0) ++InputType;
72 //switch(InputType) {
73 // case 0:
74 if(InBuf->IsEmpty(InBuf)) {
75 NumRead = filp->f_ops->fo_read(filp, &filp->f_offset, sizeof(wchar_t), &InChar);
76 if(NumRead > 0) {
77 Status = InBuf->Write(InBuf, &InChar, 1); // Buffer the character
78 }
79 }
80 // break;
81 // case 1:
82 // break;
83 // case 2:
84 // break;
85 // case 3:
86 // break;
87 //}
88 return NumRead;
89 }
90