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


#include "mozilla/dom/PRemoteWorkerNonLifeCycleOpControllerParent.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/dom/ClientIPCUtils.h"
#include "mozilla/dom/ReferrerInfoUtils.h"
#include "mozilla/dom/RemoteWorkerNonLifeCycleOpControllerParent.h"
#include "mozilla/dom/ServiceWorkerIPCUtils.h"
#include "mozilla/dom/WorkerIPCUtils.h"
#include "mozilla/ipc/IPCCore.h"
#include "nsIPrincipal.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 PRemoteWorkerNonLifeCycleOpControllerParent::ProcessingError(
        Result aCode,
        const char* aReason) -> void
{
}

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

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

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

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

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

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

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

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

auto PRemoteWorkerNonLifeCycleOpControllerParent::SendExecOp(const SharedWorkerOpArgs& aOpArgs) -> bool
{
    UniquePtr<IPC::Message> msg__ = PRemoteWorkerNonLifeCycleOpController::Msg_ExecOp(MSG_ROUTING_CONTROL);
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

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


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

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

auto PRemoteWorkerNonLifeCycleOpControllerParent::SendExecServiceWorkerOp(
        const ServiceWorkerOpArgs& aOpArgs,
        mozilla::ipc::ResolveCallback<ServiceWorkerOpResult>&& aResolve,
        mozilla::ipc::RejectCallback&& aReject) -> void
{
    UniquePtr<IPC::Message> msg__ = PRemoteWorkerNonLifeCycleOpController::Msg_ExecServiceWorkerOp(MSG_ROUTING_CONTROL);
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

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


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

    IPC::Message::seqno_t seqno__ = 0;
    if (ChannelSend(std::move(msg__), (&(seqno__)))) {
        mAsyncCallbacks.AddCallback(seqno__, PRemoteWorkerNonLifeCycleOpController::Reply_ExecServiceWorkerOp__ID, [resolve=std::move(aResolve)](IPC::MessageReader* aReader) mutable {
            auto maybe__aResult = IPC::ReadParam<ServiceWorkerOpResult>(aReader);
            if (!maybe__aResult) {
                (aReader)->FatalError("Error deserializing 'ServiceWorkerOpResult'");
                return MsgValueError;

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


            aReader->EndRead();

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

auto PRemoteWorkerNonLifeCycleOpControllerParent::SendExecServiceWorkerOp(const ServiceWorkerOpArgs& aOpArgs) -> RefPtr<ExecServiceWorkerOpPromise>
{
    RefPtr<MozPromise<ServiceWorkerOpResult, ResponseRejectReason, true>::Private> promise__ = new MozPromise<ServiceWorkerOpResult, ResponseRejectReason, true>::Private(__func__);
    promise__->UseDirectTaskDispatch(__func__);
    SendExecServiceWorkerOp(std::move(aOpArgs), [promise__](ServiceWorkerOpResult&& aValue) {
        promise__->Resolve(std::move(aValue), __func__);
    }, [promise__](ResponseRejectReason&& aReason) {
        promise__->Reject(std::move(aReason), __func__);
    });
    return promise__;
}

auto PRemoteWorkerNonLifeCycleOpControllerParent::SendShutdown() -> bool
{
    UniquePtr<IPC::Message> msg__ = PRemoteWorkerNonLifeCycleOpController::Msg_Shutdown(MSG_ROUTING_CONTROL);
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};



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

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

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

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

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

            return MsgProcessed;
        }
    case PRemoteWorkerNonLifeCycleOpController::Msg_Error__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PRemoteWorkerNonLifeCycleOpController", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PRemoteWorkerNonLifeCycleOpControllerParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PRemoteWorkerNonLifeCycleOpController::Msg_Error", OTHER);

            IPC::MessageReader reader__{
                    msg__,
                    this};

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

            }
            auto& aValue = *maybe__aValue;
            // Sentinel = 'aValue'
            if ((!(((&(reader__)))->ReadSentinel(135332447)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'ErrorValue'");
                return MsgValueError;
            }
            reader__.EndRead();
            mozilla::ipc::IPCResult __ok = (static_cast<RemoteWorkerNonLifeCycleOpControllerParent*>(this))->RecvError(std::move(aValue));
            if ((!(__ok))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                // Error handled in mozilla::ipc::IPCResult
                return MsgProcessingError;
            }

            return MsgProcessed;
        }
    case PRemoteWorkerNonLifeCycleOpController::Reply_ExecServiceWorkerOp__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PRemoteWorkerNonLifeCycleOpController", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PRemoteWorkerNonLifeCycleOpControllerParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }

            AUTO_PROFILER_LABEL("PRemoteWorkerNonLifeCycleOpController::Msg_ExecServiceWorkerOp", OTHER);


            return mAsyncCallbacks.GotReply(this, msg__);
        }
    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 PRemoteWorkerNonLifeCycleOpControllerParent::OnMessageReceived(
        const Message& msg__,
        UniquePtr<Message>& reply__) -> PRemoteWorkerNonLifeCycleOpControllerParent::Result
{
    MOZ_ASSERT_UNREACHABLE("message protocol not supported");
    return MsgNotKnown;
}



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

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

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

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

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

} // namespace IPC
