VBoxXPCOMCGlue.c revision 4c6a62982e10f932ad80cd99f45f244e1b349273
/* $Revsion: $ */
/** @file
* Glue code for dynamically linking to VBoxXPCOMC.
*/
/*
* Copyright (C) 2009 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "VBoxXPCOMCGlue.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dlfcn.h>
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
# define DYNLIB_NAME "VBoxXPCOMC.so"
# define DYNLIB_NAME "VBoxXPCOMC.dylib"
# define DYNLIB_NAME "VBoxXPCOMC.dll"
#else
# error "Port me"
#endif
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** The dlopen handle for VBoxXPCOMC. */
void *g_hVBoxXPCOMC = NULL;
/** The last load error. */
char g_szVBoxErrMsg[256];
/** Pointer to the VBoxXPCOMC function table. */
/**
* Try load VBoxXPCOMC.so/dylib/dll from the specified location and resolve all
* the symbols we need.
*
* @returns 0 on success, -1 on failure.
* @param pszHome The director where to try load VBoxXPCOMC from. Can be NULL.
* @param pszMsgPrefix Error message prefix. NULL means no error messages.
*/
{
char * pszBuf;
int rc = -1;
/*
* Construct the full name.
*/
if (!pszBuf)
{
if (pszMsgPrefix)
return -1;
}
if (pszHome)
{
cchHome++;
}
/*
* Try load it by that name, setting the VBOX_APP_HOME first (for now).
* Then resolve and call the function table getter.
*/
if (g_hVBoxXPCOMC)
{
if (pfnGetFunctions)
{
if (g_pVBoxFuncs)
rc = 0;
else
}
else
}
else
return rc;
}
/**
* Tries to locate and load VBoxXPCOMC.so/dylib/dll, resolving all the related
* function pointers.
*
* @returns 0 on success, -1 on failure.
* @param pszMsgPrefix Error message prefix. NULL means no error messages.
*
* @remark This should be considered moved into a separate glue library since
* its its going to be pretty much the same for any user of VBoxXPCOMC
* and it will just cause trouble to have duplicate versions of this
* source code all around the place.
*/
int VBoxCGlueInit(const char *pszMsgPrefix)
{
/*
* If the user specifies the location, try only that.
*/
if (pszHome)
/*
* Try the known standard locations.
*/
#if defined(__gnu__linux__) || defined(__linux__)
return 0;
return 0;
return 0;
return 0;
return 0;
#else
# error "port me"
#endif
/*
* Finally try the dynamic linker search path.
*/
return 0;
/* No luck, return failure. */
if (pszMsgPrefix)
return -1;
}
/**
* Terminate the C glue library.
*/
void VBoxCGlueTerm(void)
{
/* later */
}