From 4ab476ecf381943d7d1537c1dd82cf5783e00ad2 Mon Sep 17 00:00:00 2001 From: deva Date: Tue, 18 Oct 2005 12:13:22 +0000 Subject: *** empty log message *** --- src/multicast_configuration.cc | 129 +++++++++++++++++++++++++++++++++++++++++ src/multicast_configuration.h | 55 ++++++++++++++++++ 2 files changed, 184 insertions(+) create mode 100644 src/multicast_configuration.cc create mode 100644 src/multicast_configuration.h (limited to 'src') diff --git a/src/multicast_configuration.cc b/src/multicast_configuration.cc new file mode 100644 index 0000000..8982f7a --- /dev/null +++ b/src/multicast_configuration.cc @@ -0,0 +1,129 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * multicast_configuration.cc + * + * Wed Oct 12 10:12:11 CEST 2005 + * Copyright 2005 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of MIaV. + * + * MIaV 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. + * + * MIaV 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 MIaV; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "config.h" +#include "multicast_configuration.h" + +MulticastConfiguration::MulticastConfiguration(Info *info, char *file) + : MiavConfig(file, info) +{ + mcastconf_t conf; + + global_conf.addr = "224.0.0.1"; + global_conf.port = 1234; + global_conf.enabled = false; + + bool global = true; + + _cfg *cfg = configs; + + // Build the client list + while(cfg) { + if(strcmp(cfg->name->c_str(), "client") == 0) { + if(!global) confs.push_back(conf); + conf.client = *(cfg->stringval); + conf.addr = global_conf.addr; + conf.port = global_conf.port; + conf.enabled = global_conf.enabled; + global = false; + } + if(strcmp(cfg->name->c_str(), "address") == 0) { + if(global) global_conf.addr = *(cfg->stringval); + else conf.addr = *(cfg->stringval); + } + if(strcmp(cfg->name->c_str(), "port") == 0) { + if(global) global_conf.port = cfg->intval; + else conf.port = cfg->intval; + } + if(strcmp(cfg->name->c_str(), "enabled") == 0) { + if(global) global_conf.enabled = cfg->boolval; + else conf.enabled = cfg->boolval; + } + cfg = cfg->next; + } + if(!global) confs.push_back(conf); + + // Show the configuration in the log file . + info->info("Global - Enabled: %s - Addr: %s - Port: %d", + global_conf.enabled?"Yes\0":"No\0", + global_conf.addr.c_str(), + global_conf.port); + + for(unsigned int cnt = 0; cnt < confs.size(); cnt++) { + info->info("Client: %s - Enabled: %s - Addr: %s - Port: %d", + confs[cnt].client.c_str(), + confs[cnt].enabled?"Yes\0":"No\0", + confs[cnt].addr.c_str(), + confs[cnt].port); + } + + info->info("Chosing:"); +} + +MulticastConfiguration::~MulticastConfiguration() +{ +} + +mcastconf_t &MulticastConfiguration::getConf(char *client) +{ + for(unsigned int cnt = 0; cnt < confs.size(); cnt++) { + if(strcmp(confs[cnt].client.c_str(), client) == 0) + return confs[cnt]; + } + + return global_conf; +} + +#ifdef __TEST_MULTICAST_CONFIGURATION +#include "info_simple.h" + +int main(int argc, char *argv[]) { + if(argc < 2) { + fprintf(stderr, "usage:\n\t%s [filename]\n", argv[0]); + return 1; + } + + InfoSimple info; + MulticastConfiguration conf(&info, argv[1]); + + mcastconf_t mcconf = conf.getConf("192.168.0.11"); + + info.warn("Client: %s - Enabled: %s - Addr: %s - Port: %d", + mcconf.client.c_str(), + mcconf.enabled?"Yes\0":"No\0", + mcconf.addr.c_str(), + mcconf.port); + + mcconf = conf.getConf("192.168.0.0"); + + info.warn("Client: %s - Enabled: %s - Addr: %s - Port: %d", + mcconf.client.c_str(), + mcconf.enabled?"Yes\0":"No\0", + mcconf.addr.c_str(), + mcconf.port); +} + +#endif/* __TEST_MULTICAST_CONFIGURATION*/ diff --git a/src/multicast_configuration.h b/src/multicast_configuration.h new file mode 100644 index 0000000..ef65c51 --- /dev/null +++ b/src/multicast_configuration.h @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * multicast_configuration.h + * + * Wed Oct 12 10:12:11 CEST 2005 + * Copyright 2005 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of MIaV. + * + * MIaV 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. + * + * MIaV 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 MIaV; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "config.h" +#ifndef __MIAV_MULTICAST_CONFIGURATION_H__ +#define __MIAV_MULTICAST_CONFIGURATION_H__ + +#include "miav_config.h" + +#include +#include + +typedef struct { + std::string client; + std::string addr; + bool enabled; + int port; +} mcastconf_t; + +class MulticastConfiguration : private MiavConfig { +public: + MulticastConfiguration(Info *info, char *file); + ~MulticastConfiguration(); + + mcastconf_t &getConf(char *client); + +private: + std::vector confs; + mcastconf_t global_conf; +}; + +#endif/*__MIAV_MULTICAST_CONFIGURATION_H__*/ -- cgit v1.2.3