]> git.sesse.net Git - cubemap/commitdiff
Move stream creation out of main().
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 10 Apr 2013 22:12:42 +0000 (00:12 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 10 Apr 2013 22:12:42 +0000 (00:12 +0200)
main.cpp

index 278c51d67d946cb540a66fa802b20d8678f96f68..de3900b9ac6acc676143e9ae019099b77c9175e7 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -197,6 +197,51 @@ vector<Input *> create_inputs(const vector<ConfigLine> &config,
        return inputs;
 }
 
+void create_streams(const vector<ConfigLine> &config,
+                    const set<string> &deserialized_stream_ids,
+                   map<string, Input *> *deserialized_inputs)
+{
+       set<string> expecting_stream_ids = deserialized_stream_ids;
+       map<pair<int, int>, 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<string, string>::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<string>::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<string> expecting_stream_ids = deserialized_stream_ids;
-       map<pair<int, int>, 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<string>::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) {