summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/interface/ClientInterface.h6
-rw-r--r--src/common/interface/EngineInterface.h6
-rw-r--r--src/common/util/Condition.h42
-rw-r--r--src/common/util/Makefile.am4
-rw-r--r--src/common/util/Mutex.h41
-rw-r--r--src/common/util/Semaphore.h2
-rw-r--r--src/common/util/Slave.h57
-rw-r--r--src/common/util/Thread.h100
8 files changed, 252 insertions, 6 deletions
diff --git a/src/common/interface/ClientInterface.h b/src/common/interface/ClientInterface.h
index 5d56fa8e..3a9d9508 100644
--- a/src/common/interface/ClientInterface.h
+++ b/src/common/interface/ClientInterface.h
@@ -57,14 +57,12 @@ public:
virtual void num_plugins(uint32_t num_plugins) = 0;
- virtual void new_plugin(string type,
- string uri,
+ virtual void new_plugin(string uri,
string name) = 0;
virtual void new_patch(string path, uint32_t poly) = 0;
- virtual void new_node(string plugin_type,
- string plugin_uri,
+ virtual void new_node(string plugin_uri,
string node_path,
bool is_polyphonic,
uint32_t num_ports) = 0;
diff --git a/src/common/interface/EngineInterface.h b/src/common/interface/EngineInterface.h
index b8dcb6d8..1c07a561 100644
--- a/src/common/interface/EngineInterface.h
+++ b/src/common/interface/EngineInterface.h
@@ -117,8 +117,12 @@ public:
virtual void ping() = 0;
+ virtual void request_plugin(const string& uri) = 0;
+
+ virtual void request_object(const string& path) = 0;
+
virtual void request_port_value(const string& port_path) = 0;
-
+
virtual void request_plugins() = 0;
virtual void request_all_objects() = 0;
diff --git a/src/common/util/Condition.h b/src/common/util/Condition.h
new file mode 100644
index 00000000..1ee28dbd
--- /dev/null
+++ b/src/common/util/Condition.h
@@ -0,0 +1,42 @@
+/* This file is part of Ingen. Copyright (C) 2006 Dave 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 CONDITION_H
+#define CONDITION_H
+
+#include <pthread.h>
+
+
+/** Trivial (but pretty) wrapper around POSIX Conditions (zero memory overhead).
+ *
+ * A semaphore that isn't a counter and is slow and NOT realtime safe.
+ */
+class Condition {
+public:
+ inline Condition() { pthread_cond_init(&_cond, NULL); }
+
+ inline ~Condition() { pthread_cond_destroy(&_cond); }
+
+ inline void signal() { pthread_cond_signal(&_cond); }
+ inline void wait(Mutex& mutex) { pthread_cond_wait(&_cond, &mutex._mutex); }
+
+private:
+ pthread_cond_t _cond;
+};
+
+
+#endif // CONDITION_H
+
diff --git a/src/common/util/Makefile.am b/src/common/util/Makefile.am
index 46bc3691..845a5d9a 100644
--- a/src/common/util/Makefile.am
+++ b/src/common/util/Makefile.am
@@ -3,5 +3,9 @@ EXTRA_DIST = \
Path.h \
Queue.h \
Semaphore.h \
+ Mutex.h \
+ Condition.h \
+ Thread.h \
+ Slave.h \
Atom.h \
LibloAtom.h
diff --git a/src/common/util/Mutex.h b/src/common/util/Mutex.h
new file mode 100644
index 00000000..c5aaf3ae
--- /dev/null
+++ b/src/common/util/Mutex.h
@@ -0,0 +1,41 @@
+/* This file is part of Ingen. Copyright (C) 2006 Dave 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 MUTEX_H
+#define MUTEX_H
+
+#include <pthread.h>
+
+
+/** Trivial (but pretty) wrapper around POSIX Mutexes (zero memory overhead).
+ */
+class Mutex {
+public:
+ inline Mutex() { pthread_mutex_init(&_mutex, NULL); }
+
+ inline ~Mutex() { pthread_mutex_destroy(&_mutex); }
+
+ inline bool try_lock() { return (pthread_mutex_trylock(&_mutex) == 0); }
+ inline void lock() { pthread_mutex_lock(&_mutex); }
+ inline void unlock() { pthread_mutex_unlock(&_mutex); }
+
+private:
+ friend class Condition;
+ pthread_mutex_t _mutex;
+};
+
+
+#endif // MUTEX_H
diff --git a/src/common/util/Semaphore.h b/src/common/util/Semaphore.h
index a98124bf..168a7059 100644
--- a/src/common/util/Semaphore.h
+++ b/src/common/util/Semaphore.h
@@ -20,7 +20,7 @@
#include <semaphore.h>
-/** Trivial wrapper around POSIX semaphores.
+/** Trivial wrapper around POSIX semaphores (zero memory overhead).
*
* This was created to provide an alternative debuggable implementation of
* semaphores based on a cond/mutex pair because semaphore's appeared not to
diff --git a/src/common/util/Slave.h b/src/common/util/Slave.h
new file mode 100644
index 00000000..0d0976b8
--- /dev/null
+++ b/src/common/util/Slave.h
@@ -0,0 +1,57 @@
+/* This file is part of Ingen. Copyright (C) 2006 Dave 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 SLAVE_H
+#define SLAVE_H
+
+#include <pthread.h>
+#include "util/Semaphore.h"
+#include "util/Thread.h"
+
+
+/** Thread driven by (realtime safe) signals.
+ *
+ * \ingroup engine
+ */
+class Slave : public Thread
+{
+public:
+ Slave() : _whip(0) {}
+
+ /** Tell the slave to do whatever work it does. Realtime safe. */
+ inline void whip() { _whip.post(); }
+
+protected:
+ virtual void _whipped() = 0;
+
+ Semaphore _whip;
+
+private:
+ // Prevent copies (undefined)
+ Slave(const Slave&);
+ Slave& operator=(const Slave&);
+
+ inline void _run()
+ {
+ while (true) {
+ _whip.wait();
+ _whipped();
+ }
+ }
+};
+
+
+#endif // SLAVE_H
diff --git a/src/common/util/Thread.h b/src/common/util/Thread.h
new file mode 100644
index 00000000..c139434b
--- /dev/null
+++ b/src/common/util/Thread.h
@@ -0,0 +1,100 @@
+/* This file is part of Ingen. Copyright (C) 2006 Dave 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 THREAD_H
+#define THREAD_H
+
+#include <string>
+#include <iostream>
+#include <pthread.h>
+
+
+/** Abstract base class for a thread.
+ *
+ * Extend this and override the _run method to easily create a thread
+ * to perform some task.
+ *
+ * \ingroup engine
+ */
+class Thread
+{
+public:
+ Thread() : _pthread_exists(false) {}
+
+ virtual ~Thread() { stop(); }
+
+ void set_name(const std::string& name) { _name = name; }
+
+ virtual void start() {
+ std::cout << "[" << _name << " Thread] Starting." << std::endl;
+
+ pthread_attr_t attr;
+ pthread_attr_init(&attr);
+ pthread_attr_setstacksize(&attr, 1500000);
+
+ pthread_create(&_pthread, &attr, _static_run, this);
+ _pthread_exists = true;
+ }
+
+ virtual void stop() {
+ if (_pthread_exists) {
+ pthread_cancel(_pthread);
+ pthread_join(_pthread, NULL);
+ _pthread_exists = false;
+ }
+ }
+
+ void set_scheduling(int policy, unsigned int priority) {
+ sched_param sp;
+ sp.sched_priority = priority;
+ int result = pthread_setschedparam(_pthread, SCHED_FIFO, &sp);
+ if (!result) {
+ std::cout << "[" << _name << "] Set scheduling policy to ";
+ switch (policy) {
+ case SCHED_FIFO: std::cout << "SCHED_FIFO"; break;
+ case SCHED_RR: std::cout << "SCHED_RR"; break;
+ case SCHED_OTHER: std::cout << "SCHED_OTHER"; break;
+ default: std::cout << "UNKNOWN"; break;
+ }
+ std::cout << ", priority " << sp.sched_priority << std::endl;
+ } else {
+ std::cout << "[" << _name << "] Unable to set scheduling policy ("
+ << strerror(result) << ")" << std::endl;
+ }
+ }
+
+
+protected:
+ virtual void _run() = 0;
+
+private:
+ // Prevent copies (undefined)
+ Thread(const Thread&);
+ Thread& operator=(const Thread&);
+
+ inline static void* _static_run(void* me) {
+ Thread* myself = (Thread*)me;
+ myself->_run();
+ return NULL; // and I
+ }
+
+ std::string _name;
+ bool _pthread_exists;
+ pthread_t _pthread;
+};
+
+
+#endif // THREAD_H