From 93850c202de8b073a1ce1dd8bd246d407bce4e2f Mon Sep 17 00:00:00 2001
From: David Robillard <d@drobilla.net>
Date: Tue, 30 Sep 2008 16:50:21 +0000
Subject: Flatten ingen source directory heirarchy a bit.

git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@1551 a436a847-0d15-0410-975c-d299462d15a1
---
 src/module/Makefile.am | 22 ++++++++++++
 src/module/Module.cpp  | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/module/Module.hpp  | 35 ++++++++++++++++++++
 src/module/World.hpp   | 78 +++++++++++++++++++++++++++++++++++++++++++
 src/module/global.cpp  | 74 +++++++++++++++++++++++++++++++++++++++++
 src/module/global.hpp  | 33 ++++++++++++++++++
 src/module/wscript     | 17 ++++++++++
 7 files changed, 349 insertions(+)
 create mode 100644 src/module/Makefile.am
 create mode 100644 src/module/Module.cpp
 create mode 100644 src/module/Module.hpp
 create mode 100644 src/module/World.hpp
 create mode 100644 src/module/global.cpp
 create mode 100644 src/module/global.hpp
 create mode 100644 src/module/wscript

(limited to 'src/module')

diff --git a/src/module/Makefile.am b/src/module/Makefile.am
new file mode 100644
index 00000000..84d499e4
--- /dev/null
+++ b/src/module/Makefile.am
@@ -0,0 +1,22 @@
+noinst_LTLIBRARIES = libingen_module.la
+
+libingen_module_la_CXXFLAGS = \
+	@INGEN_CFLAGS@ \
+	@GLIBMM_CFLAGS@ \
+	@REDLANDMM_CFLAGS@ \
+	@RAUL_CFLAGS@ \
+	@SLV2_CFLAGS@ \
+	-DINGEN_MODULE_DIR=\"$(libdir)/ingen\"
+
+libingen_module_la_LIBADD = \
+	@GLIBMM_LIBS@ \
+	@REDLANDMM_LIBS@ \
+	@RAUL_LIBS@ \
+	@SLV2_LIBS@
+
+libingen_module_la_SOURCES = \
+	global.hpp \
+	global.cpp \
+	World.hpp \
+	Module.hpp \
+	Module.cpp
diff --git a/src/module/Module.cpp b/src/module/Module.cpp
new file mode 100644
index 00000000..8d1399b1
--- /dev/null
+++ b/src/module/Module.cpp
@@ -0,0 +1,90 @@
+/* This file is part of Ingen.
+ * Copyright (C) 2007 Dave 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
+ */
+
+#include <string>
+#include <sstream>
+#include <iostream>
+#include <glibmm/module.h>
+#include <glibmm/miscutils.h>
+#include <glibmm/fileutils.h>
+#include <raul/SharedPtr.hpp>
+
+#ifndef INGEN_MODULE_DIR
+#error This file expects INGEN_MODULE_DIR to be defined.
+#endif
+
+using namespace std;
+
+namespace Ingen {
+namespace Shared {
+
+
+/** Load a dynamic module from the default path.
+ *
+ * This will check in the directories specified in the environment variable
+ * INGEN_MODULE_PATH (typical colon delimited format), then the default module
+ * installation directory (ie /usr/local/lib/ingen), in that order.
+ *
+ * \param name The base name of the module, e.g. "ingen_serialisation"
+ */
+SharedPtr<Glib::Module>
+load_module(const string& name)
+{
+	Glib::Module* module = NULL;
+
+	// Search INGEN_MODULE_PATH first
+	bool module_path_found;
+	string module_path = Glib::getenv("INGEN_MODULE_PATH", module_path_found);
+	if (module_path_found) {
+		string dir;
+		istringstream iss(module_path);
+		while (getline(iss, dir, ':')) {
+			
+			string filename = Glib::Module::build_path(dir, name);
+			if (Glib::file_test(filename, Glib::FILE_TEST_EXISTS)) {
+				module = new Glib::Module(filename, Glib::MODULE_BIND_LAZY);
+
+				if (*module) {
+					cerr << "Loaded module \"" <<  name << "\" from " << filename << endl;
+					return SharedPtr<Glib::Module>(module);
+				} else {
+					delete module;
+					cerr << Glib::Module::get_last_error() << endl;
+				}
+			}
+		}
+	}
+
+	// Try default directory if not found
+	module = new Glib::Module(
+			Glib::Module::build_path(INGEN_MODULE_DIR, name),
+            Glib::MODULE_BIND_LAZY);
+
+	if (*module) {
+		cerr << "Loaded module \"" <<  name << "\" from " << INGEN_MODULE_DIR << endl;
+		return SharedPtr<Glib::Module>(module);
+	} else {
+		cerr << "Unable to load module \"" <<  name << "\", is Ingen installed?" << endl
+			<< "Use ./ingen.dev to run from the source tree." << endl;
+		return SharedPtr<Glib::Module>();
+	}
+}
+
+
+} // namespace Shared
+} // namespace Ingen
+
diff --git a/src/module/Module.hpp b/src/module/Module.hpp
new file mode 100644
index 00000000..2d9ba382
--- /dev/null
+++ b/src/module/Module.hpp
@@ -0,0 +1,35 @@
+/* This file is part of Ingen.
+ * Copyright (C) 2007 Dave 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
+ */
+
+#include <string>
+#include <glibmm/module.h>
+#include <raul/SharedPtr.hpp>
+
+namespace Ingen {
+namespace Shared {
+
+
+/** Load a dynamic module from the default path.
+ *
+ * \param name The base name of the module, e.g. "ingen_serialisation"
+ */
+SharedPtr<Glib::Module> load_module(const std::string& name);
+
+
+} // namespace Shared
+} // namespace Ingen
+
diff --git a/src/module/World.hpp b/src/module/World.hpp
new file mode 100644
index 00000000..dbbac2bd
--- /dev/null
+++ b/src/module/World.hpp
@@ -0,0 +1,78 @@
+/* This file is part of Ingen.
+ * Copyright (C) 2007 Dave 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_WORLD_HPP
+#define INGEN_WORLD_HPP
+
+#include CONFIG_H_PATH
+
+#include <string>
+#include <glibmm/module.h>
+#include <raul/SharedPtr.hpp>
+#include "shared/LV2Features.hpp"
+
+#ifdef HAVE_SLV2
+#include <slv2/slv2.h>
+#endif
+
+namespace Redland { class World; }
+
+namespace Ingen {
+class Engine;
+
+namespace Serialisation { class Serialiser; class Parser; }
+using Serialisation::Serialiser;
+using Serialisation::Parser;
+
+namespace Shared {
+class EngineInterface;
+class Store;
+
+
+/** The "world" all Ingen modules may share.
+ *
+ * This is required for shared access to things like Redland, so locking can
+ * take place centrally and the engine/gui using the same library won't
+ * explode horribly.
+ *
+ * Hopefully at some point in the future it can allow some fun things like
+ * scripting bindings that play with all loaded components of
+ * The Ingen System(TM) and whatnot.
+ */
+struct World {
+#ifdef HAVE_SLV2
+	SLV2World    slv2_world;
+	LV2Features* lv2_features;
+#endif
+
+	Redland::World* rdf_world;
+
+    SharedPtr<EngineInterface> engine;
+    SharedPtr<Engine>          local_engine;
+    SharedPtr<Serialiser>      serialiser;
+    SharedPtr<Parser>          parser;
+    SharedPtr<Store>           store;
+	
+	SharedPtr<Glib::Module> serialisation_module;
+};
+
+
+} // namespace Shared
+} // namespace Ingen
+
+#endif // INGEN_WORLD_HPP
+
diff --git a/src/module/global.cpp b/src/module/global.cpp
new file mode 100644
index 00000000..c78f9fc3
--- /dev/null
+++ b/src/module/global.cpp
@@ -0,0 +1,74 @@
+/* This file is part of Ingen.
+ * Copyright (C) 2007 Dave 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
+ */
+
+#include <iostream>
+#include <redlandmm/World.hpp>
+#include "global.hpp"
+#include "World.hpp"
+
+#include CONFIG_H_PATH
+#ifdef HAVE_SLV2
+#include <slv2/slv2.h>
+#endif
+
+using namespace std;
+
+namespace Ingen {
+namespace Shared {
+
+static World* world = NULL;
+
+
+World*
+get_world()
+{
+    static World* world = NULL;
+
+	if (!world) {
+		world = new World();
+        world->rdf_world = new Redland::World();
+#ifdef HAVE_SLV2
+		world->slv2_world = slv2_world_new_using_rdf_world(world->rdf_world->world());
+		world->lv2_features = new LV2Features();
+		slv2_world_load_all(world->slv2_world);
+#endif
+		world->engine.reset();
+		world->local_engine.reset();
+	}
+
+	return world;
+}
+
+
+void
+destroy_world()
+{
+	if (world) {
+#ifdef HAVE_SLV2
+		slv2_world_free(world->slv2_world);
+		delete world->lv2_features;
+#endif
+        delete world->rdf_world;
+		delete world;
+		world = NULL;
+	}
+}
+
+
+} // namesace Shared
+} // namespace Ingen
+
diff --git a/src/module/global.hpp b/src/module/global.hpp
new file mode 100644
index 00000000..1aa46be6
--- /dev/null
+++ b/src/module/global.hpp
@@ -0,0 +1,33 @@
+/* This file is part of Ingen.
+ * Copyright (C) 2007 Dave 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_GLOBAL_H
+#define INGEN_GLOBAL_H
+
+namespace Ingen {
+namespace Shared {
+
+class World;
+
+World* get_world();
+void   destroy_world();
+
+} // namesace Shared
+} // namespace Ingen
+
+#endif // INGEN_GLOBAL_H
+
diff --git a/src/module/wscript b/src/module/wscript
new file mode 100644
index 00000000..e202342d
--- /dev/null
+++ b/src/module/wscript
@@ -0,0 +1,17 @@
+#!/usr/bin/env python
+import Params
+
+def build(bld):
+	dir = Params.g_options.moduledir or bld.env()['PREFIX'] + 'lib/ingen'
+	obj = bld.create_obj('cpp', 'shlib')
+	obj.source = '''
+		Module.cpp
+		global.cpp
+	'''
+	obj.includes = ['..', '../../common', '../..']
+	obj.defines  = 'INGEN_MODULE_DIR=\\\"' + dir + '\\\"'
+	obj.name     = 'libingen_module'
+	obj.target   = 'ingen_module'
+	obj.uselib   = 'GLIBMM SLV2 RAUL REDLANDMM'
+	obj.vnum     = '0.0.0'
+
-- 
cgit v1.2.1