/* $Id$ */ /*** This file is part of ivam2. ivam2 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. ivam2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with ivam2; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ***/ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include #include "modemman.h" #include "modem.h" #define MAX_CHANNELS 10 #define TTY_START 12 struct llist { struct modem *modem; struct llist *next; }; static struct llist *llist = NULL; static int n_llist = 0; static void modem_try_open(const char *dev) { struct modem *m; if ((m = modem_open(dev))) { struct llist *l = malloc(sizeof(struct llist)); assert(l); l->modem = m; l->next = llist; llist = l; n_llist++; } } int modem_manager_init(int channels) { int i; assert(channels <= MAX_CHANNELS && channels > 0); assert(n_llist == 0); for (i = TTY_START; i < TTY_START+MAX_CHANNELS && n_llist < channels; i++) { char d[PATH_MAX]; snprintf(d, sizeof(d), "/dev/ttyI%i", i); modem_try_open(d); } if (n_llist < channels) { daemon_log(LOG_ERR, "Failed to allocate the requested channels. Got %i of %i.", n_llist, channels); modem_manager_done(); return -1; } return 0; } void modem_manager_done(void) { while (llist) { struct llist *l; modem_close(llist->modem); l = llist; llist = llist->next; free(l); n_llist--; } assert(!n_llist && !llist); }