1/*
2 *	Copyright 2010, Haiku Inc. All Rights Reserved.
3 *	Distributed under the terms of the MIT License.
4 */
5
6#ifndef _TTY_MODULE_H
7#define _TTY_MODULE_H
8
9#include <module.h>
10#include <termios.h>
11#include <Select.h>
12
13struct tty;
14struct tty_cookie;
15
16typedef bool (*tty_service_func)(struct tty *tty, uint32 op, void *buffer,
17	size_t length);
18
19// flags
20#define	TTYCARRIER		(1 << 0)
21#define	TTYWRITABLE		(1 << 1)
22#define	TTYWRITING		(1 << 2)
23#define	TTYREADING		(1 << 3)
24#define	TTYOSTOPPED		(1 << 4)
25#define	TTYEXCLUSIVE	(1 << 5)
26#define	TTYHWDCD		(1 << 6)
27#define	TTYHWCTS		(1 << 7)
28#define	TTYHWDSR		(1 << 8)
29#define	TTYHWRI			(1 << 9)
30#define	TTYFLOWFORCED	(1 << 10)
31
32// ops
33#define	TTYENABLE		0	/* bool enabled */
34#define	TTYSETMODES		1	/* struct termios termios */
35#define	TTYOSTART		2
36#define	TTYOSYNC		3
37#define	TTYISTOP		4	/* bool stopInput */
38#define	TTYSETBREAK		5	/* bool break */
39#define	TTYSETDTR		6	/* bool dataTerminalReady */
40#define TTYSETRTS		7	/* bool requestToSend */
41#define	TTYGETSIGNALS	8	/* call tty_hardware_signal for all bits */
42#define TTYFLUSH		9	/* clear input and/or output buffers */
43
44typedef struct tty_module_info tty_module_info;
45
46struct tty_module_info {
47	module_info	mi;
48
49	status_t	(*tty_create)(tty_service_func serviceFunction, struct tty *master,
50					struct tty **tty);
51	void		(*tty_destroy)(struct tty *tty);
52
53	status_t	(*tty_create_cookie)(struct tty *masterTTY, struct tty *slaveTTY,
54					uint32 openMode, struct tty_cookie **cookie);
55	void		(*tty_close_cookie)(struct tty_cookie *cookie);
56	void		(*tty_destroy_cookie)(struct tty_cookie *cookie);
57
58	status_t	(*tty_read)(struct tty_cookie *cookie, void *_buffer,
59					size_t *_length);
60	status_t	(*tty_write)(struct tty_cookie *cookie, const void *buffer,
61					size_t *length);
62	status_t	(*tty_control)(struct tty_cookie *cookie, uint32 op,
63					void *buffer, size_t length);
64	status_t	(*tty_select)(struct tty_cookie *cookie, uint8 event,
65					uint32 ref, selectsync *sync);
66	status_t	(*tty_deselect)(struct tty_cookie *cookie, uint8 event,
67					selectsync *sync);
68
69	status_t	(*tty_hardware_signal)(struct tty_cookie *cookie,
70					int signal, bool);
71};
72
73#define B_TTY_MODULE_NAME			"generic/tty/v1"
74
75#endif /* _TTY_MODULE_H */
76