From 14ab4dcff7f8461dfed27b6352249b683c1f4bae Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 22 Oct 2011 00:21:43 +0000 Subject: Move *all* OSC and HTTP stuff to their respective modules. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@3578 a436a847-0d15-0410-975c-d299462d15a1 --- src/shared/HTTPSender.cpp | 156 ---------------------------------------------- src/shared/HTTPSender.hpp | 61 ------------------ src/shared/OSCSender.cpp | 111 --------------------------------- src/shared/OSCSender.hpp | 52 ---------------- src/shared/World.cpp | 5 ++ src/shared/wscript | 9 +-- 6 files changed, 6 insertions(+), 388 deletions(-) delete mode 100644 src/shared/HTTPSender.cpp delete mode 100644 src/shared/HTTPSender.hpp delete mode 100644 src/shared/OSCSender.cpp delete mode 100644 src/shared/OSCSender.hpp (limited to 'src/shared') diff --git a/src/shared/HTTPSender.cpp b/src/shared/HTTPSender.cpp deleted file mode 100644 index 1a4d35da..00000000 --- a/src/shared/HTTPSender.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/* This file is part of Ingen. - * Copyright 2008-2011 David Robillard - * - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "raul/log.hpp" -#include "HTTPSender.hpp" - -using namespace std; -using namespace Raul; - -namespace Ingen { -namespace Shared { - -HTTPSender::HTTPSender() - : _listen_port(-1) - , _listen_sock(-1) - , _client_sock(-1) - , _send_state(Immediate) -{ - Thread::set_name("HTTPSender"); - - struct sockaddr_in addr; - - // Create listen address - memset(&addr, 0, sizeof(addr)); - addr.sin_family = AF_INET; - addr.sin_addr.s_addr = htonl(INADDR_ANY); - - // Create listen socket - if ((_listen_sock = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) { - error << "Error creating listening socket (" << strerror(errno) << ")" << endl; - exit(EXIT_FAILURE); - } - - // Bind our socket addresss to the listening socket - if (bind(_listen_sock, (struct sockaddr*)&addr, sizeof(addr)) < 0) { - error << "Error calling bind (%s)\n" << strerror(errno) << ")" << endl; - _listen_sock = -1; - } - - // Find port number - socklen_t length = sizeof(addr); - if (getsockname(_listen_sock, (struct sockaddr*)&addr, &length) == -1) { - error << "Error calling getsockname (" << strerror(errno) << ")" << endl; - _listen_sock = -1; - return; - } - - if (listen(_listen_sock, 1) < 0 ) { - error << "Error calling listen (" << strerror(errno) << ")" << endl; - _listen_sock = -1; - return; - } - - _listen_port = ntohs(addr.sin_port); - info << "Opening event stream on TCP port " << _listen_port << endl; - start(); -} - -HTTPSender::~HTTPSender() -{ - stop(); - if (_listen_sock != -1) - close(_listen_sock); - if (_client_sock != -1) - close(_client_sock); -} - -void -HTTPSender::_run() -{ - if (_listen_sock == -1) { - error << "Unable to open socket, exiting sender thread" << endl; - return; - } - - // Accept connection - if ((_client_sock = accept(_listen_sock, NULL, NULL) ) < 0) { - error << "Error calling accept: " << strerror(errno) << endl; - return; - } - - // Hold connection open and write when signalled - while (true) { - _mutex.lock(); - _signal.wait(_mutex); - - write(_client_sock, _transfer.c_str(), _transfer.length()); - write(_client_sock, "\n\n\n", 3); - - _signal.broadcast(); - _mutex.unlock(); - } - - close(_listen_sock); - _listen_sock = -1; -} - -void -HTTPSender::bundle_begin() -{ - _mutex.lock(); - _send_state = SendingBundle; - _transfer = ""; -} - -void -HTTPSender::bundle_end() -{ - assert(_send_state == SendingBundle); - _signal.broadcast(); - _signal.wait(_mutex); - _send_state = Immediate; - _mutex.unlock(); -} - -void -HTTPSender::send_chunk(const std::string& buf) -{ - if (_send_state == Immediate) { - _mutex.lock(); - _transfer = buf; - _signal.broadcast(); - _signal.wait(_mutex); - _mutex.unlock(); - } else { - _transfer.append(buf); - } -} - -} // namespace Shared -} // namespace Ingen diff --git a/src/shared/HTTPSender.hpp b/src/shared/HTTPSender.hpp deleted file mode 100644 index a1a3ea2a..00000000 --- a/src/shared/HTTPSender.hpp +++ /dev/null @@ -1,61 +0,0 @@ -/* This file is part of Ingen. - * Copyright 2008-2011 David Robillard - * - * 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 INGEN_SHARED_HTTPSENDER_HPP -#define INGEN_SHARED_HTTPSENDER_HPP - -#include - -#include - -#include "raul/Thread.hpp" - -namespace Ingen { -namespace Shared { - -class HTTPSender : public Raul::Thread { -public: - HTTPSender(); - virtual ~HTTPSender(); - - void bundle_begin(); - void bundle_end(); - - int listen_port() const { return _listen_port; } - -protected: - void _run(); - - void send_chunk(const std::string& buf); - - enum SendState { Immediate, SendingBundle }; - - Glib::Mutex _mutex; - Glib::Cond _signal; - - int _listen_port; - int _listen_sock; - int _client_sock; - SendState _send_state; - std::string _transfer; -}; - -} // namespace Shared -} // namespace Ingen - -#endif // INGEN_SHARED_HTTPSENDER_HPP - diff --git a/src/shared/OSCSender.cpp b/src/shared/OSCSender.cpp deleted file mode 100644 index 6c07551b..00000000 --- a/src/shared/OSCSender.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* This file is part of Ingen. - * Copyright 2008-2011 David Robillard - * - * 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 -#include -#include - -#include "raul/log.hpp" - -#include "OSCSender.hpp" -#include "ingen-config.h" - -using namespace std; -using namespace Raul; - -namespace Ingen { -namespace Shared { - -OSCSender::OSCSender(size_t max_packet_size) - : _bundle(NULL) - , _address(NULL) - , _max_packet_size(max_packet_size) - , _enabled(true) -{ -} - -void -OSCSender::bundle_begin() -{ - assert(!_bundle); - lo_timetag t; - lo_timetag_now(&t); - _bundle = lo_bundle_new(t); -} - -void -OSCSender::bundle_end() -{ - assert(_bundle); - lo_send_bundle(_address, _bundle); - lo_bundle_free_messages(_bundle); - _bundle = NULL; -} - -int -OSCSender::send(const char *path, const char *types, ...) -{ - if (!_enabled) - return 0; - -#ifdef RAUL_LOG_DEBUG - info << "[OSCSender] " << path << " (" << types << ")" << endl; -#endif - - va_list args; - va_start(args, types); - - lo_message msg = lo_message_new(); - int ret = lo_message_add_varargs(msg, types, args); - - if (!ret) - send_message(path, msg); - else - lo_message_free(msg); - - va_end(args); - - return ret; -} - -void -OSCSender::send_message(const char* path, lo_message msg) -{ - if (!_enabled) { - lo_message_free(msg); - return; - } - - if (_bundle) { - if (lo_bundle_length(_bundle) + lo_message_length(msg, path) > _max_packet_size) { - warn << "Maximum bundle size reached, bundle split" << endl; - lo_send_bundle(_address, _bundle); - lo_bundle_free_messages(_bundle); - lo_timetag t; - lo_timetag_now(&t); - _bundle = lo_bundle_new(t); - } - lo_bundle_add_message(_bundle, path, msg); - - } else { - lo_send_message(_address, path, msg); - lo_message_free(msg); - } -} - -} // namespace Shared -} // namespace Ingen diff --git a/src/shared/OSCSender.hpp b/src/shared/OSCSender.hpp deleted file mode 100644 index b2febb70..00000000 --- a/src/shared/OSCSender.hpp +++ /dev/null @@ -1,52 +0,0 @@ -/* This file is part of Ingen. - * Copyright 2007-2011 David Robillard - * - * 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 INGEN_SHARED_OSCSENDER_HPP -#define INGEN_SHARED_OSCSENDER_HPP - -#include - -#include - -namespace Ingen { -namespace Shared { - -class OSCSender { -public: - OSCSender(size_t max_packet_size); - virtual ~OSCSender() {} - - lo_address address() const { return _address; } - - void bundle_begin(); - void bundle_end(); - -protected: - int send(const char *path, const char *types, ...); - void send_message(const char* path, lo_message m); - - lo_bundle _bundle; - lo_address _address; - size_t _max_packet_size; - bool _enabled; -}; - -} // namespace Shared -} // namespace Ingen - -#endif // INGEN_SHARED_OSCSENDER_HPP - diff --git a/src/shared/World.cpp b/src/shared/World.cpp index 9aa17d4f..aae321fe 100644 --- a/src/shared/World.cpp +++ b/src/shared/World.cpp @@ -219,6 +219,11 @@ SharedPtr World::lv2_uri_map() { return _impl->lv2_uri_map; } bool World::load_module(const char* name) { + Pimpl::Modules::iterator i = _impl->modules.find(name); + if (i != _impl->modules.end()) { + LOG(info) << "Module `" << name << "' already loaded" << endl; + return true; + } SharedPtr lib = ingen_load_module(name); Ingen::Shared::Module* (*module_load)() = NULL; if (lib && lib->get_symbol("ingen_module_load", (void*&)module_load)) { diff --git a/src/shared/wscript b/src/shared/wscript index 601f3286..410325a4 100644 --- a/src/shared/wscript +++ b/src/shared/wscript @@ -10,7 +10,7 @@ def build(bld): vnum = '0.0.0', install_path = '${LIBDIR}', linkflags = '-ldl') - autowaf.use_lib(bld, obj, 'GLIBMM LV2CORE LILV RAUL SORD LIBLO') + autowaf.use_lib(bld, obj, 'GLIBMM LV2CORE LILV RAUL SORD') obj.source = ''' Builder.cpp @@ -26,10 +26,3 @@ def build(bld): World.cpp runtime_paths.cpp ''' - - if bld.is_defined('HAVE_LIBLO'): - obj.source += ' OSCSender.cpp ' - - if bld.is_defined('HAVE_SOUP'): - autowaf.use_lib(bld, obj, 'SOUP') - obj.source += ' HTTPSender.cpp ' -- cgit v1.2.1