aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llappviewerlinux_api_dbus.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-12-01 17:39:58 -0600
committerJacek Antonelli2008-12-01 17:40:06 -0600
commit7abecb48babe6a6f09bf6692ba55076546cfced9 (patch)
tree8d18a88513fb97adf32c10aae78f4be1984942db /linden/indra/newview/llappviewerlinux_api_dbus.cpp
parentSecond Life viewer sources 1.21.6 (diff)
downloadmeta-impy-7abecb48babe6a6f09bf6692ba55076546cfced9.zip
meta-impy-7abecb48babe6a6f09bf6692ba55076546cfced9.tar.gz
meta-impy-7abecb48babe6a6f09bf6692ba55076546cfced9.tar.bz2
meta-impy-7abecb48babe6a6f09bf6692ba55076546cfced9.tar.xz
Second Life viewer sources 1.22.0-RC
Diffstat (limited to 'linden/indra/newview/llappviewerlinux_api_dbus.cpp')
-rw-r--r--linden/indra/newview/llappviewerlinux_api_dbus.cpp131
1 files changed, 131 insertions, 0 deletions
diff --git a/linden/indra/newview/llappviewerlinux_api_dbus.cpp b/linden/indra/newview/llappviewerlinux_api_dbus.cpp
new file mode 100644
index 0000000..806714f
--- /dev/null
+++ b/linden/indra/newview/llappviewerlinux_api_dbus.cpp
@@ -0,0 +1,131 @@
1/**
2 * @file llappviewerlinux_api_dbus.cpp
3 * @brief dynamic DBus symbol-grabbing code
4 *
5 * $LicenseInfo:firstyear=2008&license=viewergpl$
6 *
7 * Copyright (c) 2008, Linden Research, Inc.
8 *
9 * Second Life Viewer Source Code
10 * The source code in this file ("Source Code") is provided by Linden Lab
11 * to you under the terms of the GNU General Public License, version 2.0
12 * ("GPL"), unless you have obtained a separate licensing agreement
13 * ("Other License"), formally executed by you and Linden Lab. Terms of
14 * the GPL can be found in doc/GPL-license.txt in this distribution, or
15 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
16 *
17 * There are special exceptions to the terms and conditions of the GPL as
18 * it is applied to this Source Code. View the full text of the exception
19 * in the file doc/FLOSS-exception.txt in this software distribution, or
20 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
21 *
22 * By copying, modifying or distributing this software, you acknowledge
23 * that you have read and understood your obligations described above,
24 * and agree to abide by those obligations.
25 *
26 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
27 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
28 * COMPLETENESS OR PERFORMANCE.
29 * $/LicenseInfo$
30 */
31
32#if LL_DBUS_ENABLED
33
34#include "linden_common.h"
35
36extern "C" {
37#include <dbus/dbus-glib.h>
38
39#include "apr_pools.h"
40#include "apr_dso.h"
41}
42
43#define DEBUGMSG(...) lldebugs << llformat(__VA_ARGS__) << llendl
44#define INFOMSG(...) llinfos << llformat(__VA_ARGS__) << llendl
45#define WARNMSG(...) llwarns << llformat(__VA_ARGS__) << llendl
46
47#define LL_DBUS_SYM(REQUIRED, DBUSSYM, RTN, ...) RTN (*ll##DBUSSYM)(__VA_ARGS__) = NULL
48#include "llappviewerlinux_api_dbus_syms_raw.inc"
49#undef LL_DBUS_SYM
50
51static bool sSymsGrabbed = false;
52static apr_pool_t *sSymDBUSDSOMemoryPool = NULL;
53static apr_dso_handle_t *sSymDBUSDSOHandleG = NULL;
54
55bool grab_dbus_syms(std::string dbus_dso_name)
56{
57 if (sSymsGrabbed)
58 {
59 // already have grabbed good syms
60 return TRUE;
61 }
62
63 bool sym_error = false;
64 bool rtn = false;
65 apr_status_t rv;
66 apr_dso_handle_t *sSymDBUSDSOHandle = NULL;
67
68#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)
69
70 //attempt to load the shared library
71 apr_pool_create(&sSymDBUSDSOMemoryPool, NULL);
72
73 if ( APR_SUCCESS == (rv = apr_dso_load(&sSymDBUSDSOHandle,
74 dbus_dso_name.c_str(),
75 sSymDBUSDSOMemoryPool) ))
76 {
77 INFOMSG("Found DSO: %s", dbus_dso_name.c_str());
78
79#include "llappviewerlinux_api_dbus_syms_raw.inc"
80
81 if ( sSymDBUSDSOHandle )
82 {
83 sSymDBUSDSOHandleG = sSymDBUSDSOHandle;
84 sSymDBUSDSOHandle = NULL;
85 }
86
87 rtn = !sym_error;
88 }
89 else
90 {
91 INFOMSG("Couldn't load DSO: %s", dbus_dso_name.c_str());
92 rtn = false; // failure
93 }
94
95 if (sym_error)
96 {
97 WARNMSG("Failed to find necessary symbols in DBUS-GLIB libraries.");
98 }
99#undef LL_DBUS_SYM
100
101 sSymsGrabbed = rtn;
102 return rtn;
103}
104
105
106void ungrab_dbus_syms()
107{
108 // should be safe to call regardless of whether we've
109 // actually grabbed syms.
110
111 if ( sSymDBUSDSOHandleG )
112 {
113 apr_dso_unload(sSymDBUSDSOHandleG);
114 sSymDBUSDSOHandleG = NULL;
115 }
116
117 if ( sSymDBUSDSOMemoryPool )
118 {
119 apr_pool_destroy(sSymDBUSDSOMemoryPool);
120 sSymDBUSDSOMemoryPool = NULL;
121 }
122
123 // NULL-out all of the symbols we'd grabbed
124#define LL_DBUS_SYM(REQUIRED, DBUSSYM, RTN, ...) do{ll##DBUSSYM = NULL;}while(0)
125#include "llappviewerlinux_api_dbus_syms_raw.inc"
126#undef LL_DBUS_SYM
127
128 sSymsGrabbed = false;
129}
130
131#endif // LL_DBUS_ENABLED