19105df34Sshatty/*
217dfb8b1SStefano Ceccherini * Copyright 2007 Haiku, Inc.
39105df34Sshatty * Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net>
4ead4f89eSassimil * Copyright (c) 2004 Daniel Furrer <assimil8or@users.sourceforge.net>
5ad827632SIngo Weinhold * Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
6258e9494SStefano Ceccherini * Distributed under the terms of the MIT License.
7258e9494SStefano Ceccherini * Authors:
8258e9494SStefano Ceccherini *		Stefano Ceccherini <stefano.ceccherini@gmail.com>
9258e9494SStefano Ceccherini *		Kian Duffy <myob@users.sourceforge.net>
10258e9494SStefano Ceccherini *		Kazuho Okui
11ad827632SIngo Weinhold *		Takashi Murai
129105df34Sshatty */
1337b209afSStefano Ceccherini#ifndef _SHELL_H
1437b209afSStefano Ceccherini#define _SHELL_H
159105df34Sshatty
16ad827632SIngo Weinhold
17ca598670SIngo Weinhold#include "ShellInfo.h"
189105df34Sshatty
19ad827632SIngo Weinhold
20b27862d2SIngo Weinholdclass ActiveProcessInfo;
2137322c4bSIngo Weinholdclass ShellParameters;
22ac3a8f54SStefano Ceccherini// TODO: Maybe merge TermParse and Shell classes ?
234012c75aSStefano Ceccheriniclass TerminalBuffer;
24ac3a8f54SStefano Ceccheriniclass TermParse;
254386ce02SIngo Weinhold
26ad827632SIngo Weinhold
27f3d05c8bSStefano Ceccheriniclass Shell {
28f3d05c8bSStefano Ceccherinipublic:
29ad827632SIngo Weinhold								Shell();
30ad827632SIngo Weinhold	virtual						~Shell();
31ad827632SIngo Weinhold
3237322c4bSIngo Weinhold			status_t			Open(int row, int col,
3337322c4bSIngo Weinhold									const ShellParameters& parameters);
34ad827632SIngo Weinhold			void				Close();
35f3d05c8bSStefano Ceccherini
36ad827632SIngo Weinhold			const char*			TTYName() const;
37f3d05c8bSStefano Ceccherini
38ad827632SIngo Weinhold			ssize_t				Read(void* buffer, size_t numBytes) const;
39ad827632SIngo Weinhold			ssize_t				Write(const void* buffer, size_t numBytes);
40f3d05c8bSStefano Ceccherini
41ad827632SIngo Weinhold			status_t			UpdateWindowSize(int row, int columns);
429105df34Sshatty
43ad827632SIngo Weinhold			status_t			GetAttr(struct termios& attr) const;
44ad827632SIngo Weinhold			status_t			SetAttr(const struct termios& attr);
459105df34Sshatty
46ad827632SIngo Weinhold			int					FD() const;
47ca598670SIngo Weinhold			pid_t				ProcessID() const
48ca598670SIngo Weinhold									{ return fShellInfo.ProcessID(); }
49ca598670SIngo Weinhold			const ShellInfo&	Info() const
50ca598670SIngo Weinhold									{ return fShellInfo; }
51ad827632SIngo Weinhold
5219bfeaa7SSiarzhuk Zharski			int					Encoding() const
5319bfeaa7SSiarzhuk Zharski									{ return fShellInfo.Encoding(); }
5419bfeaa7SSiarzhuk Zharski			void				SetEncoding(int encoding)
5519bfeaa7SSiarzhuk Zharski									{ fShellInfo.SetEncoding(encoding); }
5619bfeaa7SSiarzhuk Zharski
57ad827632SIngo Weinhold			bool				HasActiveProcesses() const;
58b27862d2SIngo Weinhold			bool				GetActiveProcessInfo(
59b27862d2SIngo Weinhold									ActiveProcessInfo& _info) const;
60ad827632SIngo Weinhold
61ad827632SIngo Weinhold	virtual	status_t			AttachBuffer(TerminalBuffer* buffer);
62ad827632SIngo Weinhold	virtual void				DetachBuffer();
63d9fdb4f6SStefano Ceccherini
64f3d05c8bSStefano Ceccheriniprivate:
6537322c4bSIngo Weinhold			status_t			_Spawn(int row, int col,
6637322c4bSIngo Weinhold									const ShellParameters& parameters);
670d32d905SStefano Ceccherini
68ad827632SIngo Weinholdprivate:
69ca598670SIngo Weinhold			ShellInfo			fShellInfo;
70ad827632SIngo Weinhold			int					fFd;
71ad827632SIngo Weinhold			pid_t				fProcessID;
72ad827632SIngo Weinhold			TermParse*			fTermParse;
73ad827632SIngo Weinhold			bool				fAttached;
74f3d05c8bSStefano Ceccherini};
759105df34Sshatty
76ad827632SIngo Weinhold
7737b209afSStefano Ceccherini#endif // _SHELL_H
78