summaryrefslogtreecommitdiffstats
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/HTTPSender.cpp81
-rw-r--r--src/shared/HTTPSender.hpp57
-rw-r--r--src/shared/wscript5
3 files changed, 142 insertions, 1 deletions
diff --git a/src/shared/HTTPSender.cpp b/src/shared/HTTPSender.cpp
new file mode 100644
index 00000000..20135b2a
--- /dev/null
+++ b/src/shared/HTTPSender.cpp
@@ -0,0 +1,81 @@
+/* This file is part of Ingen.
+ * Copyright (C) 2008 Dave Robillard <http://drobilla.net>
+ *
+ * Ingen is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "HTTPSender.hpp"
+#include <cassert>
+#include <iostream>
+#include <unistd.h>
+#include <stdarg.h>
+
+using namespace std;
+
+namespace Ingen {
+namespace Shared {
+
+
+HTTPSender::HTTPSender(SoupServer* server, SoupMessage* msg)
+ : _server(server)
+ , _msg(msg)
+{
+ soup_message_headers_set_encoding(msg->response_headers, SOUP_ENCODING_CHUNKED);
+ cout << "Hello?" << endl;
+ send_chunk("hello");
+}
+
+
+HTTPSender::~HTTPSender()
+{
+ cout << "HTTP SENDER EXIT" << endl;
+ soup_message_body_complete(_msg->response_body);
+ soup_server_unpause_message(_server, _msg);
+}
+
+
+void
+HTTPSender::bundle_begin()
+{
+ _send_state = SendingBundle;
+}
+
+
+void
+HTTPSender::bundle_end()
+{
+ assert(_send_state == SendingBundle);
+ soup_message_body_append(_msg->response_body,
+ SOUP_MEMORY_TEMPORARY, _transfer.c_str(), _transfer.length());
+ soup_server_unpause_message(_server, _msg);
+ _transfer = "";
+ _send_state = Immediate;
+}
+
+
+void
+HTTPSender::send_chunk(const std::string& buf)
+{
+ if (_send_state == Immediate) {
+ soup_message_body_append(_msg->response_body,
+ SOUP_MEMORY_TEMPORARY, buf.c_str(), buf.length());
+ soup_server_unpause_message(_server, _msg);
+ } else {
+ _transfer.append(buf);
+ }
+}
+
+
+} // namespace Shared
+} // namespace Ingen
diff --git a/src/shared/HTTPSender.hpp b/src/shared/HTTPSender.hpp
new file mode 100644
index 00000000..1025c071
--- /dev/null
+++ b/src/shared/HTTPSender.hpp
@@ -0,0 +1,57 @@
+/* This file is part of Ingen.
+ * Copyright (C) 2008 Dave Robillard <http://drobilla.net>
+ *
+ * Ingen is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef HTTPSENDER_H
+#define HTTPSENDER_H
+
+#include <stdint.h>
+#include <string>
+#include <libsoup/soup.h>
+
+namespace Ingen {
+namespace Shared {
+
+class HTTPSender {
+public:
+ HTTPSender(SoupServer* server, SoupMessage* msg);
+ virtual ~HTTPSender();
+
+ // Message bundling
+ void bundle_begin();
+ void bundle_end();
+
+ // Transfers (loose bundling)
+ void transfer_begin() { bundle_begin(); }
+ void transfer_end() { bundle_end(); }
+
+protected:
+ void send_chunk(const std::string& buf);
+
+ enum SendState { Immediate, SendingBundle };
+
+ SoupServer* _server;
+ SoupMessage* _msg;
+ SendState _send_state;
+ std::string _transfer;
+};
+
+
+} // namespace Shared
+} // namespace Ingen
+
+#endif // HTTPSENDER_H
+
diff --git a/src/shared/wscript b/src/shared/wscript
index 6a5758a0..a758b8ad 100644
--- a/src/shared/wscript
+++ b/src/shared/wscript
@@ -12,8 +12,11 @@ def build(bld):
Store.cpp
runtime_paths.cpp
'''
- if bld.env()['HAVE_LIBLO']:
+ if bld.env()['HAVE_LIBLO'] == 1:
obj.source += ' OSCSender.cpp '
+ if bld.env()['HAVE_SOUP'] == 1:
+ autowaf.use_lib(bld, obj, 'SOUP')
+ obj.source += ' HTTPSender.cpp '
obj.includes = ['.', '../', '../common']
obj.name = 'libingen_shared'
obj.target = 'ingen_shared'