[5267] | 1 | //listenpty.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
[5381] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2011-2012 |
---|
[5267] | 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> |
---|
[5493] | 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 |
---|
[5267] | 33 | #include <termios.h> |
---|
[5493] | 34 | #endif |
---|
[5267] | 35 | |
---|
[5343] | 36 | static int init (struct roar_dl_librarypara * para) { |
---|
[5493] | 37 | #ifdef __HAVE_SUPPORT |
---|
[5267] | 38 | int serverfh = posix_openpt(O_RDWR|O_NOCTTY); |
---|
| 39 | struct termios termios; |
---|
| 40 | |
---|
[5343] | 41 | (void)para; |
---|
| 42 | |
---|
[5267] | 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; |
---|
[5493] | 62 | #else |
---|
| 63 | ROAR_ERR("No PTY Support found so can not load listenpty plugin."); |
---|
| 64 | return -1; |
---|
| 65 | #endif |
---|
[5267] | 66 | } |
---|
| 67 | |
---|
[5343] | 68 | static struct roar_dl_appsched sched = { |
---|
| 69 | .init = init, |
---|
| 70 | .free = NULL, |
---|
| 71 | .update = NULL, |
---|
| 72 | .tick = NULL, |
---|
| 73 | .wait = NULL |
---|
[5267] | 74 | }; |
---|
| 75 | |
---|
[5434] | 76 | ROAR_DL_PLUGIN_START(listenpty) { |
---|
[5275] | 77 | ROARD_DL_CHECK_VERSIONS(); |
---|
| 78 | |
---|
[5434] | 79 | ROAR_DL_PLUGIN_META_PRODUCT_NIV("listenpty", ROAR_VID_ROARAUDIO, ROAR_VNAME_ROARAUDIO); |
---|
[5340] | 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"); |
---|
[5275] | 84 | |
---|
[5343] | 85 | ROAR_DL_PLUGIN_REG_APPSCHED(&sched); |
---|
[5267] | 86 | } ROAR_DL_PLUGIN_END |
---|
| 87 | |
---|
| 88 | //ll |
---|