#include <string.h>
#include <string>
+#include "httpinput.h"
#include "input.h"
+#include "state.pb.h"
using namespace std;
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() {}
#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();
#include "server.h"
#include "serverpool.h"
#include "input.h"
-#include "httpinput.h"
#include "stats.h"
#include "version.h"
#include "state.pb.h"
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);
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.