From 7c4707af4ea7af05e34bc0414d18d9fd54e4f23e Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Thu, 11 Apr 2013 21:31:11 +0200 Subject: [PATCH] More support for multiple input types. --- input.cpp | 26 ++++++++++++++++++++++++++ input.h | 6 ++++++ main.cpp | 5 ++--- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/input.cpp b/input.cpp index 1e61780..00b6547 100644 --- a/input.cpp +++ b/input.cpp @@ -1,7 +1,9 @@ #include #include +#include "httpinput.h" #include "input.h" +#include "state.pb.h" using namespace std; @@ -50,5 +52,29 @@ bool parse_url(const string &url, string *protocol, string *host, string *port, 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() {} diff --git a/input.h b/input.h index 3e86510..50cfeaa 100644 --- a/input.h +++ b/input.h @@ -5,11 +5,17 @@ #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); +// 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(); diff --git a/main.cpp b/main.cpp index e258c86..03ef0d7 100644 --- a/main.cpp +++ b/main.cpp @@ -25,7 +25,6 @@ #include "server.h" #include "serverpool.h" #include "input.h" -#include "httpinput.h" #include "stats.h" #include "version.h" #include "state.pb.h" @@ -269,7 +268,7 @@ vector create_inputs(const vector &config, 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); @@ -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(), - new HTTPInput(loaded_state.inputs(i)))); + create_input(loaded_state.inputs(i)))); } // Convert the acceptor from older serialized formats. -- 2.39.2