More support for multiple input types.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 11 Apr 2013 19:31:11 +0000 (21:31 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 11 Apr 2013 19:31:11 +0000 (21:31 +0200)
input.cpp
input.h
main.cpp

index 1e61780..00b6547 100644 (file)
--- a/input.cpp
+++ b/input.cpp
@@ -1,7 +1,9 @@
 #include <string.h>
 #include <string>
 
 #include <string.h>
 #include <string>
 
+#include "httpinput.h"
 #include "input.h"
 #include "input.h"
+#include "state.pb.h"
 
 using namespace std;
 
 
 using namespace std;
 
@@ -50,5 +52,29 @@ bool parse_url(const string &url, string *protocol, string *host, string *port,
        return true;
 }
 
        return true;
 }
 
+Input *create_input(const std::string &stream_id, const std::string &url)
+{
+       string protocol, host, port, path;
+       if (!parse_url(url, &protocol, &host, &port, &path)) {
+               return NULL;
+       }
+       if (protocol == "http") {
+               return new HTTPInput(stream_id, url);
+       }
+       return NULL;
+}
+
+Input *create_input(const InputProto &serialized)
+{
+       string protocol, host, port, path;
+       if (!parse_url(serialized.url(), &protocol, &host, &port, &path)) {
+               return NULL;
+       }
+       if (protocol == "http") {
+               return new HTTPInput(serialized);
+       }
+       return NULL;
+}
+
 Input::~Input() {}
 
 Input::~Input() {}
 
diff --git a/input.h b/input.h
index 3e86510..50cfeaa 100644 (file)
--- a/input.h
+++ b/input.h
@@ -5,11 +5,17 @@
 
 #include "thread.h"
 
 
 #include "thread.h"
 
+class Input;
 class InputProto;
 
 // Extremely rudimentary URL parsing.
 bool parse_url(const std::string &url, std::string *protocol, std::string *host, std::string *port, std::string *path);
 
 class InputProto;
 
 // Extremely rudimentary URL parsing.
 bool parse_url(const std::string &url, std::string *protocol, std::string *host, std::string *port, std::string *path);
 
+// Figure out the right type of input based on the URL, and create a new Input of the right type.
+// Will return NULL if unknown.
+Input *create_input(const std::string &stream_id, const std::string &url);
+Input *create_input(const InputProto &serialized);
+
 class Input : public Thread {
 public:
        virtual ~Input();
 class Input : public Thread {
 public:
        virtual ~Input();
index e258c86..03ef0d7 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -25,7 +25,6 @@
 #include "server.h"
 #include "serverpool.h"
 #include "input.h"
 #include "server.h"
 #include "serverpool.h"
 #include "input.h"
-#include "httpinput.h"
 #include "stats.h"
 #include "version.h"
 #include "state.pb.h"
 #include "stats.h"
 #include "version.h"
 #include "state.pb.h"
@@ -269,7 +268,7 @@ vector<Input *> create_inputs(const vector<ConfigLine> &config,
                        deserialized_inputs->erase(deserialized_input_it);
                }
                if (input == NULL) {
                        deserialized_inputs->erase(deserialized_input_it);
                }
                if (input == NULL) {
-                       input = new HTTPInput(stream_id, src);
+                       input = create_input(stream_id, src);
                }
                input->run();
                inputs.push_back(input);
                }
                input->run();
                inputs.push_back(input);
@@ -360,7 +359,7 @@ int main(int argc, char **argv)
                for (int i = 0; i < loaded_state.inputs_size(); ++i) {
                        deserialized_inputs.insert(make_pair(
                                loaded_state.inputs(i).stream_id(),
                for (int i = 0; i < loaded_state.inputs_size(); ++i) {
                        deserialized_inputs.insert(make_pair(
                                loaded_state.inputs(i).stream_id(),
-                               new HTTPInput(loaded_state.inputs(i))));
+                               create_input(loaded_state.inputs(i))));
                } 
 
                // Convert the acceptor from older serialized formats.
                } 
 
                // Convert the acceptor from older serialized formats.