Skip to content

Commit

Permalink
Mac OS X: Working on plugin loading
Browse files Browse the repository at this point in the history
Further renamed audio plugins by adding the prefix "audio_" so that
the automatic loader can skip those.
  • Loading branch information
skyjake committed Oct 15, 2012
1 parent 5fe32b1 commit cf26a48
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 46 deletions.
6 changes: 3 additions & 3 deletions doomsday/engine/portable/include/library.h
Expand Up @@ -66,14 +66,14 @@ void Library_ReleaseGames(void);
* returns a non-zero value to indicate aborting the iteration at some point,
* that value is returned instead.
*/
int Library_IterateAvailableLibraries(int (*func)(const char* fileName, void* data), void* data);
int Library_IterateAvailableLibraries(int (*func)(const char* fileName, const char* absPath, void* data), void* data);

/**
* Loads a dynamic library.
*
* @param fileName Name of the library to open.
* @param filePath Absolute native path of the library to open.
*/
Library* Library_New(const char* fileName);
Library* Library_New(const char* filePath);

void Library_Delete(Library* lib);

Expand Down
48 changes: 27 additions & 21 deletions doomsday/engine/portable/src/library.cpp
Expand Up @@ -57,13 +57,16 @@ struct library_s {
boolean isGamePlugin;
};

/*
#ifdef UNIX
static filename_t appDir; /// @todo Use ddstring_t
#endif
*/

static ddstring_t* lastError;
static Library* loadedLibs[MAX_LIBRARIES];

/*
#ifdef UNIX
static void getBundlePath(char* path, size_t len)
{
Expand All @@ -79,13 +82,6 @@ static void getBundlePath(char* path, size_t len)
return;
}
/*
#ifdef MACOSX
// This is the default location where bundles are.
dd_snprintf(path, len, "%s/Bundles", appDir);
#endif
*/

#ifdef UNIX
# ifdef DENG_LIBRARY_DIR
strncpy(path, DENG_LIBRARY_DIR, len);
Expand All @@ -99,6 +95,7 @@ static void getBundlePath(char* path, size_t len)
#endif
}
#endif
*/

static void addToLoaded(Library* lib)
{
Expand Down Expand Up @@ -131,12 +128,14 @@ static void removeFromLoaded(Library* lib)
void Library_Init(void)
{
lastError = Str_NewStd();
/*
#ifdef UNIX
if(!getcwd(appDir, sizeof(appDir)))
{
strcpy(appDir, "");
}
#endif
*/
}

void Library_Shutdown(void)
Expand Down Expand Up @@ -182,10 +181,11 @@ static void reopenLibraryIfNeeded(Library* lib)
}
#endif

