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


#include "mozilla/dom/PJSValidatorParent.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/dom/JSValidatorParent.h"

#include "mozilla/dom/PJSOracleParent.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 {


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

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

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

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

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

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

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

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

auto PJSValidatorParent::SendIsOpaqueResponseAllowed(
        mozilla::ipc::ResolveCallback<std::tuple<mozilla::Maybe<Shmem>, ValidatorResult>>&& aResolve,
        mozilla::ipc::RejectCallback&& aReject) -> void
{
    UniquePtr<IPC::Message> msg__ = PJSValidator::Msg_IsOpaqueResponseAllowed(Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};



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

    IPC::Message::seqno_t seqno__ = 0;
    if (ChannelSend(std::move(msg__), (&(seqno__)))) {
        mAsyncCallbacks.AddCallback(seqno__, PJSValidator::Reply_IsOpaqueResponseAllowed__ID, [resolve=std::move(aResolve)](IPC::MessageReader* aReader) mutable {
            auto maybe__aMem = IPC::ReadParam<mozilla::Maybe<Shmem>>(aReader);
            if (!maybe__aMem) {
                (aReader)->FatalError("Error deserializing 'Shmem?'");
                return MsgValueError;

            }
            auto& aMem = *maybe__aMem;
            // Sentinel = 'aMem'
            if ((!((aReader)->ReadSentinel(61211009)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'Shmem?'");
                return MsgValueError;
            }
            auto maybe__aResult = IPC::ReadParam<ValidatorResult>(aReader);
            if (!maybe__aResult) {
                (aReader)->FatalError("Error deserializing 'ValidatorResult'");
                return MsgValueError;

            }
            auto& aResult = *maybe__aResult;
            // Sentinel = 'aResult'
            if ((!((aReader)->ReadSentinel(185205473)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'ValidatorResult'");
                return MsgValueError;
            }


            aReader->EndRead();

            resolve(std::make_tuple(std::move(aMem), std::move(aResult)));
            return MsgProcessed;
        }, std::move(aReject));
    }
    else {
        aReject(::mozilla::ipc::ResponseRejectReason::SendError);
    }
    return;
}

auto PJSValidatorParent::SendIsOpaqueResponseAllowed() -> RefPtr<IsOpaqueResponseAllowedPromise>
{
    RefPtr<MozPromise<std::tuple<mozilla::Maybe<Shmem>, ValidatorResult>, ResponseRejectReason, true>::Private> promise__ = new MozPromise<std::tuple<mozilla::Maybe<Shmem>, ValidatorResult>, ResponseRejectReason, true>::Private(__func__);
    promise__->UseDirectTaskDispatch(__func__);
    SendIsOpaqueResponseAllowed([promise__](std::tuple<mozilla::Maybe<Shmem>, ValidatorResult>&& aValue) {
        promise__->Resolve(std::move(aValue), __func__);
    }, [promise__](ResponseRejectReason&& aReason) {
        promise__->Reject(std::move(aReason), __func__);
    });
    return promise__;
}

auto PJSValidatorParent::SendOnDataAvailable(Shmem&& aData) -> bool
{
    UniquePtr<IPC::Message> msg__ = PJSValidator::Msg_OnDataAvailable(Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

    IPC::WriteParam((&(writer__)), std::move(aData));
    // Sentinel = 'aData'
    ((&(writer__)))->WriteSentinel(90571228);


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

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

auto PJSValidatorParent::SendOnStopRequest(
        const nsresult& aReason,
        const nsACString& aContentCharset,
        const nsAString& aHintCharset,
        const nsAString& aDocumentCharset) -> bool
{
    UniquePtr<IPC::Message> msg__ = PJSValidator::Msg_OnStopRequest(Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

    IPC::WriteParam((&(writer__)), aReason);
    // Sentinel = 'aReason'
    ((&(writer__)))->WriteSentinel(180093642);
    IPC::WriteParam((&(writer__)), aContentCharset);
    // Sentinel = 'aContentCharset'
    ((&(writer__)))->WriteSentinel(791152135);
    IPC::WriteParam((&(writer__)), aHintCharset);
    // Sentinel = 'aHintCharset'
    ((&(writer__)))->WriteSentinel(500237503);
    IPC::WriteParam((&(writer__)), aDocumentCharset);
    // Sentinel = 'aDocumentCharset'
    ((&(writer__)))->WriteSentinel(895026795);


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

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

auto PJSValidatorParent::Send__delete__(PJSValidatorParent* actor) -> bool
{
    if (!actor || !actor->CanSend()) {
        NS_WARNING("Attempt to __delete__ missing or closed actor");
        return false;
    }
    UniquePtr<IPC::Message> msg__ = PJSValidator::Msg___delete__((actor)->Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            actor};


    if (mozilla::ipc::LoggingEnabledFor("PJSValidator", mozilla::ipc::ParentSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PJSValidatorParent",
            actor->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Sending ",
            msg__->type(),
            mozilla::ipc::MessageDirection::eSending);
    }
    AUTO_PROFILER_LABEL("PJSValidator::Msg___delete__", OTHER);

    bool sendok__ = (actor)->ChannelSend(std::move(msg__));

    actor->ActorDisconnected(Deletion);
    return sendok__;
}

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

auto PJSValidatorParent::OnMessageReceived(const Message& msg__) -> PJSValidatorParent::Result
{
    if (!CanSend()) {
        if (mozilla::ipc::LoggingEnabledFor("PJSValidator", mozilla::ipc::ParentSide)) {
            mozilla::ipc::LogMessageForProtocol(
                "PJSValidatorParent",
                this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                "Ignored message for dead actor",
                (&(msg__))->type(),
                mozilla::ipc::MessageDirection::eSending);
        }
        return MsgProcessed;

    }
    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 PJSValidator::Reply_IsOpaqueResponseAllowed__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PJSValidator", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PJSValidatorParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }

            AUTO_PROFILER_LABEL("PJSValidator::Msg_IsOpaqueResponseAllowed", OTHER);


            return mAsyncCallbacks.GotReply(this, msg__);
        }
    case PJSValidator::Reply___delete____ID:
        {
            return MsgProcessed;
        }
    default:
        return MsgNotKnown;
    }
}

auto PJSValidatorParent::OnMessageReceived(
        const Message& msg__,
        UniquePtr<Message>& reply__) -> PJSValidatorParent::Result
{
    if (!CanSend()) {
        return MsgDropped;

    }
    MOZ_ASSERT_UNREACHABLE("message protocol not supported");
    return MsgNotKnown;
}



} // namespace dom
} // namespace mozilla
