summaryrefslogtreecommitdiffstats
path: root/include/ingen/client/ThreadedSigClientInterface.hpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-05-24 23:48:12 +0000
committerDavid Robillard <d@drobilla.net>2011-05-24 23:48:12 +0000
commit1b29d7799c32b7be8bc563d2b21349115be04e6e (patch)
tree3687992f99d42755d172ec0f6a590bdee22204ae /include/ingen/client/ThreadedSigClientInterface.hpp
parentacaab5ca7ce6869b8192de4f98c9f075fd17690e (diff)
downloadingen-1b29d7799c32b7be8bc563d2b21349115be04e6e.tar.gz
ingen-1b29d7799c32b7be8bc563d2b21349115be04e6e.tar.bz2
ingen-1b29d7799c32b7be8bc563d2b21349115be04e6e.zip
Move appropriate client headers to public include directory.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@3319 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'include/ingen/client/ThreadedSigClientInterface.hpp')
-rw-r--r--include/ingen/client/ThreadedSigClientInterface.hpp155
1 files changed, 155 insertions, 0 deletions
diff --git a/include/ingen/client/ThreadedSigClientInterface.hpp b/include/ingen/client/ThreadedSigClientInterface.hpp
new file mode 100644
index 00000000..c30b62da
--- /dev/null
+++ b/include/ingen/client/ThreadedSigClientInterface.hpp
@@ -0,0 +1,155 @@
+/* This file is part of Ingen.
+ * Copyright 2007-2011 David 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 INGEN_CLIENT_THREADEDSIGCLIENTINTERFACE_HPP
+#define INGEN_CLIENT_THREADEDSIGCLIENTINTERFACE_HPP
+
+#include <stdint.h>
+
+#include <string>
+
+#include <sigc++/sigc++.h>
+#include <glibmm/thread.h>
+
+#include "raul/Atom.hpp"
+#include "raul/SRSWQueue.hpp"
+
+#include "ingen/ClientInterface.hpp"
+#include "ingen/client/SigClientInterface.hpp"
+
+/** Returns nothing and takes no parameters (because they have all been bound) */
+typedef sigc::slot<void> Closure;
+
+namespace Ingen {
+
+class ServerInterface;
+
+namespace Client {
+
+/** A LibSigC++ signal emitting interface for clients to use.
+ *
+ * This emits signals (possibly) in a different thread than the ClientInterface
+ * functions are called. It must be explicitly driven with the emit_signals()
+ * function, which fires all enqueued signals up until the present. You can
+ * use this in a GTK idle callback for receiving thread safe engine signals.
+ */
+class ThreadedSigClientInterface : public SigClientInterface
+{
+public:
+ ThreadedSigClientInterface(uint32_t queue_size)
+ : _sigs(queue_size)
+ , response_ok_slot(_signal_response_ok.make_slot())
+ , response_error_slot(_signal_response_error.make_slot())
+ , error_slot(_signal_error.make_slot())
+ , new_port_slot(_signal_new_port.make_slot())
+ , put_slot(_signal_put.make_slot())
+ , connection_slot(_signal_connection.make_slot())
+ , object_deleted_slot(_signal_object_deleted.make_slot())
+ , object_moved_slot(_signal_object_moved.make_slot())
+ , disconnection_slot(_signal_disconnection.make_slot())
+ , disconnect_all_slot(_signal_disconnect_all.make_slot())
+ , variable_change_slot(_signal_variable_change.make_slot())
+ , property_change_slot(_signal_property_change.make_slot())
+ , port_value_slot(_signal_port_value.make_slot())
+ , activity_slot(_signal_activity.make_slot())
+ {}
+
+ virtual Raul::URI uri() const { return "http://drobilla.net/ns/ingen#internal"; }
+
+ void bundle_begin()
+ { push_sig(bundle_begin_slot); }
+
+ void bundle_end()
+ { push_sig(bundle_end_slot); }
+
+ void response_ok(int32_t id)
+ { push_sig(sigc::bind(response_ok_slot, id)); }
+
+ void response_error(int32_t id, const std::string& msg)
+ { push_sig(sigc::bind(response_error_slot, id, msg)); }
+
+ void error(const std::string& msg)
+ { push_sig(sigc::bind(error_slot, msg)); }
+
+ void put(const Raul::URI& path,
+ const Resource::Properties& properties,
+ Resource::Graph ctx=Resource::DEFAULT)
+ { push_sig(sigc::bind(put_slot, path, properties, ctx)); }
+
+ void delta(const Raul::URI& path,
+ const Resource::Properties& remove,
+ const Resource::Properties& add)
+ { push_sig(sigc::bind(delta_slot, path, remove, add)); }
+
+ void connect(const Raul::Path& src_port_path, const Raul::Path& dst_port_path)
+ { push_sig(sigc::bind(connection_slot, src_port_path, dst_port_path)); }
+
+ void del(const Raul::URI& uri)
+ { push_sig(sigc::bind(object_deleted_slot, uri)); }
+
+ void move(const Raul::Path& old_path, const Raul::Path& new_path)
+ { push_sig(sigc::bind(object_moved_slot, old_path, new_path)); }
+
+ void disconnect(const Raul::URI& src, const Raul::URI& dst)
+ { push_sig(sigc::bind(disconnection_slot, src, dst)); }
+
+ void disconnect_all(const Raul::Path& parent_patch_path, const Raul::Path& path)
+ { push_sig(sigc::bind(disconnect_all_slot, parent_patch_path, path)); }
+
+ void set_property(const Raul::URI& subject, const Raul::URI& key, const Raul::Atom& value)
+ { push_sig(sigc::bind(property_change_slot, subject, key, value)); }
+
+ void activity(const Raul::Path& port_path)
+ { push_sig(sigc::bind(activity_slot, port_path)); }
+
+ /** Process all queued events - Called from GTK thread to emit signals. */
+ bool emit_signals();
+
+private:
+ void push_sig(Closure ev);
+
+ Glib::Mutex _mutex;
+ Glib::Cond _cond;
+
+ Raul::SRSWQueue<Closure> _sigs;
+
+ sigc::slot<void> bundle_begin_slot;
+ sigc::slot<void> bundle_end_slot;
+ sigc::slot<void, int32_t> response_ok_slot;
+ sigc::slot<void, int32_t, std::string> response_error_slot;
+ sigc::slot<void, std::string> error_slot;
+ sigc::slot<void, Raul::URI, Raul::URI, Raul::Symbol> new_plugin_slot;
+ sigc::slot<void, Raul::Path, Raul::URI, uint32_t, bool> new_port_slot;
+ sigc::slot<void, Raul::URI, Resource::Properties,
+ Resource::Graph> put_slot;
+ sigc::slot<void, Raul::URI, Resource::Properties,
+ Resource::Properties> delta_slot;
+ sigc::slot<void, Raul::Path, Raul::Path> connection_slot;
+ sigc::slot<void, Raul::URI> object_deleted_slot;
+ sigc::slot<void, Raul::Path, Raul::Path> object_moved_slot;
+ sigc::slot<void, Raul::URI, Raul::URI> disconnection_slot;
+ sigc::slot<void, Raul::Path, Raul::Path> disconnect_all_slot;
+ sigc::slot<void, Raul::URI, Raul::URI, Raul::Atom> variable_change_slot;
+ sigc::slot<void, Raul::URI, Raul::URI, Raul::Atom> property_change_slot;
+ sigc::slot<void, Raul::Path, Raul::Atom> port_value_slot;
+ sigc::slot<void, Raul::Path> activity_slot;
+};
+
+} // namespace Client
+} // namespace Ingen
+
+#endif