From 43a97878ce14b72f0981164f87f2e35e14151312 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:22:09 +0200 Subject: Adding upstream version 110.0.1. Signed-off-by: Daniel Baumann --- toolkit/components/uniffi-js/UniFFICallbacks.h | 75 ++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 toolkit/components/uniffi-js/UniFFICallbacks.h (limited to 'toolkit/components/uniffi-js/UniFFICallbacks.h') diff --git a/toolkit/components/uniffi-js/UniFFICallbacks.h b/toolkit/components/uniffi-js/UniFFICallbacks.h new file mode 100644 index 0000000000..34faeda6a2 --- /dev/null +++ b/toolkit/components/uniffi-js/UniFFICallbacks.h @@ -0,0 +1,75 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:set ts=2 sw=2 sts=2 et cindent: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_UniFFICallbacks_h +#define mozilla_UniFFICallbacks_h + +#include "mozilla/StaticPtr.h" +#include "mozilla/dom/UniFFIRust.h" +#include "mozilla/dom/UniFFIScaffolding.h" + +namespace mozilla::uniffi { + +/** + * UniFFI-generated scaffolding function to initialize a callback interface + * + * The Rust code expests us to pass it a ForeignCallback entrypoint for each + * callback interface. + */ +typedef void (*CallbackInitFunc)(ForeignCallback, RustCallStatus*); + +/** + * All the information needed to handle a callback interface. + * + * The generated code includes a function that maps interface ids to one of + * these structs + */ +struct CallbackInterfaceInfo { + // Human-friendly name + const char* mName; + // JS handler + StaticRefPtr* mHandler; + // Handler function, defined in the generated C++ code + ForeignCallback mForeignCallback; + // Init function, defined in the generated Rust scaffolding. mForeignCallback + // should be passed to this. + CallbackInitFunc mInitForeignCallback; +}; + +Maybe UniFFIGetCallbackInterfaceInfo( + uint64_t aInterfaceId); + +#ifdef MOZ_UNIFFI_FIXTURES +Maybe UniFFIFixturesGetCallbackInterfaceInfo( + uint64_t aInterfaceId); +#endif + +/** + * Register the JS handler for a callback interface + */ +void RegisterCallbackHandler(uint64_t aInterfaceId, + dom::UniFFICallbackHandler& aCallbackHandler, + ErrorResult& aError); + +/** + * Deregister the JS handler for a callback interface + */ +void DeregisterCallbackHandler(uint64_t aInterfaceId, ErrorResult& aError); + +/** + * Queue a UniFFI callback interface function to run at some point + * + * This function is for fire-and-forget callbacks where the caller doesn't care + * about the return value and doesn't want to wait for the call to finish. A + * good use case for this is logging. + */ +MOZ_CAN_RUN_SCRIPT +void QueueCallback(size_t aInterfaceId, uint64_t aHandle, uint32_t aMethod, + RustBuffer aArgs); + +} // namespace mozilla::uniffi + +#endif // mozilla_UniFFICallbacks_h -- cgit v1.2.3