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
43typedef struct tty_module_info tty_module_info;
44
45struct tty_module_info {
46	module_info	mi;
47
48	struct tty *(*tty_create)(tty_service_func serviceFunction, bool isMaster);
49	void		(*tty_destroy)(struct tty *tty);
50
51	struct tty_cookie *
52				(*tty_create_cookie)(struct tty *masterTTY, struct tty *slaveTTY,
53					uint32 openMode);
54	void		(*tty_close_cookie)(struct tty_cookie *cookie);
55	void		(*tty_destroy_cookie)(struct tty_cookie *cookie);
56
57	status_t	(*tty_read)(struct tty_cookie *cookie, void *_buffer,
58					size_t *_length);
59	status_t	(*tty_write)(struct tty_cookie *cookie, const void *buffer,
60					size_t *length);
61	status_t	(*tty_control)(struct tty_cookie *cookie, uint32 op,
62					void *buffer, size_t length);
63	status_t	(*tty_select)(struct tty_cookie *cookie, uint8 event,
64					uint32 ref, selectsync *sync);
65	status_t	(*tty_deselect)(struct tty_cookie *cookie, uint8 event,
66					selectsync *sync);
67
68	status_t	(*tty_hardware_signal)(struct tty_cookie *cookie,
69					int signal, bool);
70};
71
72#define B_TTY_MODULE_NAME			"generic/tty/v1"
73
74#endif /* _TTY_MODULE_H */
75