summaryrefslogtreecommitdiff
path: root/src/multicast_configuration.cc
diff options
context:
space:
mode:
authordeva <deva>2005-10-18 12:13:22 +0000
committerdeva <deva>2005-10-18 12:13:22 +0000
commit4ab476ecf381943d7d1537c1dd82cf5783e00ad2 (patch)
tree425f9d8de53f2faac73fae09e900a6a9c275e123 /src/multicast_configuration.cc
parent1099eeae24b28306022ae3663a2766261b3455e4 (diff)
*** empty log message ***
Diffstat (limited to 'src/multicast_configuration.cc')
-rw-r--r--src/multicast_configuration.cc129
1 files changed, 129 insertions, 0 deletions
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*/