From 92aebf172247328aa8928aa421a69854975236f4 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Thu, 11 Apr 2013 00:12:42 +0200 Subject: [PATCH 1/1] Move stream creation out of main(). --- main.cpp | 83 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 46 insertions(+), 37 deletions(-) diff --git a/main.cpp b/main.cpp index 278c51d..de3900b 100644 --- a/main.cpp +++ b/main.cpp @@ -197,6 +197,51 @@ vector create_inputs(const vector &config, return inputs; } +void create_streams(const vector &config, + const set &deserialized_stream_ids, + map *deserialized_inputs) +{ + set expecting_stream_ids = deserialized_stream_ids; + map, MarkPool *> mark_pools; + for (unsigned i = 0; i < config.size(); ++i) { + if (config[i].keyword != "stream") { + continue; + } + if (config[i].arguments.size() != 1) { + fprintf(stderr, "ERROR: 'stream' takes exactly one argument\n"); + exit(1); + } + string stream_id = config[i].arguments[0]; + if (deserialized_stream_ids.count(stream_id) == 0) { + servers->add_stream(stream_id); + } + expecting_stream_ids.erase(stream_id); + + // Set up marks, if so desired. + map::const_iterator mark_parm_it = + config[i].parameters.find("mark"); + if (mark_parm_it != config[i].parameters.end()) { + MarkPool *mark_pool = parse_mark_pool(&mark_pools, mark_parm_it->second); + servers->set_mark_pool(stream_id, mark_pool); + } + } + + // Warn about any servers we've lost. + // TODO: Make an option (delete=yes?) to actually shut down streams. + for (set::const_iterator stream_it = expecting_stream_ids.begin(); + stream_it != expecting_stream_ids.end(); + ++stream_it) { + string stream_id = *stream_it; + fprintf(stderr, "WARNING: stream '%s' disappeared from the configuration file.\n", + stream_id.c_str()); + fprintf(stderr, " It will not be deleted, but clients will not get any new inputs.\n"); + if (deserialized_inputs->count(stream_id) != 0) { + delete (*deserialized_inputs)[stream_id]; + deserialized_inputs->erase(stream_id); + } + } +} + int main(int argc, char **argv) { fprintf(stderr, "\nCubemap starting.\n"); @@ -247,43 +292,7 @@ int main(int argc, char **argv) } // Find all streams in the configuration file, and create them. - set expecting_stream_ids = deserialized_stream_ids; - map, MarkPool *> mark_pools; - for (unsigned i = 0; i < config.size(); ++i) { - if (config[i].keyword != "stream") { - continue; - } - if (config[i].arguments.size() != 1) { - fprintf(stderr, "ERROR: 'stream' takes exactly one argument\n"); - exit(1); - } - string stream_id = config[i].arguments[0]; - if (deserialized_stream_ids.count(stream_id) == 0) { - servers->add_stream(stream_id); - } - expecting_stream_ids.erase(stream_id); - - // Set up marks, if so desired. - if (config[i].parameters.count("mark")) { - MarkPool *mark_pool = parse_mark_pool(&mark_pools, config[i].parameters["mark"]); - servers->set_mark_pool(stream_id, mark_pool); - } - } - - // Warn about any servers we've lost. - // TODO: Make an option (delete=yes?) to actually shut down streams. - for (set::const_iterator stream_it = expecting_stream_ids.begin(); - stream_it != expecting_stream_ids.end(); - ++stream_it) { - string stream_id = *stream_it; - fprintf(stderr, "WARNING: stream '%s' disappeared from the configuration file.\n", - stream_id.c_str()); - fprintf(stderr, " It will not be deleted, but clients will not get any new inputs.\n"); - if (deserialized_inputs.count(stream_id) != 0) { - delete deserialized_inputs[stream_id]; - deserialized_inputs.erase(stream_id); - } - } + create_streams(config, deserialized_stream_ids, &deserialized_inputs); // Open a new server socket if we do not already have one, or if we changed ports. if (server_sock != -1 && port != old_port) { -- 2.39.2