206 lines
6.7 KiB
C++
Executable File
206 lines
6.7 KiB
C++
Executable File
// Copyright 2013 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 NET_INTERFACES_IP_ADDRESS_MOJOM_BLINK_H_
|
|
#define NET_INTERFACES_IP_ADDRESS_MOJOM_BLINK_H_
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <limits>
|
|
#include <type_traits>
|
|
#include <utility>
|
|
|
|
#include "base/callback.h"
|
|
#include "base/macros.h"
|
|
#include "base/optional.h"
|
|
|
|
#include "mojo/public/cpp/bindings/mojo_buildflags.h"
|
|
#if BUILDFLAG(MOJO_TRACE_ENABLED)
|
|
#include "base/trace_event/trace_event.h"
|
|
#endif
|
|
#include "mojo/public/cpp/bindings/clone_traits.h"
|
|
#include "mojo/public/cpp/bindings/equals_traits.h"
|
|
#include "mojo/public/cpp/bindings/lib/serialization.h"
|
|
#include "mojo/public/cpp/bindings/struct_ptr.h"
|
|
#include "mojo/public/cpp/bindings/struct_traits.h"
|
|
#include "mojo/public/cpp/bindings/union_traits.h"
|
|
#include "net/interfaces/ip_address.mojom-shared.h"
|
|
|
|
#include "mojo/public/cpp/bindings/lib/wtf_clone_equals_util.h"
|
|
#include "mojo/public/cpp/bindings/lib/wtf_hash_util.h"
|
|
#include "third_party/blink/renderer/platform/mojo/revocable_interface_ptr.h"
|
|
#include "third_party/blink/renderer/platform/wtf/hash_functions.h"
|
|
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
|
|
|
|
#include "mojo/public/cpp/bindings/associated_interface_ptr.h"
|
|
#include "mojo/public/cpp/bindings/associated_interface_ptr_info.h"
|
|
#include "mojo/public/cpp/bindings/associated_interface_request.h"
|
|
#include "mojo/public/cpp/bindings/interface_ptr.h"
|
|
#include "mojo/public/cpp/bindings/interface_request.h"
|
|
#include "mojo/public/cpp/bindings/lib/control_message_handler.h"
|
|
#include "mojo/public/cpp/bindings/raw_ptr_impl_ref_traits.h"
|
|
#include "mojo/public/cpp/bindings/thread_safe_interface_ptr.h"
|
|
#include "third_party/blink/renderer/platform/mojo/revocable_interface_ptr.h"
|
|
|
|
|
|
#include "mojo/public/cpp/bindings/lib/native_enum_serialization.h"
|
|
#include "mojo/public/cpp/bindings/lib/native_struct_serialization.h"
|
|
|
|
|
|
namespace net {
|
|
namespace interfaces {
|
|
namespace blink {
|
|
class IPAddress;
|
|
using IPAddressPtr = mojo::StructPtr<IPAddress>;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class IPAddress {
|
|
public:
|
|
using DataView = IPAddressDataView;
|
|
using Data_ = internal::IPAddress_Data;
|
|
|
|
template <typename... Args>
|
|
static IPAddressPtr New(Args&&... args) {
|
|
return IPAddressPtr(
|
|
base::in_place, std::forward<Args>(args)...);
|
|
}
|
|
|
|
template <typename U>
|
|
static IPAddressPtr From(const U& u) {
|
|
return mojo::TypeConverter<IPAddressPtr, U>::Convert(u);
|
|
}
|
|
|
|
template <typename U>
|
|
U To() const {
|
|
return mojo::TypeConverter<U, IPAddress>::Convert(*this);
|
|
}
|
|
|
|
|
|
IPAddress();
|
|
|
|
explicit IPAddress(
|
|
const WTF::Vector<uint8_t>& address_bytes);
|
|
|
|
~IPAddress();
|
|
|
|
// Clone() is a template so it is only instantiated if it is used. Thus, the
|
|
// bindings generator does not need to know whether Clone() or copy
|
|
// constructor/assignment are available for members.
|
|
template <typename StructPtrType = IPAddressPtr>
|
|
IPAddressPtr Clone() const;
|
|
|
|
// Equals() is a template so it is only instantiated if it is used. Thus, the
|
|
// bindings generator does not need to know whether Equals() or == operator
|
|
// are available for members.
|
|
template <typename T,
|
|
typename std::enable_if<std::is_same<
|
|
T, IPAddress>::value>::type* = nullptr>
|
|
bool Equals(const T& other) const;
|
|
|
|
template <typename UserType>
|
|
static WTF::Vector<uint8_t> Serialize(UserType* input) {
|
|
return mojo::internal::SerializeImpl<
|
|
IPAddress::DataView, WTF::Vector<uint8_t>>(input);
|
|
}
|
|
|
|
template <typename UserType>
|
|
static mojo::Message SerializeAsMessage(UserType* input) {
|
|
return mojo::internal::SerializeAsMessageImpl<
|
|
IPAddress::DataView>(input);
|
|
}
|
|
|
|
// The returned Message is serialized only if the message is moved
|
|
// cross-process or cross-language. Otherwise if the message is Deserialized
|
|
// as the same UserType |input| will just be moved to |output| in
|
|
// DeserializeFromMessage.
|
|
template <typename UserType>
|
|
static mojo::Message WrapAsMessage(UserType input) {
|
|
return mojo::Message(std::make_unique<
|
|
internal::IPAddress_UnserializedMessageContext<
|
|
UserType, IPAddress::DataView>>(0, 0, std::move(input)));
|
|
}
|
|
|
|
template <typename UserType>
|
|
static bool Deserialize(const void* data,
|
|
size_t data_num_bytes,
|
|
UserType* output) {
|
|
return mojo::internal::DeserializeImpl<IPAddress::DataView>(
|
|
data, data_num_bytes, std::vector<mojo::ScopedHandle>(), output, Validate);
|
|
}
|
|
|
|
template <typename UserType>
|
|
static bool Deserialize(const WTF::Vector<uint8_t>& input,
|
|
UserType* output) {
|
|
return IPAddress::Deserialize(
|
|
input.size() == 0 ? nullptr : &input.front(), input.size(), output);
|
|
}
|
|
|
|
template <typename UserType>
|
|
static bool DeserializeFromMessage(mojo::Message input,
|
|
UserType* output) {
|
|
auto context = input.TakeUnserializedContext<
|
|
internal::IPAddress_UnserializedMessageContext<
|
|
UserType, IPAddress::DataView>>();
|
|
if (context) {
|
|
*output = std::move(context->TakeData());
|
|
return true;
|
|
}
|
|
input.SerializeIfNecessary();
|
|
return mojo::internal::DeserializeImpl<IPAddress::DataView>(
|
|
input.payload(), input.payload_num_bytes(),
|
|
std::move(*input.mutable_handles()), output, Validate);
|
|
}
|
|
|
|
WTF::Vector<uint8_t> address_bytes;
|
|
|
|
private:
|
|
static bool Validate(const void* data,
|
|
mojo::internal::ValidationContext* validation_context);
|
|
};
|
|
|
|
template <typename StructPtrType>
|
|
IPAddressPtr IPAddress::Clone() const {
|
|
return New(
|
|
mojo::Clone(address_bytes)
|
|
);
|
|
}
|
|
|
|
template <typename T,
|
|
typename std::enable_if<std::is_same<
|
|
T, IPAddress>::value>::type*>
|
|
bool IPAddress::Equals(const T& other_struct) const {
|
|
if (!mojo::Equals(this->address_bytes, other_struct.address_bytes))
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
|
|
} // namespace blink
|
|
} // namespace interfaces
|
|
} // namespace net
|
|
|
|
namespace mojo {
|
|
|
|
|
|
template <>
|
|
struct StructTraits<::net::interfaces::blink::IPAddress::DataView,
|
|
::net::interfaces::blink::IPAddressPtr> {
|
|
static bool IsNull(const ::net::interfaces::blink::IPAddressPtr& input) { return !input; }
|
|
static void SetToNull(::net::interfaces::blink::IPAddressPtr* output) { output->reset(); }
|
|
|
|
static const decltype(::net::interfaces::blink::IPAddress::address_bytes)& address_bytes(
|
|
const ::net::interfaces::blink::IPAddressPtr& input) {
|
|
return input->address_bytes;
|
|
}
|
|
|
|
static bool Read(::net::interfaces::blink::IPAddress::DataView input, ::net::interfaces::blink::IPAddressPtr* output);
|
|
};
|
|
|
|
} // namespace mojo
|
|
|
|
#endif // NET_INTERFACES_IP_ADDRESS_MOJOM_BLINK_H_
|