Library* Library_New(const char *fileName)
Library* Library_New(const char *filePath)
{
Library* lib = 0;
handle_t handle = 0;
/*
#ifdef UNIX
filename_t bundlePath; /// @todo Use ddstring_t
#ifdef MACOSX
Expand Down Expand Up @@ -214,24 +214,27 @@ Library* Library_New(const char *fileName)
if(NULL != (ptr = strrchr(bundlePath, '.')))
*ptr = '\0';
#endif
*/

Str_Clear(lastError);

handle = dlopen(bundlePath, RTLD_NOW);
#ifdef UNIX
LOG_INFO("Trying to dlopen: ") << filePath;
handle = dlopen(filePath, RTLD_NOW);
if(!handle)
{
Str_Set(lastError, dlerror());
printf("Library_New: Error opening \"%s\" (%s).\n", bundlePath, Library_LastError());
printf("Library_New: Error opening \"%s\" (%s).\n", filePath, Library_LastError());
return 0;
}
#endif

#ifdef WIN32
Str_Clear(lastError);
handle = LoadLibrary(WIN_STRING(fileName));
handle = LoadLibrary(WIN_STRING(filePath));
if(!handle)
{
Str_Set(lastError, DD_Win32_GetLastErrorMessage());
printf("Library_New: Error opening \"%s\" (%s).\n", fileName, Library_LastError());
printf("Library_New: Error opening \"%s\" (%s).\n", filePath, Library_LastError());
return 0;
}
#endif
Expand All @@ -241,17 +244,18 @@ Library* Library_New(const char *fileName)
lib->handle = handle;
lib->path = Str_NewStd();
#ifdef UNIX
Str_Set(lib->path, bundlePath);
Str_Set(lib->path, filePath);
#endif
#ifdef WIN32
Str_Set(lib->path, fileName);
Str_Set(lib->path, filePath);
#endif

addToLoaded(lib);

// Symbols from game plugins conflict with each other, so we have to
// keep track of them.
/// @todo Needs a more generic way to detect the type of plugin.
/// @todo Needs a more generic way to detect the type of plugin
/// (see de::Library in libdeng2).
if(Library_Symbol(lib, "G_RegisterGames"))
{
lib->isGamePlugin = true;
Expand Down Expand Up @@ -335,17 +339,19 @@ static boolean isPossiblyLibraryFile(const char* path, const struct dirent* entr
#endif
*/

int Library_IterateAvailableLibraries(int (*func)(const char *, void *), void *data)
int Library_IterateAvailableLibraries(int (*func)(const char*, const char *, void *), void *data)
{
const de::FS::Index& libs = DENG2_APP->fileSystem().indexFor(DENG2_TYPE_NAME(de::LibraryFile));

DENG2_FOR_EACH_CONST(de::FS::Index, i, libs)
{
const de::NativeFile* native = dynamic_cast<const de::NativeFile*>(i->second);
if(native)
// For now we are not using libdeng2 to actually load the library.
de::LibraryFile* lib = static_cast<de::LibraryFile*>(i->second);
const de::NativeFile* src = dynamic_cast<const de::NativeFile*>(lib->source());
if(src)
{
QByteArray nativePath = native->nativePath().toUtf8();
int result = func(nativePath.constData(), data);
int result = func(src->name().toUtf8().constData(),
src->nativePath().toUtf8().constData(), data);
if(result) return result;
}
}
Expand Down
20 changes: 18 additions & 2 deletions doomsday/engine/unix/src/dd_uinit.c
Expand Up @@ -81,6 +81,7 @@ application_t app;

// CODE --------------------------------------------------------------------

/// @todo Assigning IDs to the libs should be handled in the plugin module.
static PluginHandle* findFirstUnusedPluginHandle(application_t* app)
{
int i;
Expand All @@ -93,14 +94,22 @@ static PluginHandle* findFirstUnusedPluginHandle(application_t* app)
return 0;
}

static int loadPlugin(application_t* app, const char* pluginPath, void* paramaters)
static int loadPlugin(const char* fileName, const char* pluginPath, void* param)
{
application_t* app = (application_t*) param;
Library* plugin;
PluginHandle* handle;
void (*initializer)(void);
filename_t name;

assert(app && pluginPath && pluginPath[0]);

if(!strncmp(fileName, "audio_", 6))
{
// The audio plugins are loaded later on demand by AudioDriver.
return false;
}

plugin = Library_New(pluginPath);
if(!plugin)
{
Expand Down Expand Up @@ -139,8 +148,9 @@ static int loadPlugin(application_t* app, const char* pluginPath, void* paramate
return 0; // Continue iteration.
}

#if 0
typedef struct {
boolean loadingGames;
//boolean loadingGames;
application_t* app;
} loadpluginparamaters_t;

Expand Down Expand Up @@ -168,6 +178,7 @@ static int loadPluginWorker(const char* pluginPath, void* data)
}
return 0; // Continue search.
}
#endif

static boolean unloadPlugin(PluginHandle* handle)
{
Expand All @@ -189,6 +200,9 @@ static boolean loadAllPlugins(application_t* app)

Con_Message("Initializing plugins...\n");

Library_IterateAvailableLibraries(loadPlugin, app);

/*
// Try to load all libraries that begin with libj.
{ loadpluginparamaters_t params;
params.app = app;
Expand All @@ -202,6 +216,8 @@ static boolean loadAllPlugins(application_t* app)
params.loadingGames = false;
Library_IterateAvailableLibraries(loadPluginWorker, &params);
}
*/

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/directsound/directsound.pro
Expand Up @@ -11,7 +11,7 @@ include(../../dep_eax.pri)
}

TEMPLATE = lib
TARGET = directsound
TARGET = audio_directsound
VERSION = $$DIRECTSOUND_VERSION

HEADERS += include/version.h
Expand Down
6 changes: 3 additions & 3 deletions doomsday/plugins/fluidsynth/fluidsynth.pro
Expand Up @@ -5,7 +5,7 @@ include(../config_plugin.pri)
include(../../dep_glib.pri)

TEMPLATE = lib
TARGET = fluidsynth
TARGET = audio_fluidsynth

CONFIG -= qt

Expand All @@ -26,8 +26,8 @@ win32 {
target.path = $$DENG_LIB_DIR
}
macx {
linkToBundledLibdeng2(fluidsynth)
linkToBundledLibdeng(fluidsynth)
linkToBundledLibdeng2(audio_fluidsynth)
linkToBundledLibdeng(audio_fluidsynth)
}
unix:!macx {
INSTALLS += target
Expand Down
12 changes: 6 additions & 6 deletions doomsday/plugins/fmod/fmod.pro
Expand Up @@ -5,7 +5,7 @@ include(../config_plugin.pri)
include(../../dep_fmod.pri)

TEMPLATE = lib
TARGET = fmod
TARGET = audio_fmod
VERSION = $$FMOD_VERSION

deng_debug: DEFINES += DENG_DSFMOD_DEBUG
Expand Down Expand Up @@ -38,17 +38,17 @@ win32 {
}
else:macx {
# Bundle the FMOD shared library in dsFMOD.bundle.
doPostLink("cp -f \"$$FMOD_DIR/api/lib/libfmodex.dylib\" dsFMOD.bundle/")
doPostLink("install_name_tool -id @executable_path/../../../dsFMOD.bundle/libfmodex.dylib dsFMOD.bundle/libfmodex.dylib")
doPostLink("install_name_tool -change ./libfmodex.dylib @executable_path/../../../dsFMOD.bundle/libfmodex.dylib dsFMOD.bundle/dsfmod")
doPostLink("cp -f \"$$FMOD_DIR/api/lib/libfmodex.dylib\" audio_fmod.bundle/")
doPostLink("install_name_tool -id @executable_path/../../../audio_fmod.bundle/libfmodex.dylib audio_fmod.bundle/libfmodex.dylib")
doPostLink("install_name_tool -change ./libfmodex.dylib @executable_path/../../../audio_fmod.bundle/libfmodex.dylib audio_fmod.bundle/audio_fmod")
}
else {
INSTALLS += target
target.path = $$DENG_LIB_DIR
}

macx {
linkToBundledLibdeng2(fmod)
linkToBundledLibdeng(fmod)
linkToBundledLibdeng2(audio_fmod)
linkToBundledLibdeng(audio_fmod)
}

6 changes: 3 additions & 3 deletions doomsday/plugins/openal/openal.pro
Expand Up @@ -6,7 +6,7 @@ include(../config_plugin.pri)
include(../../dep_openal.pri)

TEMPLATE = lib
TARGET = openal
TARGET = audio_openal
VERSION = $$OPENAL_VERSION

#DEFINES += DENG_DSOPENAL_DEBUG
Expand All @@ -30,7 +30,7 @@ win32 {
}

macx {
linkToBundledLibdeng2(openal)
linkToBundledLibdeng(openal)
linkToBundledLibdeng2(audio_openal)
linkToBundledLibdeng(audio_openal)
}

2 changes: 1 addition & 1 deletion doomsday/plugins/winmm/winmm.pro
Expand Up @@ -9,7 +9,7 @@ include(../config_plugin.pri)
}

TEMPLATE = lib
TARGET = winmm
TARGET = audio_winmm
VERSION = $$WINMM_VERSION

INCLUDEPATH += include
Expand Down
12 changes: 6 additions & 6 deletions doomsday/postbuild/bundleapp.sh
Expand Up @@ -28,17 +28,17 @@ $CP plugins/jdoom/doom.bundle $PLUGDIR/
$CP plugins/jheretic/heretic.bundle $PLUGDIR/
$CP plugins/jhexen/hexen.bundle $PLUGDIR/
$CP plugins/jdoom64/doom64.bundle $PLUGDIR/
$CP plugins/fmod/fmod.bundle $PLUGDIR/
$CP plugins/fmod/audio_fmod.bundle $PLUGDIR/

# Tools
#$CP $SRCDIR/../tools/wadtool/wadtool $APPDIR/Resources
$CP $SRCDIR/../tools/texc/texc $APPDIR/Resources
$CP $SRCDIR/../tools/md2tool/md2tool $APPDIR/Resources

if [ -e plugins/fluidsynth/dsFluidSynth.bundle ]; then
$CP plugins/fluidsynth/dsFluidSynth.bundle $BUILDDIR/dsFluidSynth.bundle
if [ -e plugins/fluidsynth/audio_fluidsynth.bundle ]; then
$CP plugins/fluidsynth/audio_fluidsynth.bundle $PLUGDIR/

echo "Installing deps for dsFluidSynth..."
echo "Installing deps for audio_fluidsynth..."
FWDIR=$BUILDDIR/Doomsday.app/Contents/Frameworks
cp /usr/local/lib/libglib-2.0.0.dylib $FWDIR
cp /usr/local/lib/libgthread-2.0.0.dylib $FWDIR
Expand All @@ -60,8 +60,8 @@ if [ -e plugins/fluidsynth/dsFluidSynth.bundle ]; then
install_name_tool -change /usr/local/Cellar/gettext/0.18.1.1/lib/libintl.8.dylib \
@executable_path/../Frameworks/libintl.8.dylib $FWDIR/libgthread-2.0.0.dylib

# dsFluidSynth
DSFS=$BUILDDIR/dsFluidSynth.bundle/dsFluidSynth
# audio_fluidsynth
DSFS=$PLUGDIR/audio_fluidsynth.bundle/audio_fluidsynth
install_name_tool -change /usr/local/lib/libglib-2.0.0.dylib \
@executable_path/../Frameworks/libglib-2.0.0.dylib $DSFS
install_name_tool -change /usr/local/lib/libgthread-2.0.0.dylib \
Expand Down

0 comments on commit cf26a48

Please sign in to comment.