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


#include "mozilla/gmp/PGMPContentChild.h"
#include "GMPContentChild.h"
#include "mozilla/ProfilerLabels.h"

#include "mozilla/gmp/PGMPVideoDecoderChild.h"
#include "mozilla/gmp/PGMPVideoEncoderChild.h"
#include "mozilla/gmp/PChromiumCDMChild.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 gmp {


auto PGMPContentChild::RecvPGMPVideoDecoderConstructor(PGMPVideoDecoderChild* actor) -> mozilla::ipc::IPCResult
{
    return IPC_OK();
}

auto PGMPContentChild::RecvPGMPVideoEncoderConstructor(PGMPVideoEncoderChild* actor) -> mozilla::ipc::IPCResult
{
    return IPC_OK();
}

auto PGMPContentChild::RecvPChromiumCDMConstructor(
        PChromiumCDMChild* actor,
        const nsACString& aKeySystem) -> mozilla::ipc::IPCResult
{
    return IPC_OK();
}

auto PGMPContentChild::ProcessingError(
        Result aCode,
        const char* aReason) -> void
{
}

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

MOZ_IMPLICIT PGMPContentChild::PGMPContentChild() :
    mozilla::ipc::IToplevelProtocol("PGMPContentChild", kProtocolId, mozilla::ipc::ChildSide)
{
    MOZ_COUNT_CTOR(PGMPContentChild);
}

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

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

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

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

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

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

auto PGMPContentChild::ManagedPGMPVideoDecoderChild(nsTArray<PGMPVideoDecoderChild*>& aArr) const -> void
{
    mManagedPGMPVideoDecoderChild.ToArray(aArr);
}

auto PGMPContentChild::ManagedPGMPVideoDecoderChild() const -> const ManagedContainer<PGMPVideoDecoderChild>&
{
    return mManagedPGMPVideoDecoderChild;
}

auto PGMPContentChild::ManagedPGMPVideoEncoderChild(nsTArray<PGMPVideoEncoderChild*>& aArr) const -> void
{
    mManagedPGMPVideoEncoderChild.ToArray(aArr);
}

auto PGMPContentChild::ManagedPGMPVideoEncoderChild() const -> const ManagedContainer<PGMPVideoEncoderChild>&
{
    return mManagedPGMPVideoEncoderChild;
}

auto PGMPContentChild::ManagedPChromiumCDMChild(nsTArray<PChromiumCDMChild*>& aArr) const -> void
{
    mManagedPChromiumCDMChild.ToArray(aArr);
}

auto PGMPContentChild::ManagedPChromiumCDMChild() const -> const ManagedContainer<PChromiumCDMChild>&
{
    return mManagedPChromiumCDMChild;
}

auto PGMPContentChild::ManagedProtocolIds() const -> mozilla::Span<mozilla::ipc::ProtocolId const>
{
    static constexpr ::mozilla::ipc::ProtocolId sIds[] = {
        PGMPVideoDecoderMsgStart,
        PGMPVideoEncoderMsgStart,
        PChromiumCDMMsgStart
    };
    return sIds;
}

auto PGMPContentChild::GetManagedActors(mozilla::ipc::ProtocolId aProtocol) -> UntypedManagedContainer*
{
    switch (aProtocol) {
    case PGMPVideoDecoderMsgStart:
        return (&(mManagedPGMPVideoDecoderChild));
    case PGMPVideoEncoderMsgStart:
        return (&(mManagedPGMPVideoEncoderChild));
    case PChromiumCDMMsgStart:
        return (&(mManagedPChromiumCDMChild));
    default:
        return nullptr;
    }
}

auto PGMPContentChild::OpenPGMPVideoDecoderEndpoint(PGMPVideoDecoderChild* aActor) -> ManagedEndpoint<PGMPVideoDecoderParent>
{
    if (!aActor) {
        NS_WARNING("Cannot bind null PGMPVideoDecoderChild actor");
        return ManagedEndpoint<PGMPVideoDecoderParent>();
    }

    if (!aActor->SetManagerAndRegister(this)) {
        NS_WARNING("Failed to bind PGMPVideoDecoderChild actor");
        return ManagedEndpoint<PGMPVideoDecoderParent>();
    }

    // Mark our actor as awaiting the other side to be bound. This will
    // be cleared when a `MANAGED_ENDPOINT_{DROPPED,BOUND}` message is
    // received.
    aActor->mAwaitingManagedEndpointBind = true;
    return ManagedEndpoint<PGMPVideoDecoderParent>(mozilla::ipc::PrivateIPDLInterface(), aActor);
}

