PageRenderTime 52ms CodeModel.GetById 20ms app.highlight 6ms RepoModel.GetById 24ms app.codeStats 0ms

/indra/newview/llappviewerlinux_api_dbus.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 126 lines | 72 code | 24 blank | 30 comment | 11 complexity | df99f3576b85507f1b0fd41de906c792 MD5 | raw file
  1/** 
  2 * @file llappviewerlinux_api_dbus.cpp
  3 * @brief dynamic DBus symbol-grabbing code
  4 *
  5 * $LicenseInfo:firstyear=2008&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#if LL_DBUS_ENABLED
 28
 29#include "linden_common.h"
 30
 31extern "C" {
 32#include <dbus/dbus-glib.h>
 33
 34#include "apr_pools.h"
 35#include "apr_dso.h"
 36}
 37
 38#define DEBUGMSG(...) do { lldebugs << llformat(__VA_ARGS__) << llendl; } while(0)
 39#define INFOMSG(...) do { llinfos << llformat(__VA_ARGS__) << llendl; } while(0)
 40#define WARNMSG(...) do { llwarns << llformat(__VA_ARGS__) << llendl; } while(0)
 41
 42#define LL_DBUS_SYM(REQUIRED, DBUSSYM, RTN, ...) RTN (*ll##DBUSSYM)(__VA_ARGS__) = NULL
 43#include "llappviewerlinux_api_dbus_syms_raw.inc"
 44#undef LL_DBUS_SYM
 45
 46static bool sSymsGrabbed = false;
 47static apr_pool_t *sSymDBUSDSOMemoryPool = NULL;
 48static apr_dso_handle_t *sSymDBUSDSOHandleG = NULL;
 49
 50bool grab_dbus_syms(std::string dbus_dso_name)
 51{
 52	if (sSymsGrabbed)
 53	{
 54		// already have grabbed good syms
 55		return TRUE;
 56	}
 57
 58	bool sym_error = false;
 59	bool rtn = false;
 60	apr_status_t rv;
 61	apr_dso_handle_t *sSymDBUSDSOHandle = NULL;
 62
 63#define LL_DBUS_SYM(REQUIRED, DBUSSYM, RTN, ...) do{rv = apr_dso_sym((apr_dso_handle_sym_t*)&ll##DBUSSYM, sSymDBUSDSOHandle, #DBUSSYM); if (rv != APR_SUCCESS) {INFOMSG("Failed to grab symbol: %s", #DBUSSYM); if (REQUIRED) sym_error = true;} else DEBUGMSG("grabbed symbol: %s from %p", #DBUSSYM, (void*)ll##DBUSSYM);}while(0)
 64
 65	//attempt to load the shared library
 66	apr_pool_create(&sSymDBUSDSOMemoryPool, NULL);
 67  
 68	if ( APR_SUCCESS == (rv = apr_dso_load(&sSymDBUSDSOHandle,
 69					       dbus_dso_name.c_str(),
 70					       sSymDBUSDSOMemoryPool) ))
 71	{
 72		INFOMSG("Found DSO: %s", dbus_dso_name.c_str());
 73
 74#include "llappviewerlinux_api_dbus_syms_raw.inc"
 75      
 76		if ( sSymDBUSDSOHandle )
 77		{
 78			sSymDBUSDSOHandleG = sSymDBUSDSOHandle;
 79			sSymDBUSDSOHandle = NULL;
 80		}
 81      
 82		rtn = !sym_error;
 83	}
 84	else
 85	{
 86		INFOMSG("Couldn't load DSO: %s", dbus_dso_name.c_str());
 87		rtn = false; // failure
 88	}
 89
 90	if (sym_error)
 91	{
 92		WARNMSG("Failed to find necessary symbols in DBUS-GLIB libraries.");
 93	}
 94#undef LL_DBUS_SYM
 95
 96	sSymsGrabbed = rtn;
 97	return rtn;
 98}
 99
100
101void ungrab_dbus_syms()
102{ 
103	// should be safe to call regardless of whether we've
104	// actually grabbed syms.
105
106	if ( sSymDBUSDSOHandleG )
107	{
108		apr_dso_unload(sSymDBUSDSOHandleG);
109		sSymDBUSDSOHandleG = NULL;
110	}
111	
112	if ( sSymDBUSDSOMemoryPool )
113	{
114		apr_pool_destroy(sSymDBUSDSOMemoryPool);
115		sSymDBUSDSOMemoryPool = NULL;
116	}
117	
118	// NULL-out all of the symbols we'd grabbed
119#define LL_DBUS_SYM(REQUIRED, DBUSSYM, RTN, ...) do{ll##DBUSSYM = NULL;}while(0)
120#include "llappviewerlinux_api_dbus_syms_raw.inc"
121#undef LL_DBUS_SYM
122
123	sSymsGrabbed = false;
124}
125
126#endif // LL_DBUS_ENABLED