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


#include "mozilla/dom/PMIDIPortParent.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/dom/MIDIPortParent.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 PMIDIPortParent::ProcessingError(
        Result aCode,
        const char* aReason) -> void
{
}

auto PMIDIPortParent::ShouldContinueFromReplyTimeout() -> bool
{
    return true;
}

MOZ_IMPLICIT PMIDIPortParent::PMIDIPortParent() :
    mozilla::ipc::IToplevelProtocol("PMIDIPortParent", kProtocolId, mozilla::ipc::ParentSide)
{
    MOZ_COUNT_CTOR(PMIDIPortParent);
}

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

auto PMIDIPortParent::ActorAlloc() -> void
{
    MOZ_RELEASE_ASSERT(XRE_IsParentProcess(), "Invalid process for `PMIDIPortParent'");
    AddRef();
}

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

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

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

auto PMIDIPortParent::SendReceive(mozilla::Span<MIDIMessage const> msg) -> bool
{
    UniquePtr<IPC::Message> msg__ = PMIDIPort::Msg_Receive(MSG_ROUTING_CONTROL);
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

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


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

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

auto PMIDIPortParent::SendUpdateStatus(
        const uint32_t& deviceState,
        const uint32_t& connectionState) -> bool
{
    UniquePtr<IPC::Message> msg__ = PMIDIPort::Msg_UpdateStatus(MSG_ROUTING_CONTROL);
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

    IPC::WriteParam((&(writer__)), deviceState);
    // Sentinel = 'deviceState'
    ((&(writer__)))->WriteSentinel(447284338);
    IPC::WriteParam((&(writer__)), connectionState);
    // Sentinel = 'connectionState'
    ((&(writer__)))->WriteSentinel(834209330);


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

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

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

auto PMIDIPortParent::OnMessageReceived(const Message& msg__) -> PMIDIPortParent::Result
{
    switch (msg__.type()) {
    case PMIDIPort::Msg_Shutdown__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PMIDIPort", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PMIDIPortParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PMIDIPort::Msg_Shutdown", OTHER);

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

            return MsgProcessed;
        }
    case PMIDIPort::Msg_Send__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PMIDIPort", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PMIDIPortParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PMIDIPort::Msg_Send", OTHER);

            IPC::MessageReader reader__{
                    msg__,
                    this};

            auto maybe__msg = IPC::ReadParam<nsTArray<MIDIMessage>>((&(reader__)));
            if (!maybe__msg) {
                FatalError("Error deserializing 'MIDIMessage[]'");
                return MsgValueError;

            }
            auto& msg = *maybe__msg;
            // Sentinel = 'msg'
            if ((!(((&(reader__)))->ReadSentinel(43450696)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'MIDIMessage[]'");
                return MsgValueError;
            }
            reader__.EndRead();
            mozilla::ipc::IPCResult __ok = (static_cast<MIDIPortParent*>(this))->RecvSend(std::move(msg));
            if ((!(__ok))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                // Error handled in mozilla::ipc::IPCResult
                return MsgProcessingError;
            }

            return MsgProcessed;
        }
    case PMIDIPort::Msg_Open__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PMIDIPort", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PMIDIPortParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PMIDIPort::Msg_Open", OTHER);

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

            return MsgProcessed;
        }
    case PMIDIPort::Msg_Close__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PMIDIPort", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PMIDIPortParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PMIDIPort::Msg_Close", OTHER);

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

            return MsgProcessed;
        }
    case PMIDIPort::Msg_Clear__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PMIDIPort", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PMIDIPortParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PMIDIPort::Msg_Clear", OTHER);

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

            return MsgProcessed;
        }
    default:
        return MsgNotKnown;
    case SHMEM_CREATED_MESSAGE_TYPE:
        {
            if (!ShmemCreated(msg__)) {
                return MsgPayloadError;
            }
            return MsgProcessed;
        }
    case SHMEM_DESTROYED_MESSAGE_TYPE:
        {
            if (!ShmemDestroyed(msg__)) {
                return MsgPayloadError;
            }
            return MsgProcessed;
        }
    }
}

auto PMIDIPortParent::OnMessageReceived(
        const Message& msg__,
        UniquePtr<Message>& reply__) -> PMIDIPortParent::Result
{
    MOZ_ASSERT_UNREACHABLE("message protocol not supported");
    return MsgNotKnown;
}



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

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

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

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

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

} // namespace IPC
