Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / widget / gtk / DBusMenu.cpp
blob8672de40ef8df21f9a083a52d715f1fd08ad0afd
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/. */
6 #include "DBusMenu.h"
7 #include "prlink.h"
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
17 #undef FUNC
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());
33 if (sInitialized) {
34 return sLibPresent;
36 sInitialized = true;
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) \
45 if (!g##symbol) { \
46 g##symbol = PR_LoadLibrary(name); \
47 if (!g##symbol) { \
48 return false; \
49 } \
50 } \
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) { \
55 return false; \
56 } \
59 LOAD_LIBRARY(DbusmenuGlib, "libdbusmenu-glib.so.4")
60 LOAD_LIBRARY(DbusmenuGtk, "libdbusmenu-gtk3.so.4")
61 #undef LOAD_LIBRARY
63 sLibPresent = true;
64 return true;
67 } // namespace mozilla::widget