1 | //listenpty.c: |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2011-2012 |
---|
5 | * |
---|
6 | * This file is part of roard a part of RoarAudio, |
---|
7 | * a cross-platform sound system for both, home and professional use. |
---|
8 | * See README for details. |
---|
9 | * |
---|
10 | * This file is free software; you can redistribute it and/or modify |
---|
11 | * it under the terms of the GNU General Public License version 3 |
---|
12 | * as published by the Free Software Foundation. |
---|
13 | * |
---|
14 | * RoarAudio is distributed in the hope that it will be useful, |
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | * GNU General Public License for more details. |
---|
18 | * |
---|
19 | * You should have received a copy of the GNU General Public License |
---|
20 | * along with this software; see the file COPYING. If not, write to |
---|
21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
22 | * Boston, MA 02110-1301, USA. |
---|
23 | * |
---|
24 | */ |
---|
25 | |
---|
26 | #include <roard/include/roard.h> |
---|
27 | |
---|
28 | #if defined(ROAR_HAVE_POSIX_OPENPT) && defined(ROAR_HAVE_GRANTPT) && defined(ROAR_HAVE_UNLOCKPT) && defined(ROAR_HAVE_TCGETATTR) && defined(ROAR_HAVE_TCSETATTR) && defined(ROAR_HAVE_CFMAKERAW) |
---|
29 | #define __HAVE_SUPPORT |
---|
30 | #endif |
---|
31 | |
---|
32 | #ifdef __HAVE_SUPPORT |
---|
33 | #include <termios.h> |
---|
34 | #endif |
---|
35 | |
---|
36 | static int init (struct roar_dl_librarypara * para) { |
---|
37 | #ifdef __HAVE_SUPPORT |
---|
38 | int serverfh = posix_openpt(O_RDWR|O_NOCTTY); |
---|
39 | struct termios termios; |
---|
40 | |
---|
41 | (void)para; |
---|
42 | |
---|
43 | if ( serverfh == -1 ) { |
---|
44 | ROAR_WARN("Can not open PTY Master: %s", strerror(errno)); |
---|
45 | return 0; |
---|
46 | } |
---|
47 | |
---|
48 | tcgetattr(serverfh, &termios); |
---|
49 | cfmakeraw(&termios); |
---|
50 | tcsetattr(serverfh, TCSANOW, &termios); |
---|
51 | |
---|
52 | grantpt(serverfh); |
---|
53 | unlockpt(serverfh); |
---|
54 | |
---|
55 | if ( clients_new_from_fh(serverfh, ROAR_PROTO_ROARAUDIO, ROAR_BYTEORDER_NETWORK, 0) == -1 ) { |
---|
56 | close(serverfh); |
---|
57 | return 0; |
---|
58 | } |
---|
59 | |
---|
60 | ROAR_WARN("PTY Slave: %s", ptsname(serverfh)); |
---|
61 | return 0; |
---|
62 | #else |
---|
63 | ROAR_ERR("No PTY Support found so can not load listenpty plugin."); |
---|
64 | return -1; |
---|
65 | #endif |
---|
66 | } |
---|
67 | |
---|
68 | static struct roar_dl_appsched sched = { |
---|
69 | .init = init, |
---|
70 | .free = NULL, |
---|
71 | .update = NULL, |
---|
72 | .tick = NULL, |
---|
73 | .wait = NULL |
---|
74 | }; |
---|
75 | |
---|
76 | ROAR_DL_PLUGIN_START(listenpty) { |
---|
77 | ROARD_DL_CHECK_VERSIONS(); |
---|
78 | |
---|
79 | ROAR_DL_PLUGIN_META_PRODUCT_NIV("listenpty", ROAR_VID_ROARAUDIO, ROAR_VNAME_ROARAUDIO); |
---|
80 | ROAR_DL_PLUGIN_META_VERSION(ROAR_VERSION_STRING); |
---|
81 | ROAR_DL_PLUGIN_META_LICENSE_TAG(GPLv3_0); |
---|
82 | ROAR_DL_PLUGIN_META_CONTACT_FLNE("Philipp", "Schafft", "ph3-der-loewe", "lion@lion.leolix.org"); |
---|
83 | ROAR_DL_PLUGIN_META_DESC("This implements a listen socket using a PTY"); |
---|
84 | |
---|
85 | ROAR_DL_PLUGIN_REG_APPSCHED(&sched); |
---|
86 | } ROAR_DL_PLUGIN_END |
---|
87 | |
---|
88 | //ll |
---|