source: mainline/uspace/srv/hid/remcons/user.h@ 5132379

Last change on this file since 5132379 was 6907f26, checked in by Jiri Svoboda <jiri@…>, 13 months ago

Parse VT100 keyboard escape sequences in libvt

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/*
2 * Copyright (c) 2024 Jiri Svoboda
3 * Copyright (c) 2012 Vojtech Horky
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @addtogroup remcons
31 * @{
32 */
33/** @file
34 */
35
36#ifndef TELNET_USER_H_
37#define TELNET_USER_H_
38
39#include <fibril_synch.h>
40#include <inet/tcp.h>
41#include <inttypes.h>
42#include <io/con_srv.h>
43
44#define BUFFER_SIZE 32
45#define SEND_BUF_SIZE 512
46
47/** Representation of a connected (human) user. */
48typedef struct {
49 /** Mutex guarding the whole structure. */
50 fibril_mutex_t guard;
51
52 /** Internal id, used for creating locfs entries. */
53 int id;
54 /** Associated connection. */
55 tcp_conn_t *conn;
56 /** Location service id assigned to the virtual terminal. */
57 service_id_t service_id;
58 /** Path name of the service. */
59 char *service_name;
60 /** Console service setup */
61 con_srvs_t srvs;
62
63 link_t link;
64 char socket_buffer[BUFFER_SIZE];
65 size_t socket_buffer_len;
66 size_t socket_buffer_pos;
67 char send_buf[SEND_BUF_SIZE];
68 size_t send_buf_used;
69
70 /** Task id of the launched application. */
71 task_id_t task_id;
72
73 /* Reference counting. */
74 fibril_condvar_t refcount_cv;
75 bool task_finished;
76 int locsrv_connection_count;
77 bool socket_closed;
78
79 /** X position of the cursor. */
80 int cursor_x;
81 /** Y position of the cursor. */
82 int cursor_y;
83 /** Total number of columns */
84 unsigned cols;
85 /** Total number of rows */
86 unsigned rows;
87} telnet_user_t;
88
89extern telnet_user_t *telnet_user_create(tcp_conn_t *);
90extern void telnet_user_add(telnet_user_t *);
91extern void telnet_user_destroy(telnet_user_t *);
92extern telnet_user_t *telnet_user_get_for_client_connection(service_id_t);
93extern bool telnet_user_is_zombie(telnet_user_t *);
94extern void telnet_user_notify_client_disconnected(telnet_user_t *);
95extern errno_t telnet_user_get_next_keyboard_event(telnet_user_t *, kbd_event_t *);
96extern errno_t telnet_user_send_data(telnet_user_t *, const char *, size_t);
97extern errno_t telnet_user_send_raw(telnet_user_t *, const char *, size_t);
98extern errno_t telnet_user_flush(telnet_user_t *);
99extern errno_t telnet_user_recv(telnet_user_t *, void *, size_t, size_t *);
100extern void telnet_user_update_cursor_x(telnet_user_t *, int);
101
102/** Print informational message about connected user. */
103#ifdef CONFIG_DEBUG
104#define telnet_user_log(user, fmt, ...) \
105 printf(NAME " [console %d (%d)]: " fmt "\n", \
106 user->id, (int) user->service_id, ##__VA_ARGS__)
107#else
108#define telnet_user_log(user, fmt, ...) ((void) 0)
109#endif
110
111/** Print error message associated with connected user. */
112#define telnet_user_error(user, fmt, ...) \
113 fprintf(stderr, NAME " [console %d (%d)]: ERROR: " fmt "\n", \
114 user->id, (int) user->service_id, ##__VA_ARGS__)
115
116#endif
117
118/**
119 * @}
120 */
Note: See TracBrowser for help on using the repository browser.