xref: /haiku/src/apps/terminal/TermParse.h (revision 0c93c0a807b27096abbfad677436afb7d1712d4a)
1 /*
2  * Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net>
3  * Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files or portions
7  * thereof (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so, subject
11  * to the following conditions:
12  *
13  *  * Redistributions of source code must retain the above copyright notice,
14  *    this list of conditions and the following disclaimer.
15  *
16  *  * Redistributions in binary form must reproduce the above copyright notice
17  *    in the  binary, as well as this list of conditions and the following
18  *    disclaimer in the documentation and/or other materials provided with
19  *    the distribution.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27  * THE SOFTWARE.
28  *
29  */
30 
31 #ifndef TERMPARSE_H
32 #define TERMPARSE_H
33 
34 #include <OS.h>
35 #include <MessageRunner.h>
36 
37 #include "TermConst.h"
38 
39 class TermView;
40 class CodeConv;
41 class TermWindow;
42 
43 //PtyReader buffer size.
44 #define READ_BUF_SIZE 2048
45 
46 class TermParse : public BHandler {
47 public:
48 	TermParse(int fd, TermWindow *inWinObj, TermView *inViewObj, CodeConv *inConvObj);
49 	~TermParse();
50 
51 	status_t StartThreads();
52 
53 private:
54 	// Initialize TermParse and PtyReader thread.
55 	status_t InitTermParse();
56 	status_t InitPtyReader();
57 
58 	// Delete TermParse and PtyReader thread.
59 	status_t AbortTermParse();
60 	status_t AbortPtyReader();
61 
62 	int32 EscParse();
63 	int32 PtyReader();
64 
65 	static int32 _ptyreader_thread(void *);
66 	static int32 _escparse_thread(void *);
67 
68 	// Reading ReadBuf at one Char.
69 	status_t GetReaderBuf(uchar &c);
70 
71 	int fFd;
72 
73 	TermView *fViewObj;
74 	TermWindow *fWinObj;
75 	CodeConv *fConvObj;
76 
77 	thread_id fParseThread;
78 	sem_id fParseSem;
79 
80 	thread_id fReaderThread;
81 	sem_id fReaderSem;
82 	sem_id fReaderLocker;
83 
84 	BMessageRunner *fCursorUpdate;
85 
86 	uint fParser_p;	/* EscParse reading buffer pointer */
87 	int fLockFlag;	/* PtyReader lock flag */
88 
89 	bool fQuitting;
90 
91 	uchar fReadBuf[READ_BUF_SIZE]; /* Reading buffer */
92 };
93 
94 #endif // TERMPARSE_H
95