diff options
author | David Robillard <d@drobilla.net> | 2008-11-15 22:56:24 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2008-11-15 22:56:24 +0000 |
commit | fb6471ac9d5daefd3655bc19532a6028b5f0ead4 (patch) | |
tree | bec99ab0a594e3be390b393af63064ce4a26f57f /src/shared | |
parent | 6f0b9a0c5a21bb660363d417313add2f66447255 (diff) | |
download | ingen-fb6471ac9d5daefd3655bc19532a6028b5f0ead4.tar.gz ingen-fb6471ac9d5daefd3655bc19532a6028b5f0ead4.tar.bz2 ingen-fb6471ac9d5daefd3655bc19532a6028b5f0ead4.zip |
Stubs for HTTP streaming.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@1719 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/HTTPSender.cpp | 81 | ||||
-rw-r--r-- | src/shared/HTTPSender.hpp | 57 | ||||
-rw-r--r-- | src/shared/wscript | 5 |
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' |