auto PGMPContentChild::BindPGMPVideoDecoderEndpoint(
        ManagedEndpoint<PGMPVideoDecoderChild> aEndpoint,
        PGMPVideoDecoderChild* aActor) -> bool
{
    return aEndpoint.Bind(mozilla::ipc::PrivateIPDLInterface(), aActor, this);
}

auto PGMPContentChild::OpenPGMPVideoEncoderEndpoint(PGMPVideoEncoderChild* aActor) -> ManagedEndpoint<PGMPVideoEncoderParent>
{
    if (!aActor) {
        NS_WARNING("Cannot bind null PGMPVideoEncoderChild actor");
        return ManagedEndpoint<PGMPVideoEncoderParent>();
    }

    if (!aActor->SetManagerAndRegister(this)) {
        NS_WARNING("Failed to bind PGMPVideoEncoderChild actor");
        return ManagedEndpoint<PGMPVideoEncoderParent>();
    }

    // Mark our actor as awaiting the other side to be bound. This will
    // be cleared when a `MANAGED_ENDPOINT_{DROPPED,BOUND}` message is
    // received.
    aActor->mAwaitingManagedEndpointBind = true;
    return ManagedEndpoint<PGMPVideoEncoderParent>(mozilla::ipc::PrivateIPDLInterface(), aActor);
}

auto PGMPContentChild::BindPGMPVideoEncoderEndpoint(
        ManagedEndpoint<PGMPVideoEncoderChild> aEndpoint,
        PGMPVideoEncoderChild* aActor) -> bool
{
    return aEndpoint.Bind(mozilla::ipc::PrivateIPDLInterface(), aActor, this);
}

auto PGMPContentChild::OpenPChromiumCDMEndpoint(PChromiumCDMChild* aActor) -> ManagedEndpoint<PChromiumCDMParent>
{
    if (!aActor) {
        NS_WARNING("Cannot bind null PChromiumCDMChild actor");
        return ManagedEndpoint<PChromiumCDMParent>();
    }

    if (!aActor->SetManagerAndRegister(this)) {
        NS_WARNING("Failed to bind PChromiumCDMChild actor");
        return ManagedEndpoint<PChromiumCDMParent>();
    }

    // Mark our actor as awaiting the other side to be bound. This will
    // be cleared when a `MANAGED_ENDPOINT_{DROPPED,BOUND}` message is
    // received.
    aActor->mAwaitingManagedEndpointBind = true;
    return ManagedEndpoint<PChromiumCDMParent>(mozilla::ipc::PrivateIPDLInterface(), aActor);
}

auto PGMPContentChild::BindPChromiumCDMEndpoint(
        ManagedEndpoint<PChromiumCDMChild> aEndpoint,
        PChromiumCDMChild* aActor) -> bool
{
    return aEndpoint.Bind(mozilla::ipc::PrivateIPDLInterface(), aActor, this);
}

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

