xdg_desktop_portal_utils.h (4589B)
1 /* 2 * Copyright 2022 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef MODULES_PORTAL_XDG_DESKTOP_PORTAL_UTILS_H_ 12 #define MODULES_PORTAL_XDG_DESKTOP_PORTAL_UTILS_H_ 13 14 #include <gio/gio.h> 15 16 #include <cstdint> 17 #include <string> 18 19 #include "absl/strings/string_view.h" 20 #include "modules/portal/portal_request_response.h" 21 #include "rtc_base/system/rtc_export.h" 22 23 namespace webrtc { 24 namespace xdg_portal { 25 26 constexpr char kDesktopBusName[] = "org.freedesktop.portal.Desktop"; 27 constexpr char kDesktopObjectPath[] = "/org/freedesktop/portal/desktop"; 28 constexpr char kDesktopRequestObjectPath[] = 29 "/org/freedesktop/portal/desktop/request"; 30 constexpr char kSessionInterfaceName[] = "org.freedesktop.portal.Session"; 31 constexpr char kRequestInterfaceName[] = "org.freedesktop.portal.Request"; 32 constexpr char kScreenCastInterfaceName[] = "org.freedesktop.portal.ScreenCast"; 33 34 using ProxyRequestCallback = void (*)(GObject*, GAsyncResult*, gpointer); 35 using SessionRequestCallback = void (*)(GDBusProxy*, GAsyncResult*, gpointer); 36 using SessionRequestResponseSignalHandler = void (*)(GDBusConnection*, 37 const char*, 38 const char*, 39 const char*, 40 const char*, 41 GVariant*, 42 gpointer); 43 using StartRequestResponseSignalHandler = void (*)(GDBusConnection*, 44 const char*, 45 const char*, 46 const char*, 47 const char*, 48 GVariant*, 49 gpointer); 50 using SessionStartRequestedHandler = void (*)(GDBusProxy*, 51 GAsyncResult*, 52 gpointer); 53 54 RTC_EXPORT std::string RequestResponseToString(RequestResponse request); 55 56 RequestResponse RequestResponseFromPortalResponse(uint32_t portal_response); 57 58 // Returns a string path for signal handle based on the provided connection and 59 // token. 60 RTC_EXPORT std::string PrepareSignalHandle(absl::string_view token, 61 GDBusConnection* connection); 62 63 // Sets up the callback to execute when a response signal is received for the 64 // given object. 65 RTC_EXPORT uint32_t 66 SetupRequestResponseSignal(absl::string_view object_path, 67 const GDBusSignalCallback callback, 68 gpointer user_data, 69 GDBusConnection* connection); 70 71 RTC_EXPORT void RequestSessionProxy( 72 absl::string_view interface_name, 73 const ProxyRequestCallback proxy_request_callback, 74 GCancellable* cancellable, 75 gpointer user_data); 76 77 RTC_EXPORT void SetupSessionRequestHandlers( 78 absl::string_view portal_prefix, 79 const SessionRequestCallback session_request_callback, 80 const SessionRequestResponseSignalHandler request_response_signale_handler, 81 GDBusConnection* connection, 82 GDBusProxy* proxy, 83 GCancellable* cancellable, 84 std::string& portal_handle, 85 guint& session_request_signal_id, 86 gpointer user_data); 87 88 RTC_EXPORT void StartSessionRequest( 89 absl::string_view prefix, 90 absl::string_view session_handle, 91 const StartRequestResponseSignalHandler signal_handler, 92 const SessionStartRequestedHandler session_started_handler, 93 GDBusProxy* proxy, 94 GDBusConnection* connection, 95 GCancellable* cancellable, 96 guint& start_request_signal_id, 97 std::string& start_handle, 98 gpointer user_data); 99 100 // Tears down the portal session and cleans up related objects. 101 RTC_EXPORT void TearDownSession(absl::string_view session_handle, 102 GDBusProxy* proxy, 103 GCancellable* cancellable, 104 GDBusConnection* connection); 105 106 } // namespace xdg_portal 107 } // namespace webrtc 108 109 #endif // MODULES_PORTAL_XDG_DESKTOP_PORTAL_UTILS_H_