From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- ipc/chromium/src/mojo/core/ports/name.h | 122 ++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 ipc/chromium/src/mojo/core/ports/name.h (limited to 'ipc/chromium/src/mojo/core/ports/name.h') diff --git a/ipc/chromium/src/mojo/core/ports/name.h b/ipc/chromium/src/mojo/core/ports/name.h new file mode 100644 index 0000000000..0e668ebc40 --- /dev/null +++ b/ipc/chromium/src/mojo/core/ports/name.h @@ -0,0 +1,122 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef MOJO_CORE_PORTS_NAME_H_ +#define MOJO_CORE_PORTS_NAME_H_ + +#include + +#include +#include + +#include "base/logging.h" +#include "mozilla/HashFunctions.h" +#include "nsHashKeys.h" + +namespace mojo { +namespace core { +namespace ports { + +struct Name { + constexpr Name(uint64_t v1, uint64_t v2) : v1(v1), v2(v2) {} + uint64_t v1, v2; +}; + +inline bool operator==(const Name& a, const Name& b) { + return a.v1 == b.v1 && a.v2 == b.v2; +} + +inline bool operator!=(const Name& a, const Name& b) { return !(a == b); } + +inline bool operator<(const Name& a, const Name& b) { + return std::tie(a.v1, a.v2) < std::tie(b.v1, b.v2); +} + +std::ostream& operator<<(std::ostream& stream, const Name& name); +mozilla::Logger& operator<<(mozilla::Logger& log, const Name& name); + +struct PortName : Name { + constexpr PortName() : Name(0, 0) {} + constexpr PortName(uint64_t v1, uint64_t v2) : Name(v1, v2) {} +}; + +constexpr PortName kInvalidPortName{0, 0}; + +struct NodeName : Name { + constexpr NodeName() : Name(0, 0) {} + constexpr NodeName(uint64_t v1, uint64_t v2) : Name(v1, v2) {} +}; + +constexpr NodeName kInvalidNodeName{0, 0}; + +} // namespace ports +} // namespace core +} // namespace mojo + +namespace mozilla { + +template <> +inline PLDHashNumber Hash( + const mojo::core::ports::PortName& aValue) { + return mozilla::HashGeneric(aValue.v1, aValue.v2); +} + +template <> +inline PLDHashNumber Hash( + const mojo::core::ports::NodeName& aValue) { + return mozilla::HashGeneric(aValue.v1, aValue.v2); +} + +using PortNameHashKey = nsGenericHashKey; +using NodeNameHashKey = nsGenericHashKey; + +} // namespace mozilla + +namespace std { + +template <> +struct hash { + std::size_t operator()(const mojo::core::ports::PortName& name) const { + // FIXME: PLDHashNumber is only 32-bits + return mozilla::Hash(name); + } +}; + +template <> +struct hash { + std::size_t operator()(const mojo::core::ports::NodeName& name) const { + // FIXME: PLDHashNumber is only 32-bits + return mozilla::Hash(name); + } +}; + +} // namespace std + +class PickleIterator; + +namespace IPC { + +template +struct ParamTraits; +class Message; +class MessageReader; +class MessageWriter; + +template <> +struct ParamTraits { + using paramType = mojo::core::ports::PortName; + static void Write(MessageWriter* aWriter, const paramType& aParam); + static bool Read(MessageReader* aReader, paramType* aResult); +}; + +template <> +struct ParamTraits { + using paramType = mojo::core::ports::NodeName; + static void Write(MessageWriter* aWriter, const paramType& aParam); + static bool Read(MessageReader* aReader, paramType* aResult); +}; + +} // namespace IPC + +#endif // MOJO_CORE_PORTS_NAME_H_ -- cgit v1.2.3