1 /* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "nsThreadUtils.h"
9 #include "mozilla/ArrayUtils.h"
11 namespace mozilla::widget
{
13 #define FUNC(name, type, params) \
14 DBusMenuFunctions::_##name##_fn DBusMenuFunctions::s_##name;
15 DBUSMENU_GLIB_FUNCTIONS
16 DBUSMENU_GTK_FUNCTIONS
19 static PRLibrary
* gDbusmenuGlib
= nullptr;
20 static PRLibrary
* gDbusmenuGtk
= nullptr;
22 using DBusMenuFunc
= void (*)();
23 struct DBusMenuDynamicFunction
{
24 const char* functionName
;
25 DBusMenuFunc
* function
;
28 static bool sInitialized
;
29 static bool sLibPresent
;
31 /* static */ bool DBusMenuFunctions::Init() {
32 MOZ_ASSERT(NS_IsMainThread());
37 #define FUNC(name, type, params) \
38 {#name, (DBusMenuFunc*)&DBusMenuFunctions::s_##name},
39 static const DBusMenuDynamicFunction kDbusmenuGlibSymbols
[] = {
40 DBUSMENU_GLIB_FUNCTIONS
};
41 static const DBusMenuDynamicFunction kDbusmenuGtkSymbols
[] = {
42 DBUSMENU_GTK_FUNCTIONS
};
44 #define LOAD_LIBRARY(symbol, name) \
46 g##symbol = PR_LoadLibrary(name); \
51 for (uint32_t i = 0; i < mozilla::ArrayLength(k##symbol##Symbols); ++i) { \
52 *k##symbol##Symbols[i].function = \
53 PR_FindFunctionSymbol(g##symbol, k##symbol##Symbols[i].functionName); \
54 if (!*k##symbol##Symbols[i].function) { \
59 LOAD_LIBRARY(DbusmenuGlib
, "libdbusmenu-glib.so.4")
60 LOAD_LIBRARY(DbusmenuGtk
, "libdbusmenu-gtk3.so.4")
67 } // namespace mozilla::widget