diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/interface/ClientInterface.h | 10 | ||||
-rw-r--r-- | src/common/interface/EngineInterface.h | 48 | ||||
-rw-r--r-- | src/common/util/CountedPtr.h | 53 | ||||
-rw-r--r-- | src/common/util/Path.h | 19 |
4 files changed, 88 insertions, 42 deletions
diff --git a/src/common/interface/ClientInterface.h b/src/common/interface/ClientInterface.h index 071b854e..3adc76f4 100644 --- a/src/common/interface/ClientInterface.h +++ b/src/common/interface/ClientInterface.h @@ -36,14 +36,14 @@ public: virtual ~ClientInterface() {} virtual void response(int32_t id, bool success, string msg) = 0; - + /** Bundles are a group of messages that are guaranteed to be in an * atomic unit with guaranteed order (eg a packet). For datagram * protocols (like UDP) there is likely an upper limit on bundle size. */ virtual void bundle_begin() = 0; virtual void bundle_end() = 0; - + /** Transfers are 'weak' bundles. These are used to break a large group * of similar/related messages into larger chunks (solely for communication * efficiency). A bunch of messages in a transfer will arrive as 1 or more @@ -51,11 +51,11 @@ public: */ virtual void transfer_begin() = 0; virtual void transfer_end() = 0; - + virtual void error(string msg) = 0; virtual void num_plugins(uint32_t num_plugins) = 0; - + virtual void new_plugin(string type, string uri, string name) = 0; @@ -101,7 +101,7 @@ public: uint32_t program, string program_name) = 0; - virtual void program_remove(string node_path, + virtual void program_remove(string node_path, uint32_t bank, uint32_t program) = 0; diff --git a/src/common/interface/EngineInterface.h b/src/common/interface/EngineInterface.h index 04d143b1..46f6fa99 100644 --- a/src/common/interface/EngineInterface.h +++ b/src/common/interface/EngineInterface.h @@ -42,23 +42,23 @@ public: // Responses virtual void set_next_response_id(int32_t id) = 0; virtual void disable_responses() = 0; - + // 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_port(const string& path, const string& data_type, bool direction) = 0; @@ -66,50 +66,50 @@ public: virtual void create_node(const string& path, const string& plugin_type, const string& plugin_uri, - bool polyphonic) = 0; + bool polyphonic) = 0; /** DEPRECATED */ virtual void create_node(const string& path, const string& plugin_type, const string& library_name, const string& plugin_label, - bool polyphonic) = 0; - + 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; @@ -117,13 +117,13 @@ public: // 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() {} }; diff --git a/src/common/util/CountedPtr.h b/src/common/util/CountedPtr.h index c5eb2e50..e3f34ec2 100644 --- a/src/common/util/CountedPtr.h +++ b/src/common/util/CountedPtr.h @@ -21,6 +21,21 @@ #include <cassert> #include <cstddef> +// honestly, WTF? +#include <boost/shared_ptr.hpp> + +#define CountedPtr boost::shared_ptr +#define PtrCast boost::dynamic_pointer_cast +#if 0 +// FIXME +#ifndef NDEBUG +#define COUNTED_PTR_DEBUG +#include <iostream> +#include <list> +#include <algorithm> +static std::list<void*> counted_ptr_counters; +#endif + /** Simple reference counted pointer. * @@ -46,7 +61,7 @@ public: /** Allocate a new Counter (if p is non-NULL) */ CountedPtr(T* p) - : _counter(NULL) + : _counter(0) { if (p) _counter = new Counter(p); @@ -57,7 +72,7 @@ public: * in STL containers :/ */ CountedPtr() - : _counter(NULL) + : _counter(0) {} ~CountedPtr() @@ -67,7 +82,7 @@ public: /** Copy a CountedPtr with the same type. */ CountedPtr(const CountedPtr& copy) - : _counter(NULL) + : _counter(0) { assert(this != ©); @@ -81,7 +96,7 @@ public: */ template <class Y> CountedPtr(const CountedPtr<Y>& y) - : _counter(NULL) + : _counter(0) { assert(this != (CountedPtr*)&y); @@ -96,14 +111,14 @@ public: } } - assert(_counter == NULL || _counter == (Counter*)y._counter); + assert( ! _counter || _counter == (Counter*)y._counter); } /** Assign to the value of a CountedPtr of the same type. */ CountedPtr& operator=(const CountedPtr& copy) { if (this != ©) { - assert(_counter == NULL || _counter != copy._counter); + assert( ! _counter || _counter != copy._counter); release(); retain(copy._counter); } @@ -163,23 +178,42 @@ public: private: /** Stored on the heap and referred to by all existing CountedPtr's to * the object */ - struct Counter + class Counter { + public: Counter(T* p) : ptr(p) , count(1) { assert(p); +#ifdef COUNTED_PTR_DEBUG + assert(std::find(counted_ptr_counters.begin(), counted_ptr_counters.end(), (void*)p) + == counted_ptr_counters.end()); + counted_ptr_counters.push_back(p); + std::cerr << "Creating " << typeid(T).name() << " Counter " << this << std::endl; +#endif } + ~Counter() + { + // for debugging + assert(count == 0); + count = 0; + } + T* const ptr; volatile size_t count; + + private: + // Prevent copies (undefined) + Counter(const Counter& copy); + Counter& operator=(const Counter& copy); }; /** Increment the count */ void retain(Counter* c) { - assert(_counter == NULL || _counter == c); + assert( ! _counter || _counter == c); _counter = c; if (_counter) ++(c->count); @@ -193,12 +227,13 @@ private: delete _counter->ptr; delete _counter; } - _counter = NULL; + _counter = 0; } } Counter* _counter; }; +#endif #endif // COUNTED_PTR_H diff --git a/src/common/util/Path.h b/src/common/util/Path.h index c84607fb..6c6d54be 100644 --- a/src/common/util/Path.h +++ b/src/common/util/Path.h @@ -199,17 +199,28 @@ public: /** Parent path with a "/" appended. * - * Because of the "/" special case, append a child name to base_path() - * to construct a path. This return value followed by a valid name is - * guaranteed to be a valid path. + * This exists to avoid needing to be careful about the special case of "/". + * To create a child of a path, use parent.base() + child_name. + * Returned value is always a valid path, with the single exception that + * the last character is "/". */ - inline string base_path() const + inline string base() const { if ((*this) == "/") return *this; else return (*this) + "/"; } + + inline bool is_child_of(const Path& parent) const + { + return (length() > parent.length() && substr(0, parent.length()) == parent); + } + + inline bool is_parent_of(const Path& child) const + { + return child.is_child_of(*this); + } }; |