PageRenderTime 157ms CodeModel.GetById 8ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1
  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. #if LL_DBUS_ENABLED
  27. #include "linden_common.h"
  28. extern "C" {
  29. #include <dbus/dbus-glib.h>
  30. #include "apr_pools.h"
  31. #include "apr_dso.h"
  32. }
  33. #define DEBUGMSG(...) do { lldebugs << llformat(__VA_ARGS__) << llendl; } while(0)
  34. #define INFOMSG(...) do { llinfos << llformat(__VA_ARGS__) << llendl; } while(0)
  35. #define WARNMSG(...) do { llwarns << llformat(__VA_ARGS__) << llendl; } while(0)
  36. #define LL_DBUS_SYM(REQUIRED, DBUSSYM, RTN, ...) RTN (*ll##DBUSSYM)(__VA_ARGS__) = NULL
  37. #include "llappviewerlinux_api_dbus_syms_raw.inc"
  38. #undef LL_DBUS_SYM
  39. static bool sSymsGrabbed = false;
  40. static apr_pool_t *sSymDBUSDSOMemoryPool = NULL;
  41. static apr_dso_handle_t *sSymDBUSDSOHandleG = NULL;
  42. bool grab_dbus_syms(std::string dbus_dso_name)
  43. {
  44. if (sSymsGrabbed)
  45. {
  46. // already have grabbed good syms
  47. return TRUE;
  48. }
  49. bool sym_error = false;
  50. bool rtn = false;
  51. apr_status_t rv;
  52. apr_dso_handle_t *sSymDBUSDSOHandle = NULL;
  53. #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)
  54. //attempt to load the shared library
  55. apr_pool_create(&sSymDBUSDSOMemoryPool, NULL);
  56. if ( APR_SUCCESS == (rv = apr_dso_load(&sSymDBUSDSOHandle,
  57. dbus_dso_name.c_str(),
  58. sSymDBUSDSOMemoryPool) ))
  59. {
  60. INFOMSG("Found DSO: %s", dbus_dso_name.c_str());
  61. #include "llappviewerlinux_api_dbus_syms_raw.inc"
  62. if ( sSymDBUSDSOHandle )
  63. {
  64. sSymDBUSDSOHandleG = sSymDBUSDSOHandle;
  65. sSymDBUSDSOHandle = NULL;
  66. }
  67. rtn = !sym_error;
  68. }
  69. else
  70. {
  71. INFOMSG("Couldn't load DSO: %s", dbus_dso_name.c_str());
  72. rtn = false; // failure
  73. }
  74. if (sym_error)
  75. {
  76. WARNMSG("Failed to find necessary symbols in DBUS-GLIB libraries.");
  77. }
  78. #undef LL_DBUS_SYM
  79. sSymsGrabbed = rtn;
  80. return rtn;
  81. }
  82. void ungrab_dbus_syms()
  83. {
  84. // should be safe to call regardless of whether we've
  85. // actually grabbed syms.
  86. if ( sSymDBUSDSOHandleG )
  87. {
  88. apr_dso_unload(sSymDBUSDSOHandleG);
  89. sSymDBUSDSOHandleG = NULL;
  90. }
  91. if ( sSymDBUSDSOMemoryPool )
  92. {
  93. apr_pool_destroy(sSymDBUSDSOMemoryPool);
  94. sSymDBUSDSOMemoryPool = NULL;
  95. }
  96. // NULL-out all of the symbols we'd grabbed
  97. #define LL_DBUS_SYM(REQUIRED, DBUSSYM, RTN, ...) do{ll##DBUSSYM = NULL;}while(0)
  98. #include "llappviewerlinux_api_dbus_syms_raw.inc"
  99. #undef LL_DBUS_SYM
  100. sSymsGrabbed = false;
  101. }
  102. #endif // LL_DBUS_ENABLED