auto PGMPContentChild::OnMessageReceived(const Message& msg__) -> PGMPContentChild::Result
{
    IPC::Message::routeid_t route__ = msg__.routing_id();
    if (MSG_ROUTING_CONTROL != route__) {
        IProtocol* routed__ = Lookup(route__);
        if (!routed__ || !routed__->GetLifecycleProxy()) {
            if (mozilla::ipc::LoggingEnabledFor("PGMPContent", mozilla::ipc::ChildSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PGMPContentChild",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Ignored message for dead actor",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eSending);
            }
            return MsgProcessed;

        }

        RefPtr<mozilla::ipc::ActorLifecycleProxy> proxy__ =
            routed__->GetLifecycleProxy();
        return proxy__->Get()->OnMessageReceived(msg__);
    }

    switch (msg__.type()) {
    case PGMPContent::Msg_PGMPVideoDecoderConstructor__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PGMPContent", mozilla::ipc::ChildSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PGMPContentChild",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PGMPContent::Msg_PGMPVideoDecoderConstructor", OTHER);

            IPC::MessageReader reader__{
                    msg__,
                    this};

            auto maybe__actorid__ = IPC::ReadParam<mozilla::ipc::ActorId>((&(reader__)));
            if (!maybe__actorid__) {
                FatalError("Error deserializing 'mozilla::ipc::ActorId'");
                return MsgValueError;

            }
            auto& actorid__ = *maybe__actorid__;
            // Sentinel = 'actorid'
            if ((!(((&(reader__)))->ReadSentinel(193725159)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'mozilla::ipc::ActorId'");
                return MsgValueError;
            }
            reader__.EndRead();
            RefPtr<PGMPVideoDecoderChild> actor = (static_cast<GMPContentChild*>(this))->AllocPGMPVideoDecoderChild();
            if (!actor) {
                NS_WARNING("Cannot bind null PGMPVideoDecoderChild actor");
                return MsgValueError;
            }

            if (!actor->SetManagerAndRegister(this, actorid__)) {
                NS_WARNING("Failed to bind PGMPVideoDecoderChild actor");
                return MsgValueError;
            }

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

            return MsgProcessed;
        }
    case PGMPContent::Msg_PGMPVideoEncoderConstructor__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PGMPContent", mozilla::ipc::ChildSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PGMPContentChild",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PGMPContent::Msg_PGMPVideoEncoderConstructor", OTHER);

            IPC::MessageReader reader__{
                    msg__,
                    this};

            auto maybe__actorid__ = IPC::ReadParam<mozilla::ipc::ActorId>((&(reader__)));
            if (!maybe__actorid__) {
                FatalError("Error deserializing 'mozilla::ipc::ActorId'");
                return MsgValueError;

            }
            auto& actorid__ = *maybe__actorid__;
            // Sentinel = 'actorid'
            if ((!(((&(reader__)))->ReadSentinel(193725159)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'mozilla::ipc::ActorId'");
                return MsgValueError;
            }
            reader__.EndRead();
            RefPtr<PGMPVideoEncoderChild> actor = (static_cast<GMPContentChild*>(this))->AllocPGMPVideoEncoderChild();
            if (!actor) {
                NS_WARNING("Cannot bind null PGMPVideoEncoderChild actor");
                return MsgValueError;
            }

            if (!actor->SetManagerAndRegister(this, actorid__)) {
                NS_WARNING("Failed to bind PGMPVideoEncoderChild actor");
                return MsgValueError;
            }

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

            return MsgProcessed;
        }
    case PGMPContent::Msg_PChromiumCDMConstructor__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PGMPContent", mozilla::ipc::ChildSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PGMPContentChild",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PGMPContent::Msg_PChromiumCDMConstructor", OTHER);

            IPC::MessageReader reader__{
                    msg__,
                    this};

            auto maybe__actorid__ = IPC::ReadParam<mozilla::ipc::ActorId>((&(reader__)));
            if (!maybe__actorid__) {
                FatalError("Error deserializing 'mozilla::ipc::ActorId'");
                return MsgValueError;

            }
            auto& actorid__ = *maybe__actorid__;
            // Sentinel = 'actorid'
            if ((!(((&(reader__)))->ReadSentinel(193725159)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'mozilla::ipc::ActorId'");
                return MsgValueError;
            }
            auto maybe__aKeySystem = IPC::ReadParam<nsCString>((&(reader__)));
            if (!maybe__aKeySystem) {
                FatalError("Error deserializing 'nsCString'");
                return MsgValueError;

            }
            auto& aKeySystem = *maybe__aKeySystem;
            // Sentinel = 'aKeySystem'
            if ((!(((&(reader__)))->ReadSentinel(362546192)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'nsCString'");
                return MsgValueError;
            }
            reader__.EndRead();
            RefPtr<PChromiumCDMChild> actor = (static_cast<GMPContentChild*>(this))->AllocPChromiumCDMChild(aKeySystem);
            if (!actor) {
                NS_WARNING("Cannot bind null PChromiumCDMChild actor");
                return MsgValueError;
            }

            if (!actor->SetManagerAndRegister(this, actorid__)) {
                NS_WARNING("Failed to bind PChromiumCDMChild actor");
                return MsgValueError;
            }

            mozilla::ipc::IPCResult __ok = (static_cast<GMPContentChild*>(this))->RecvPChromiumCDMConstructor(actor, std::move(aKeySystem));
            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 PGMPContentChild::OnMessageReceived(
        const Message& msg__,
        UniquePtr<Message>& reply__) -> PGMPContentChild::Result
{
    IPC::Message::routeid_t route__ = msg__.routing_id();
    if (MSG_ROUTING_CONTROL != route__) {
        IProtocol* routed__ = Lookup(route__);
        if (!routed__ || !routed__->GetLifecycleProxy()) {
            return MsgDropped;

        }

        RefPtr<mozilla::ipc::ActorLifecycleProxy> proxy__ =
            routed__->GetLifecycleProxy();
        return proxy__->Get()->OnMessageReceived(msg__, reply__);
    }

    return MsgNotKnown;
}



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

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

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

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

        return {};
    }
    return static_cast<::mozilla::gmp::PGMPContentChild*>(actor);
}

} // namespace IPC
