summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/Makefile.am1
-rw-r--r--src/common/interface/.ClientInterface.h.swpbin0 -> 12288 bytes
-rw-r--r--src/common/interface/ClientInterface.h102
-rw-r--r--src/common/interface/ClientKey.h84
-rw-r--r--src/common/interface/EngineInterface.h121
-rw-r--r--src/common/interface/Makefile.am5
-rw-r--r--src/common/interface/README13
-rw-r--r--src/common/util/CountedPtr.h185
-rw-r--r--src/common/util/Makefile.am6
-rw-r--r--src/common/util/Path.h84
-rw-r--r--src/common/util/Queue.h158
-rw-r--r--src/common/util/Semaphore.h63
-rw-r--r--src/common/util/types.h32
13 files changed, 854 insertions, 0 deletions
diff --git a/src/common/Makefile.am b/src/common/Makefile.am
new file mode 100644
index 00000000..bdad7860
--- /dev/null
+++ b/src/common/Makefile.am
@@ -0,0 +1 @@
+DIST_SUBDIRS = util interface
diff --git a/src/common/interface/.ClientInterface.h.swp b/src/common/interface/.ClientInterface.h.swp
new file mode 100644
index 00000000..f0127868
--- /dev/null
+++ b/src/common/interface/.ClientInterface.h.swp
Binary files differ
diff --git a/src/common/interface/ClientInterface.h b/src/common/interface/ClientInterface.h
new file mode 100644
index 00000000..d03f1668
--- /dev/null
+++ b/src/common/interface/ClientInterface.h
@@ -0,0 +1,102 @@
+/* This file is part of Om. Copyright (C) 2006 Dave Robillard.
+ *
+ * Om 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.
+ *
+ * Om 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.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef CLIENTINTERFACE_H
+#define CLIENTINTERFACE_H
+
+#include <inttypes.h>
+#include <string>
+using std::string;
+
+namespace Om {
+namespace Shared {
+
+
+/** The (only) interface the engine uses to communicate with clients.
+ *
+ * Purely virtual (except for the destructor).
+ */
+class ClientInterface
+{
+public:
+
+ virtual ~ClientInterface() {}
+
+ virtual void bundle_begin() = 0;
+ virtual void bundle_end() = 0;
+
+ virtual void error(const string& msg) = 0;
+
+ virtual void num_plugins(uint32_t num_plugins) = 0;
+
+ virtual void new_plugin(const string& type,
+ const string& uri,
+ const string& name) = 0;
+
+ virtual void new_patch(const string& path, uint32_t poly) = 0;
+
+ virtual void new_node(const string& plugin_type,
+ const string& plugin_uri,
+ const string& node_path,
+ bool is_polyphonic,
+ uint32_t num_ports) = 0;
+
+ virtual void new_port(const string& path,
+ const string& data_type,
+ bool is_output) = 0;
+
+ virtual void patch_enabled(const string& path) = 0;
+
+ virtual void patch_disabled(const string& path) = 0;
+
+ virtual void patch_cleared(const string& path) = 0;
+
+ virtual void object_renamed(const string& old_path,
+ const string& new_path) = 0;
+
+ virtual void object_destroyed(const string& path) = 0;
+
+ virtual void connection(const string& src_port_path,
+ const string& dst_port_path) = 0;
+
+ virtual void disconnection(const string& src_port_path,
+ const string& dst_port_path) = 0;
+
+ virtual void metadata_update(const string& subject_path,
+ const string& predicate,
+ const string& value) = 0;
+
+ virtual void control_change(const string& port_path,
+ float value) = 0;
+
+ virtual void program_add(const string& node_path,
+ uint32_t bank,
+ uint32_t program,
+ const string& program_name) = 0;
+
+ virtual void program_remove(const string& node_path,
+ uint32_t bank,
+ uint32_t program) = 0;
+
+protected:
+ ClientInterface() {}
+};
+
+
+} // namespace Shared
+} // namespace Om
+
+#endif
diff --git a/src/common/interface/ClientKey.h b/src/common/interface/ClientKey.h
new file mode 100644
index 00000000..eb580a2d
--- /dev/null
+++ b/src/common/interface/ClientKey.h
@@ -0,0 +1,84 @@
+/* This file is part of Om. Copyright (C) 2006 Dave Robillard.
+ *
+ * Om 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.
+ *
+ * Om 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.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef CLIENTKEY_H
+#define CLIENTKEY_H
+
+#include <string>
+
+namespace Om {
+namespace Shared {
+
+
+/** Key for looking up clients.
+ *
+ * This might actually be a lookup key (as in OSC clients) or a direct handle
+ * of some kind (eg pointer) (for in-process or shared memory clients).
+ *
+ * This is shared code, nothing client or server code specific should be here.
+ */
+class ClientKey
+{
+public:
+ /** A key to identify a particular ClientInterface.
+ *
+ * There are two different OSC key types because one is for server side,
+ * and one is for client side. A client can not identify it's own URL to
+ * the host (for NAT traversal, etc) so it can only know the outgoing UDP
+ * port it's sending on. The server however identifies that client by the
+ * full incoming URL.
+ */
+ enum Type {
+ NIL, ///< A NULL key (represents no client)
+ OSC_URL, ///< An OSC URL (remote host/client)
+ OSC_PORT ///< A local OSC port
+ };
+
+ ClientKey()
+ : _type(NIL),
+ _uri("")
+ {}
+
+ ClientKey(Type type, const std::string& uri)
+ : _type(OSC_URL)
+ , _uri(uri)
+ {}
+
+ /*ClientKey(Type type, int port)
+ : _type(OSC_PORT)
+ , _port(port)
+ {}*/
+
+ inline bool
+ operator==(const ClientKey& key) const
+ {
+ return (_type == key._type && _uri == key._uri);
+ }
+
+ inline Type type() const { return _type; }
+ inline const std::string& uri() const { return _uri; }
+
+protected:
+ Type _type;
+ const std::string _uri; ///< URL for OSC_URL, (string) port number for OSC_PORT
+};
+
+
+} // namespace Shared
+} // namespace Om
+
+#endif // CLIENTKEY_H
+
diff --git a/src/common/interface/EngineInterface.h b/src/common/interface/EngineInterface.h
new file mode 100644
index 00000000..c290a921
--- /dev/null
+++ b/src/common/interface/EngineInterface.h
@@ -0,0 +1,121 @@
+/* This file is part of Om. Copyright (C) 2006 Dave Robillard.
+ *
+ * Om is free software = 0; you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation = 0; either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * Om is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY = 0; 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 = 0; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef ENGINEINTERFACE_H
+#define ENGINEINTERFACE_H
+
+#include <inttypes.h>
+#include <string>
+#include "util/CountedPtr.h"
+#include "interface/ClientInterface.h"
+using std::string;
+
+namespace Om {
+/** Shared code used on both client side and engine side (abstract interfaces). */
+namespace Shared {
+
+class ClientKey;
+
+
+/** The (only) interface clients use to communicate with the engine.
+ *
+ * Purely virtual (except for the destructor).
+ */
+class EngineInterface
+{
+public:
+ virtual ~EngineInterface() {}
+
+ // Client registration
+ virtual void register_client(ClientKey key, CountedPtr<ClientInterface> client) = 0;
+ virtual void unregister_client(ClientKey key) = 0;
+
+
+ // Engine commands
+ virtual void load_plugins() = 0;
+ virtual void activate() = 0;
+ virtual void deactivate() = 0;
+ virtual void quit() = 0;
+
+ // Object commands
+
+ virtual void create_patch(const string& path,
+ uint32_t poly) = 0;
+
+ virtual void create_node(const string& path,
+ const string& plugin_type,
+ const string& plugin_uri,
+ bool polyphonic) = 0;
+
+ virtual void rename(const string& old_path,
+ const string& new_name) = 0;
+
+ virtual void destroy(const string& path) = 0;
+
+ virtual void clear_patch(const string& patch_path) = 0;
+
+ virtual void enable_patch(const string& patch_path) = 0;
+
+ virtual void disable_patch(const string& patch_path) = 0;
+
+ virtual void connect(const string& src_port_path,
+ const string& dst_port_path) = 0;
+
+ virtual void disconnect(const string& src_port_path,
+ const string& dst_port_path) = 0;
+
+ virtual void disconnect_all(const string& node_path) = 0;
+
+ virtual void set_port_value(const string& port_path,
+ float val) = 0;
+
+ virtual void set_port_value(const string& port_path,
+ uint32_t voice,
+ float val) = 0;
+
+ virtual void set_port_value_queued(const string& port_path,
+ float val) = 0;
+
+ virtual void set_program(const string& node_path,
+ uint32_t bank,
+ uint32_t program) = 0;
+
+ virtual void midi_learn(const string& node_path) = 0;
+
+ virtual void set_metadata(const string& path,
+ const string& predicate,
+ const string& value) = 0;
+
+ // Requests //
+
+ virtual void ping() = 0;
+
+ virtual void request_port_value(const string& port_path) = 0;
+
+ virtual void request_plugins() = 0;
+
+ virtual void request_all_objects() = 0;
+
+protected:
+ EngineInterface() {}
+};
+
+
+} // namespace Shared
+} // namespace Om
+
+#endif // ENGINEINTERFACE_H
+
diff --git a/src/common/interface/Makefile.am b/src/common/interface/Makefile.am
new file mode 100644
index 00000000..8719cccd
--- /dev/null
+++ b/src/common/interface/Makefile.am
@@ -0,0 +1,5 @@
+EXTRA_DIST = \
+ README \
+ ClientInterface.h \
+ ClientKey.h \
+ EngineInterface.h
diff --git a/src/common/interface/README b/src/common/interface/README
new file mode 100644
index 00000000..efa19700
--- /dev/null
+++ b/src/common/interface/README
@@ -0,0 +1,13 @@
+This directory is code that could POSSIBLY be used by both the engine and
+clients.
+
+It's very, very important that nothing here gets messed up that violates
+client/engine separation. All interfaces use simple messages composed of
+serializable types, and no binary data that could break is shared. It's
+basically a functional version of a human-readable OSC interface, in both
+directions.
+
+The interface here maps directly on to the OSC interface - except it can
+happen in the same process as well, with only (virtual) function call
+overhead.
+
diff --git a/src/common/util/CountedPtr.h b/src/common/util/CountedPtr.h
new file mode 100644
index 00000000..f2079c7c
--- /dev/null
+++ b/src/common/util/CountedPtr.h
@@ -0,0 +1,185 @@
+/* A Reference Counting Smart Pointer.
+ * Copyright (C) 2006 Dave Robillard.
+ *
+ * This 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.
+ *
+ * This 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.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef COUNTED_PTR_H
+#define COUNTED_PTR_H
+
+#include <cassert>
+#include <cstddef>
+
+
+/** Simple reference counted pointer.
+ *
+ * Allocates one counter on the heap on initial construction. You can safely
+ * cast a CountedPtr<X> to a CountedPtr<Y> iff Y is a base of X (eg the cast
+ * will only compile if it is a valid up-cast).
+ *
+ * It is possible for this to be a NULL pointer, and a boolean conversion
+ * operator is provided so you can test for this with "if (someCountedPtr)".
+ * Dereferencing a NULL CountedPtr will result in a failed assertion if
+ * debugging is enabled.
+ *
+ * FIXME: test this more thoroughly
+ */
+template <class T>
+class CountedPtr
+{
+public:
+
+ // Declare some other type of CountedPtr as a friend (for casting)
+ template <class Y> friend class CountedPtr;
+
+
+ /** Allocate a new Counter (if p is non-NULL) */
+ CountedPtr(T* p)
+ : _counter(NULL)
+ {
+ if (p)
+ _counter = new Counter(p);
+ }
+
+ ~CountedPtr()
+ {
+ release();
+ }
+
+ /** Copy a CountedPtr with the same type. */
+ CountedPtr(const CountedPtr& copy)
+ : _counter(NULL)
+ {
+ assert(copy);
+ assert(this != &copy);
+ retain(copy._counter);
+ }
+
+ /** Copy a CountedPtr to a valid base class.
+ */
+ template <class Y>
+ CountedPtr(const CountedPtr<Y>& y)
+ : _counter(NULL)
+ {
+ assert(this != (CountedPtr*)&y);
+
+ // Fail if this is not a valid cast
+ if (y) {
+ T* const unused_variable = static_cast<Y* const>(y._counter->ptr);
+ assert(unused_variable == y._counter->ptr); // shuts up gcc
+ }
+
+ //release();
+ retain((Counter*)y._counter);
+ }
+
+ /** Assign to the value of a CountedPtr of the same type. */
+ CountedPtr& operator=(const CountedPtr& copy)
+ {
+ if (this != &copy) {
+ release();
+ retain(copy._counter);
+ }
+ return *this;
+ }
+
+ /** Assign to the value of a CountedPtr of a different type. */
+ template <class Y>
+ CountedPtr& operator=(const CountedPtr<Y>& y)
+ {
+ if (this != (CountedPtr*)&y) {
+ release();
+ retain(y._counter);
+ }
+ return *this;
+ }
+
+ inline bool operator==(const CountedPtr& p) const
+ {
+ return (_counter == p._counter);
+ }
+
+ inline bool operator!=(const CountedPtr& p) const
+ {
+ return (_counter != p._counter);
+ }
+
+ /** Allow testing for NULL nicely like a real pointer */
+ operator bool() const
+ {
+ return (_counter && _counter->ptr);
+ }
+
+ inline T& operator*() const
+ {
+ assert(_counter);
+ assert(_counter->count > 0);
+ assert(_counter->ptr);
+ return *_counter->ptr;
+ }
+
+ inline T* operator->() const
+ {
+ assert(_counter);
+ assert(_counter->count > 0);
+ assert(_counter->ptr);
+ return _counter->ptr;
+ }
+
+ inline T* get() const { return _counter ? _counter->ptr : 0; }
+
+ bool unique() const { return (_counter ? _counter->count == 1 : true); }
+
+private:
+ /** Stored on the heap and referred to by all existing CountedPtr's to
+ * the object */
+ struct Counter
+ {
+ Counter(T* p)
+ : ptr(p)
+ , count(1)
+ {
+ assert(p);
+ }
+
+ T* const ptr;
+ volatile size_t count;
+ };
+
+ /** Increment the count */
+ void retain(Counter* c)
+ {
+ assert(_counter == NULL || _counter == c);
+ _counter = c;
+ if (_counter)
+ ++c->count;
+ }
+
+ /** Decrement the count, delete if we're the last reference */
+ void release()
+ {
+ if (_counter) {
+ if (--(_counter->count) == 0) {
+ delete _counter->ptr;
+ delete _counter;
+ }
+ _counter = NULL;
+ }
+ }
+
+
+ Counter* _counter;
+};
+
+#endif // COUNTED_PTR_H
diff --git a/src/common/util/Makefile.am b/src/common/util/Makefile.am
new file mode 100644
index 00000000..b835dfde
--- /dev/null
+++ b/src/common/util/Makefile.am
@@ -0,0 +1,6 @@
+EXTRA_DIST = \
+ CountedPtr.h \
+ Path.h \
+ Queue.h \
+ Semaphore.h \
+ types.h
diff --git a/src/common/util/Path.h b/src/common/util/Path.h
new file mode 100644
index 00000000..126fe01d
--- /dev/null
+++ b/src/common/util/Path.h
@@ -0,0 +1,84 @@
+/* This file is part of Om. Copyright (C) 2005 Dave Robillard.
+ *
+ * Om 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.
+ *
+ * Om 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.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PATH_H
+#define PATH_H
+
+#include <string>
+#include <cassert>
+using std::string;
+
+namespace Om {
+
+
+/** Simple wrapper around standard string with useful path-specific methods.
+ */
+class Path : public std::basic_string<char> {
+public:
+ Path(const std::basic_string<char>& path)
+ : std::basic_string<char>(path)
+ {
+ assert(path.length() > 0);
+ }
+
+
+ inline bool is_valid() const
+ {
+ return (find_last_of("/") != string::npos);
+ }
+
+ /** Return the name of this object (everything after the last '/').
+ */
+ inline std::basic_string<char> name() const
+ {
+ assert(is_valid());
+
+ if ((*this) == "/")
+ return "";
+ else
+ return substr(find_last_of("/")+1);
+ }
+
+
+ /** Return the parent's path.
+ *
+ * Calling this on the path "/" will return "/".
+ */
+ inline Path parent() const
+ {
+ assert(is_valid());
+
+ std::basic_string<char> parent = substr(0, find_last_of("/"));
+ return (parent == "") ? "/" : parent;
+ }
+
+ inline Path base_path() const
+ {
+ assert(is_valid());
+
+ if ((*this) == "/")
+ return *this;
+ else
+ return (*this) + "/";
+ }
+
+ Path(const char* s) : std::basic_string<char>(s) {}
+};
+
+
+} // namespace Om
+
+#endif // PATH_H
diff --git a/src/common/util/Queue.h b/src/common/util/Queue.h
new file mode 100644
index 00000000..649cbcbe
--- /dev/null
+++ b/src/common/util/Queue.h
@@ -0,0 +1,158 @@
+/* This file is part of Om. Copyright (C) 2005 Dave Robillard.
+ *
+ * Om 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.
+ *
+ * Om 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.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef QUEUE_H
+#define QUEUE_H
+
+#include <cassert>
+#include <cstdlib>
+
+
+/** Realtime-safe single-reader single-writer queue (aka lock-free ringbuffer)
+ *
+ * Implemented as a dequeue in a fixed array. This is read/write thread-safe,
+ * pushing and popping may occur simultaneously by seperate threads, but
+ * the push and pop operations themselves are not thread-safe.
+ *
+ * FIXME: Verify atomicity of everything here.
+ */
+template <typename T>
+class Queue
+{
+public:
+ Queue(size_t size);
+ ~Queue();
+
+ inline bool is_empty() const;
+ inline bool is_full() const;
+
+ inline size_t capacity() const { return m_size-1; }
+ inline size_t fill() const;
+
+ inline T& front() const;
+
+ inline bool push(T obj);
+ inline T& pop();
+
+private:
+ // Prevent copies (these are undefined)
+ Queue(const Queue& copy);
+ Queue& operator=(const Queue& copy);
+
+ volatile size_t m_front; ///< Index to front of queue (circular)
+ volatile size_t m_back; ///< Index to back of queue (one past last element) (circular)
+ const size_t m_size; ///< Size of @ref m_objects (you can store m_size-1 objects)
+ T* const m_objects; ///< Fixed array containing queued elements
+};
+
+
+template<typename T>
+Queue<T>::Queue(size_t size)
+: m_front(0),
+ m_back(0),
+ m_size(size+1),
+ m_objects((T*)calloc(m_size, sizeof(T)))
+{
+}
+
+
+template <typename T>
+Queue<T>::~Queue()
+{
+ free(m_objects);
+}
+
+
+/** Return whether or not the queue is empty.
+ */
+template <typename T>
+inline bool
+Queue<T>::is_empty() const
+{
+ return (m_back == m_front);
+}
+
+
+/** Return whether or not the queue is full.
+ */
+template <typename T>
+inline bool
+Queue<T>::is_full() const
+{
+ // FIXME: This can probably be faster
+ return (fill() == capacity());
+}
+
+
+/** Returns how many elements are currently in the queue.
+ */
+template <typename T>
+inline size_t
+Queue<T>::fill() const
+{
+ return (m_back + m_size - m_front) % m_size;
+}
+
+
+/** Return the element at the front of the queue without removing it
+ */
+template <typename T>
+inline T&
+Queue<T>::front() const
+{
+ return m_objects[m_front];
+}
+
+
+/** Push an item onto the back of the Queue - realtime-safe, not thread-safe.
+ *
+ * @returns true if @a elem was successfully pushed onto the queue,
+ * false otherwise (queue is full).
+ */
+template <typename T>
+inline bool
+Queue<T>::push(T elem)
+{
+ if (is_full()) {
+ return false;
+ } else {
+ m_objects[m_back] = elem;
+ m_back = (m_back + 1) % (m_size);
+ return true;
+ }
+}
+
+
+/** Pop an item off the front of the queue - realtime-safe, not thread-safe.
+ *
+ * It is a fatal error to call pop() when the queue is empty.
+ *
+ * @returns the element popped.
+ */
+template <typename T>
+inline T&
+Queue<T>::pop()
+{
+ assert(!is_empty());
+
+ T& r = m_objects[m_front];
+ m_front = (m_front + 1) % (m_size);
+
+ return r;
+}
+
+
+#endif // QUEUE_H
diff --git a/src/common/util/Semaphore.h b/src/common/util/Semaphore.h
new file mode 100644
index 00000000..c8abaf35
--- /dev/null
+++ b/src/common/util/Semaphore.h
@@ -0,0 +1,63 @@
+/* This file is part of Om. Copyright (C) 2005 Dave Robillard.
+ *
+ * Om 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.
+ *
+ * Om 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.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef SEMAPHORE_H
+#define SEMAPHORE_H
+
+#include <semaphore.h>
+
+
+/** Trivial wrapper around POSIX semaphores.
+ *
+ * This was created to provide an alternative debuggable implementation of
+ * semaphores based on a cond/mutex pair because semaphore's appeared not to
+ * work in GDB. Turns out sem_wait can fail when run in GDB, and Debian
+ * really needs to update it's man pages.
+ *
+ * This class remains as a pretty wrapper/abstraction that does nothing.
+ */
+class Semaphore {
+public:
+ inline Semaphore(unsigned int initial) { sem_init(&m_sem, 0, initial); }
+
+ inline ~Semaphore() { sem_destroy(&m_sem); }
+
+ /** Increment (and signal any waiters).
+ *
+ * Realtime safe.
+ */
+ inline void post() { sem_post(&m_sem); }
+
+ /** Wait until count is > 0, then decrement.
+ *
+ * Note that sem_wait always returns 0 in practise. It returns nonzero
+ * when run in GDB, so the while is necessary to allow debugging.
+ *
+ * Obviously not realtime safe.
+ */
+ inline void wait() { while (sem_wait(&m_sem) != 0) ; }
+
+ /** Non-blocking version of wait().
+ *
+ * Realtime safe?
+ */
+ inline int try_wait() { return sem_trywait(&m_sem); }
+private:
+ sem_t m_sem;
+};
+
+
+#endif // SEMAPHORE_H
diff --git a/src/common/util/types.h b/src/common/util/types.h
new file mode 100644
index 00000000..4c138292
--- /dev/null
+++ b/src/common/util/types.h
@@ -0,0 +1,32 @@
+/* This file is part of Om. Copyright (C) 2005 Dave Robillard.
+ *
+ * Om 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.
+ *
+ * Om 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.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#ifndef TYPES_H
+#define TYPES_H
+
+#include <cstddef> // for NULL, size_t, etc
+#include <jack/jack.h>
+
+typedef unsigned char uchar;
+typedef unsigned int uint;
+typedef unsigned long ulong;
+
+typedef jack_default_audio_sample_t sample;
+typedef jack_nframes_t samplecount;
+typedef jack_nframes_t samplerate;
+
+#endif // TYPES_H