xref: /haiku/src/apps/terminal/TermParse.h (revision 5115ca085884f7b604a3d607688f0ca20fb7cf57)
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 #ifndef TERMPARSE_H
31 #define TERMPARSE_H
32 
33 
34 #include "TermConst.h"
35 
36 #include <OS.h>
37 #include <MessageRunner.h>
38 
39 
40 class TermView;
41 class CodeConv;
42 class TermWindow;
43 
44 //PtyReader buffer size.
45 #define READ_BUF_SIZE 2048
46 
47 class TermParse : public BHandler {
48 public:
49 	TermParse(int fd, TermWindow *inWinObj, TermView *inViewObj, CodeConv *inConvObj);
50 	~TermParse();
51 
52 	status_t StartThreads();
53 
54 private:
55 	// Initialize TermParse and PtyReader thread.
56 	status_t InitTermParse();
57 	status_t InitPtyReader();
58 
59 	// Delete TermParse and PtyReader thread.
60 	status_t AbortTermParse();
61 	status_t AbortPtyReader();
62 
63 	int32 EscParse();
64 	int32 PtyReader();
65 
66 	static int32 _ptyreader_thread(void *);
67 	static int32 _escparse_thread(void *);
68 
69 	// Reading ReadBuf at one Char.
70 	status_t GetReaderBuf(uchar &c);
71 
72 	int fFd;
73 
74 	TermView *fViewObj;
75 	TermWindow *fWinObj;
76 	CodeConv *fConvObj;
77 
78 	thread_id fParseThread;
79 	sem_id fParseSem;
80 
81 	thread_id fReaderThread;
82 	sem_id fReaderSem;
83 	sem_id fReaderLocker;
84 
85 	BMessageRunner *fCursorUpdate;
86 
87 	uint fParser_p;	/* EscParse reading buffer pointer */
88 	int fLockFlag;	/* PtyReader lock flag */
89 
90 	bool fQuitting;
91 
92 	uchar fReadBuf[READ_BUF_SIZE]; /* Reading buffer */
93 };
94 
95 #endif // TERMPARSE_H
96