diff options
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/ClientModel.cpp | 94 | ||||
-rw-r--r-- | src/client/ClientModel.hpp | 67 | ||||
-rw-r--r-- | src/client/ClientObject.cpp | 56 | ||||
-rw-r--r-- | src/client/ClientObject.hpp | 71 | ||||
-rw-r--r-- | src/client/wscript | 17 |
5 files changed, 305 insertions, 0 deletions
diff --git a/src/client/ClientModel.cpp b/src/client/ClientModel.cpp new file mode 100644 index 0000000..3a8770f --- /dev/null +++ b/src/client/ClientModel.cpp @@ -0,0 +1,94 @@ +/* + This file is part of Machina. + Copyright 2007-2014 David Robillard <http://drobilla.net> + + Machina 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 3 of the License, or any later version. + + Machina 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 more details. + + You should have received a copy of the GNU General Public License + along with Machina. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "ClientModel.hpp" + +namespace machina { +namespace client { + +SPtr<ClientObject> +ClientModel::find(uint64_t id) +{ + SPtr<ClientObject> key(new ClientObjectKey(id)); + Objects::iterator i = _objects.find(key); + if (i != _objects.end()) { + return *i; + } else { + return SPtr<ClientObject>(); + } +} + +SPtr<const ClientObject> +ClientModel::find(uint64_t id) const +{ + SPtr<ClientObject> key(new ClientObjectKey(id)); + Objects::const_iterator i = _objects.find(key); + if (i != _objects.end()) { + return *i; + } else { + return SPtr<ClientObject>(); + } +} + +void +ClientModel::new_object(uint64_t id, const Properties& properties) +{ + SPtr<ClientObject> key(new ClientObjectKey(id)); + Objects::iterator i = _objects.find(key); + if (i == _objects.end()) { + SPtr<ClientObject> object(new ClientObject(id, properties)); + _objects.insert(object); + signal_new_object.emit(object); + } else { + for (const auto& p : properties) { + (*i)->set(p.first, p.second); + } + } +} + +void +ClientModel::erase_object(uint64_t id) +{ + SPtr<ClientObject> key(new ClientObjectKey(id)); + Objects::iterator i = _objects.find(key); + if (i == _objects.end()) { + return; + } + + signal_erase_object.emit(*i); + (*i)->set_view(NULL); + _objects.erase(i); +} + +void +ClientModel::set(uint64_t id, URIInt key, const Atom& value) +{ + SPtr<ClientObject> object = find(id); + if (object) { + object->set(key, value); + } +} + +const Atom& +ClientModel::get(uint64_t id, URIInt key) const +{ + static const Atom null_atom; + SPtr<const ClientObject> object = find(id); + return object ? object->get(key) : null_atom; +} + +} +} diff --git a/src/client/ClientModel.hpp b/src/client/ClientModel.hpp new file mode 100644 index 0000000..e65fb93 --- /dev/null +++ b/src/client/ClientModel.hpp @@ -0,0 +1,67 @@ +/* + This file is part of Machina. + Copyright 2007-2014 David Robillard <http://drobilla.net> + + Machina 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 3 of the License, or any later version. + + Machina 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 more details. + + You should have received a copy of the GNU General Public License + along with Machina. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef MACHINA_CLIENTMODEL_HPP +#define MACHINA_CLIENTMODEL_HPP + +#include <set> + +#include <sigc++/sigc++.h> + +#include "machina/Model.hpp" + +#include "ClientObject.hpp" + +namespace Raul { +class Atom; +} + +namespace machina { +namespace client { + +class ClientModel : public Model +{ +public: + void new_object(uint64_t id, const Properties& properties); + + void erase_object(uint64_t id); + + SPtr<ClientObject> find(uint64_t id); + SPtr<const ClientObject> find(uint64_t id) const; + + void set(uint64_t id, URIInt key, const Atom& value); + const Atom& get(uint64_t id, URIInt key) const; + + sigc::signal< void, SPtr<ClientObject> > signal_new_object; + sigc::signal< void, SPtr<ClientObject> > signal_erase_object; + +private: + struct ClientObjectComparator { + inline bool operator()(SPtr<ClientObject> lhs, + SPtr<ClientObject> rhs) const { + return lhs->id() < rhs->id(); + } + + }; + + typedef std::set<SPtr<ClientObject>, ClientObjectComparator> Objects; + Objects _objects; +}; + +} +} + +#endif // MACHINA_CLIENTMODEL_HPP diff --git a/src/client/ClientObject.cpp b/src/client/ClientObject.cpp new file mode 100644 index 0000000..20b50a2 --- /dev/null +++ b/src/client/ClientObject.cpp @@ -0,0 +1,56 @@ +/* + This file is part of Machina. + Copyright 2007-2014 David Robillard <http://drobilla.net> + + Machina 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 3 of the License, or any later version. + + Machina 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 more details. + + You should have received a copy of the GNU General Public License + along with Machina. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <iostream> + +#include "ClientObject.hpp" + +namespace machina { +namespace client { + +ClientObject::ClientObject(uint64_t id, const Properties& properties) + : _id(id) + , _view(NULL) + , _properties(properties) +{} + +ClientObject::ClientObject(const ClientObject& copy, uint64_t id) + : _id(id) + , _view(NULL) + , _properties(copy._properties) +{} + +void +ClientObject::set(URIInt key, const Atom& value) +{ + _properties[key] = value; + signal_property.emit(key, value); +} + +const Atom& +ClientObject::get(URIInt key) const +{ + static const Atom null_atom; + Properties::const_iterator i = _properties.find(key); + if (i != _properties.end()) { + return i->second; + } else { + return null_atom; + } +} + +} +} diff --git a/src/client/ClientObject.hpp b/src/client/ClientObject.hpp new file mode 100644 index 0000000..6520b11 --- /dev/null +++ b/src/client/ClientObject.hpp @@ -0,0 +1,71 @@ +/* + This file is part of Machina. + Copyright 2007-2014 David Robillard <http://drobilla.net> + + Machina 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 3 of the License, or any later version. + + Machina 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 more details. + + You should have received a copy of the GNU General Public License + along with Machina. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef MACHINA_CLIENTOBJECT_HPP +#define MACHINA_CLIENTOBJECT_HPP + +#include <map> + +#include <sigc++/sigc++.h> + +#include "machina/Atom.hpp" +#include "machina/types.hpp" + +namespace machina { +namespace client { + +class ClientObject +{ +public: + explicit ClientObject(uint64_t id, const Properties& properties={}); + ClientObject(const ClientObject& copy, uint64_t id); + + inline uint64_t id() const { return _id; } + + void set(URIInt key, const Atom& value); + const Atom& get(URIInt key) const; + + sigc::signal<void, URIInt, Atom> signal_property; + + class View + { + public: + virtual ~View() {} + }; + + typedef std::map<URIInt, Atom> Properties; + const Properties& properties() { return _properties; } + + View* view() const { return _view; } + void set_view(View* view) { _view = view; } + +private: + uint64_t _id; + View* _view; + + Properties _properties; +}; + +/** Stub client object to use as a search key. */ +struct ClientObjectKey : public ClientObject +{ + explicit ClientObjectKey(uint64_t id) : ClientObject(id) {} +}; + +} +} + +#endif // MACHINA_CLIENTOBJECT_HPP diff --git a/src/client/wscript b/src/client/wscript new file mode 100644 index 0000000..8333b43 --- /dev/null +++ b/src/client/wscript @@ -0,0 +1,17 @@ +#!/usr/bin/env python +from waflib.extras import autowaf as autowaf + +def build(bld): + obj = bld(features = 'cxx cxxshlib') + obj.source = ''' + ClientModel.cpp + ClientObject.cpp + ''' + obj.export_includes = ['.'] + obj.includes = ['.', '..', '../..'] + obj.name = 'libmachina_client' + obj.target = 'machina_client' + obj.use = 'libmachina_engine' + autowaf.use_lib(bld, obj, 'GLIBMM GTKMM RAUL LV2') + + bld.add_post_fun(autowaf.run_ldconfig) |