//
// Automatically generated by ipdlc.
// Edit at your own risk
//


#include "mozilla/dom/PGamepadEventChannelParent.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/dom/GamepadEventChannelParent.h"
#include "mozilla/dom/GamepadMessageUtils.h"

#include "mozilla/ipc/PBackgroundParent.h"

#include "ipc/IPCMessageUtils.h"
#include "ipc/IPCMessageUtilsSpecializations.h"
#include "nsIFile.h"
#include "mozilla/ipc/Endpoint.h"
#include "mozilla/ipc/ProtocolMessageUtils.h"
#include "mozilla/ipc/ProtocolUtils.h"
#include "mozilla/ipc/ShmemMessageUtils.h"
#include "mozilla/ipc/TaintingIPCUtils.h"

namespace mozilla {
namespace dom {


auto PGamepadEventChannelParent::Recv__delete__() -> mozilla::ipc::IPCResult
{
    return IPC_OK();
}

MOZ_IMPLICIT PGamepadEventChannelParent::PGamepadEventChannelParent() :
    mozilla::ipc::IRefCountedProtocol(kProtocolId, mozilla::ipc::ParentSide)
{
    MOZ_COUNT_CTOR(PGamepadEventChannelParent);
}

PGamepadEventChannelParent::~PGamepadEventChannelParent()
{
    MOZ_COUNT_DTOR(PGamepadEventChannelParent);
}

auto PGamepadEventChannelParent::ActorAlloc() -> void
{
    AddRef();
}

auto PGamepadEventChannelParent::ActorDealloc() -> void
{
    Release();
}

auto PGamepadEventChannelParent::OtherPid() const -> ::base::ProcessId
{
    ::base::ProcessId pid =
        ::mozilla::ipc::IProtocol::ToplevelProtocol()->OtherPidMaybeInvalid();
    MOZ_RELEASE_ASSERT(pid != ::base::kInvalidProcessId);
    return pid;
}

auto PGamepadEventChannelParent::OtherChildID() const -> ::GeckoChildID
{
    ::GeckoChildID childID =
        ::mozilla::ipc::IProtocol::ToplevelProtocol()->OtherChildIDMaybeInvalid();
    MOZ_RELEASE_ASSERT(childID != -1);
    return childID;
}

auto PGamepadEventChannelParent::OtherEndpointProcInfo() const -> ::mozilla::ipc::EndpointProcInfo
{
    return ::mozilla::ipc::EndpointProcInfo{OtherPid(), OtherChildID()};
}

auto PGamepadEventChannelParent::Manager() const -> PBackgroundParent*
{
    return static_cast<PBackgroundParent*>(IProtocol::Manager());
}

auto PGamepadEventChannelParent::ManagedProtocolIds() const -> mozilla::Span<mozilla::ipc::ProtocolId const>
{
    return {};
}

auto PGamepadEventChannelParent::GetManagedActors(mozilla::ipc::ProtocolId aProtocol) -> UntypedManagedContainer*
{
    switch (aProtocol) {
    default:
        return nullptr;
    }
}

auto PGamepadEventChannelParent::RejectPendingResponses(ResponseRejectReason aReason) -> void
{
    mAsyncCallbacks.RejectPendingResponses(aReason);
}

auto PGamepadEventChannelParent::SendGamepadUpdate(const GamepadChangeEvent& aGamepadEvent) -> bool
{
    UniquePtr<IPC::Message> msg__ = PGamepadEventChannel::Msg_GamepadUpdate(Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

    IPC::WriteParam((&(writer__)), aGamepadEvent);
    // Sentinel = 'aGamepadEvent'
    ((&(writer__)))->WriteSentinel(578225427);


    if (mozilla::ipc::LoggingEnabledFor("PGamepadEventChannel", mozilla::ipc::ParentSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PGamepadEventChannelParent",
            this->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Sending ",
            msg__->type(),
            mozilla::ipc::MessageDirection::eSending);
    }
    AUTO_PROFILER_LABEL("PGamepadEventChannel::Msg_GamepadUpdate", OTHER);

    bool sendok__ = ChannelSend(std::move(msg__));
    return sendok__;
}

auto PGamepadEventChannelParent::SendReplyGamepadPromise(const uint32_t& aPromiseID) -> bool
{
    UniquePtr<IPC::Message> msg__ = PGamepadEventChannel::Msg_ReplyGamepadPromise(Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

    IPC::WriteParam((&(writer__)), aPromiseID);
    // Sentinel = 'aPromiseID'
    ((&(writer__)))->WriteSentinel(363398094);


    if (mozilla::ipc::LoggingEnabledFor("PGamepadEventChannel", mozilla::ipc::ParentSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PGamepadEventChannelParent",
            this->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Sending ",
            msg__->type(),
            mozilla::ipc::MessageDirection::eSending);
    }
    AUTO_PROFILER_LABEL("PGamepadEventChannel::Msg_ReplyGamepadPromise", OTHER);

    bool sendok__ = ChannelSend(std::move(msg__));
    return sendok__;
}

auto PGamepadEventChannelParent::DeallocManagee(
        mozilla::ipc::ProtocolId aProtocolId,
        IProtocol* aListener) -> void
{
    FatalError("unreached");
    return;
}

auto PGamepadEventChannelParent::OnMessageReceived(const Message& msg__) -> PGamepadEventChannelParent::Result
{
    switch (msg__.type()) {
    case MANAGED_ENDPOINT_BOUND_MESSAGE_TYPE:
        {
            if (!mAwaitingManagedEndpointBind) {
                NS_WARNING("Unexpected managed endpoint lifecycle message after actor bound!");
                return MsgNotAllowed;
            }
            mAwaitingManagedEndpointBind = false;
            return MsgProcessed;
        }
    case MANAGED_ENDPOINT_DROPPED_MESSAGE_TYPE:
        {
            if (!mAwaitingManagedEndpointBind) {
                NS_WARNING("Unexpected managed endpoint lifecycle message after actor bound!");
                return MsgNotAllowed;
            }
            mAwaitingManagedEndpointBind = false;
            this->ActorDisconnected(ManagedEndpointDropped);
            return MsgProcessed;
        }
    case PGamepadEventChannel::Msg___delete____ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PGamepadEventChannel", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PGamepadEventChannelParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PGamepadEventChannel::Msg___delete__", OTHER);

            mozilla::ipc::IPCResult __ok = (static_cast<GamepadEventChannelParent*>(this))->Recv__delete__();
            if ((!(__ok))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                // Error handled in mozilla::ipc::IPCResult
                return MsgProcessingError;
            }


            this->ActorDisconnected(Deletion);

            return MsgProcessed;
        }
    case PGamepadEventChannel::Msg_VibrateHaptic__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PGamepadEventChannel", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PGamepadEventChannelParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PGamepadEventChannel::Msg_VibrateHaptic", OTHER);

            IPC::MessageReader reader__{
                    msg__,
                    this};

            auto maybe__aHandle = IPC::ReadParam<Tainted<GamepadHandle>>((&(reader__)));
            if (!maybe__aHandle) {
                FatalError("Error deserializing 'GamepadHandle'");
                return MsgValueError;

            }
            auto& aHandle = *maybe__aHandle;
            // Sentinel = 'aHandle'
            if ((!(((&(reader__)))->ReadSentinel(174326446)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'GamepadHandle'");
                return MsgValueError;
            }
            auto maybe__aHapticIndex = IPC::ReadParam<Tainted<uint32_t>>((&(reader__)));
            if (!maybe__aHapticIndex) {
                FatalError("Error deserializing 'uint32_t'");
                return MsgValueError;

            }
            auto& aHapticIndex = *maybe__aHapticIndex;
            // Sentinel = 'aHapticIndex'
            if ((!(((&(reader__)))->ReadSentinel(500040883)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'uint32_t'");
                return MsgValueError;
            }
            auto maybe__aIntensity = IPC::ReadParam<Tainted<double>>((&(reader__)));
            if (!maybe__aIntensity) {
                FatalError("Error deserializing 'double'");
                return MsgValueError;

            }
            auto& aIntensity = *maybe__aIntensity;
            // Sentinel = 'aIntensity'
            if ((!(((&(reader__)))->ReadSentinel(367854633)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'double'");
                return MsgValueError;
            }
            auto maybe__aDuration = IPC::ReadParam<Tainted<double>>((&(reader__)));
            if (!maybe__aDuration) {
                FatalError("Error deserializing 'double'");
                return MsgValueError;

            }
            auto& aDuration = *maybe__aDuration;
            // Sentinel = 'aDuration'
            if ((!(((&(reader__)))->ReadSentinel(296551336)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'double'");
                return MsgValueError;
            }
            auto maybe__aPromiseID = IPC::ReadParam<uint32_t>((&(reader__)));
            if (!maybe__aPromiseID) {
                FatalError("Error deserializing 'uint32_t'");
                return MsgValueError;

            }
            auto& aPromiseID = *maybe__aPromiseID;
            // Sentinel = 'aPromiseID'
            if ((!(((&(reader__)))->ReadSentinel(363398094)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'uint32_t'");
                return MsgValueError;
            }
            reader__.EndRead();
            mozilla::ipc::IPCResult __ok = (static_cast<GamepadEventChannelParent*>(this))->RecvVibrateHaptic(std::move(aHandle), std::move(aHapticIndex), std::move(aIntensity), std::move(aDuration), std::move(aPromiseID));
            if ((!(__ok))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                // Error handled in mozilla::ipc::IPCResult
                return MsgProcessingError;
            }

            return MsgProcessed;
        }
    case PGamepadEventChannel::Msg_StopVibrateHaptic__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PGamepadEventChannel", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PGamepadEventChannelParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PGamepadEventChannel::Msg_StopVibrateHaptic", OTHER);

            IPC::MessageReader reader__{
                    msg__,
                    this};

            auto maybe__aHandle = IPC::ReadParam<Tainted<GamepadHandle>>((&(reader__)));
            if (!maybe__aHandle) {
                FatalError("Error deserializing 'GamepadHandle'");
                return MsgValueError;

            }
            auto& aHandle = *maybe__aHandle;
            // Sentinel = 'aHandle'
            if ((!(((&(reader__)))->ReadSentinel(174326446)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'GamepadHandle'");
                return MsgValueError;
            }
            reader__.EndRead();
            mozilla::ipc::IPCResult __ok = (static_cast<GamepadEventChannelParent*>(this))->RecvStopVibrateHaptic(std::move(aHandle));
            if ((!(__ok))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                // Error handled in mozilla::ipc::IPCResult
                return MsgProcessingError;
            }

            return MsgProcessed;
        }
    case PGamepadEventChannel::Msg_LightIndicatorColor__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PGamepadEventChannel", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PGamepadEventChannelParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PGamepadEventChannel::Msg_LightIndicatorColor", OTHER);

            IPC::MessageReader reader__{
                    msg__,
                    this};

            auto maybe__aHandle = IPC::ReadParam<Tainted<GamepadHandle>>((&(reader__)));
            if (!maybe__aHandle) {
                FatalError("Error deserializing 'GamepadHandle'");
                return MsgValueError;

            }
            auto& aHandle = *maybe__aHandle;
            // Sentinel = 'aHandle'
            if ((!(((&(reader__)))->ReadSentinel(174326446)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'GamepadHandle'");
                return MsgValueError;
            }
            auto maybe__aLightColorIndex = IPC::ReadParam<Tainted<uint32_t>>((&(reader__)));
            if (!maybe__aLightColorIndex) {
                FatalError("Error deserializing 'uint32_t'");
                return MsgValueError;

            }
            auto& aLightColorIndex = *maybe__aLightColorIndex;
            // Sentinel = 'aLightColorIndex'
            if ((!(((&(reader__)))->ReadSentinel(882247249)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'uint32_t'");
                return MsgValueError;
            }
            auto maybe__aRed = IPC::ReadParam<uint8_t>((&(reader__)));
            if (!maybe__aRed) {
                FatalError("Error deserializing 'uint8_t'");
                return MsgValueError;

            }
            auto& aRed = *maybe__aRed;
            // Sentinel = 'aRed'
            if ((!(((&(reader__)))->ReadSentinel(61604221)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'uint8_t'");
                return MsgValueError;
            }
            auto maybe__aGreen = IPC::ReadParam<uint8_t>((&(reader__)));
            if (!maybe__aGreen) {
                FatalError("Error deserializing 'uint8_t'");
                return MsgValueError;

            }
            auto& aGreen = *maybe__aGreen;
            // Sentinel = 'aGreen'
            if ((!(((&(reader__)))->ReadSentinel(131990099)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'uint8_t'");
                return MsgValueError;
            }
            auto maybe__aBlue = IPC::ReadParam<uint8_t>((&(reader__)));
            if (!maybe__aBlue) {
                FatalError("Error deserializing 'uint8_t'");
                return MsgValueError;

            }
            auto& aBlue = *maybe__aBlue;
            // Sentinel = 'aBlue'
            if ((!(((&(reader__)))->ReadSentinel(92602858)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'uint8_t'");
                return MsgValueError;
            }
            auto maybe__aPromiseID = IPC::ReadParam<uint32_t>((&(reader__)));
            if (!maybe__aPromiseID) {
                FatalError("Error deserializing 'uint32_t'");
                return MsgValueError;

            }
            auto& aPromiseID = *maybe__aPromiseID;
            // Sentinel = 'aPromiseID'
            if ((!(((&(reader__)))->ReadSentinel(363398094)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'uint32_t'");
                return MsgValueError;
            }
            reader__.EndRead();
            mozilla::ipc::IPCResult __ok = (static_cast<GamepadEventChannelParent*>(this))->RecvLightIndicatorColor(std::move(aHandle), std::move(aLightColorIndex), std::move(aRed), std::move(aGreen), std::move(aBlue), std::move(aPromiseID));
            if ((!(__ok))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                // Error handled in mozilla::ipc::IPCResult
                return MsgProcessingError;
            }

            return MsgProcessed;
        }
    case PGamepadEventChannel::Msg_RequestAllGamepads__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PGamepadEventChannel", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PGamepadEventChannelParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PGamepadEventChannel::Msg_RequestAllGamepads", OTHER);

            mozilla::ipc::ActorId id__ = Id();
            UniquePtr<IPC::Message> reply__(PGamepadEventChannel::Reply_RequestAllGamepads(id__));
            reply__->set_seqno(msg__.seqno());

            RefPtr<mozilla::ipc::IPDLResolverInner> resolver__ =
                new mozilla::ipc::IPDLResolverInner(std::move(reply__), this);

            RequestAllGamepadsResolver resolver = [resolver__ = std::move(resolver__)](mozilla::Span<GamepadAdded const> aParam) {
                resolver__->Resolve([&] (IPC::Message* reply__, IProtocol* self__) {
                    IPC::MessageWriter writer__(*reply__, self__);
                    IPC::WriteParam((&(writer__)), aParam);
                    // Sentinel = 'gamepads'
                    ((&(writer__)))->WriteSentinel(244056899);

                    if (mozilla::ipc::LoggingEnabledFor("PGamepadEventChannel", mozilla::ipc::ParentSide)) {
                        mozilla::ipc::LogMessageForProtocol(
                            "PGamepadEventChannelParent",
                            self__->ToplevelProtocol()->OtherPidMaybeInvalid(),
                            "Sending reply ",
                            reply__->type(),
                            mozilla::ipc::MessageDirection::eSending);
                    }

                });
            };
            mozilla::ipc::IPCResult __ok = (static_cast<GamepadEventChannelParent*>(this))->RecvRequestAllGamepads(std::move(resolver));
            if ((!(__ok))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                // Error handled in mozilla::ipc::IPCResult
                return MsgProcessingError;
            }

            return MsgProcessed;
        }
    default:
        return MsgNotKnown;
    }
}

auto PGamepadEventChannelParent::OnMessageReceived(
        const Message& msg__,
        UniquePtr<Message>& reply__) -> PGamepadEventChannelParent::Result
{
    return MsgNotKnown;
}



} // namespace dom
} // namespace mozilla
namespace IPC {
auto ParamTraits<::mozilla::dom::PGamepadEventChannelParent*>::Write(
        IPC::MessageWriter* aWriter,
        const paramType& aVar) -> void
{
    IPC::WriteParam(aWriter, static_cast<mozilla::ipc::IProtocol*>(aVar));
    // Sentinel = 'PGamepadEventChannel'
    (aWriter)->WriteSentinel(1326057403);
}

auto ParamTraits<::mozilla::dom::PGamepadEventChannelParent*>::Read(IPC::MessageReader* aReader) -> IPC::ReadResult<paramType>
{
    auto maybe__actor = IPC::ReadParam<mozilla::ipc::IProtocol*>(aReader);
    if (!maybe__actor) {
        aReader->FatalError("Error deserializing managed PGamepadEventChannel actor");
        return {};

    }
    auto& actor = *maybe__actor;
    // Sentinel = 'PGamepadEventChannel'
    if ((!((aReader)->ReadSentinel(1326057403)))) {
        mozilla::ipc::SentinelReadError("Error deserializing managed PGamepadEventChannel actor");
        return {};
    }

    if (actor && actor->GetProtocolId() != PGamepadEventChannelMsgStart) {
        aReader->FatalError("Unexpected actor type (expected PGamepadEventChannel)");

        return {};
    }
    return static_cast<::mozilla::dom::PGamepadEventChannelParent*>(actor);
}

} // namespace IPC
