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


#include "mozilla/media/PMediaSystemResourceManagerChild.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/media/MediaSystemResourceManagerChild.h"
#include "mozilla/media/MediaSystemResourceMessageUtils.h"

#include "mozilla/layers/PImageBridgeChild.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 media {


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

MOZ_IMPLICIT PMediaSystemResourceManagerChild::PMediaSystemResourceManagerChild() :
    mozilla::ipc::IProtocol(kProtocolId, mozilla::ipc::ChildSide)
{
    MOZ_COUNT_CTOR(PMediaSystemResourceManagerChild);
}

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

auto PMediaSystemResourceManagerChild::ActorAlloc() -> void
{
}

auto PMediaSystemResourceManagerChild::ActorDealloc() -> void
{
    if (Manager()) {
        Manager()->DeallocManagee(kProtocolId, this);
    }
}

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

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

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

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

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

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

auto PMediaSystemResourceManagerChild::SendAcquire(
        const uint32_t& aId,
        const MediaSystemResourceType& aResourceType,
        const bool& aWillWait) -> bool
{
    UniquePtr<IPC::Message> msg__ = PMediaSystemResourceManager::Msg_Acquire(Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

    IPC::WriteParam((&(writer__)), aId);
    // Sentinel = 'aId'
    ((&(writer__)))->WriteSentinel(35389711);
    IPC::WriteParam((&(writer__)), aResourceType);
    // Sentinel = 'aResourceType'
    ((&(writer__)))->WriteSentinel(614401356);
    IPC::WriteParam((&(writer__)), aWillWait);
    // Sentinel = 'aWillWait'
    ((&(writer__)))->WriteSentinel(292684687);


    if (mozilla::ipc::LoggingEnabledFor("PMediaSystemResourceManager", mozilla::ipc::ChildSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PMediaSystemResourceManagerChild",
            this->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Sending ",
            msg__->type(),
            mozilla::ipc::MessageDirection::eSending);
    }
    AUTO_PROFILER_LABEL("PMediaSystemResourceManager::Msg_Acquire", OTHER);

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

auto PMediaSystemResourceManagerChild::SendRelease(const uint32_t& aId) -> bool
{
    UniquePtr<IPC::Message> msg__ = PMediaSystemResourceManager::Msg_Release(Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

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


    if (mozilla::ipc::LoggingEnabledFor("PMediaSystemResourceManager", mozilla::ipc::ChildSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PMediaSystemResourceManagerChild",
            this->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Sending ",
            msg__->type(),
            mozilla::ipc::MessageDirection::eSending);
    }
    AUTO_PROFILER_LABEL("PMediaSystemResourceManager::Msg_Release", OTHER);

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

auto PMediaSystemResourceManagerChild::SendRemoveResourceManager() -> bool
{
    UniquePtr<IPC::Message> msg__ = PMediaSystemResourceManager::Msg_RemoveResourceManager(Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};



    if (mozilla::ipc::LoggingEnabledFor("PMediaSystemResourceManager", mozilla::ipc::ChildSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PMediaSystemResourceManagerChild",
            this->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Sending ",
            msg__->type(),
            mozilla::ipc::MessageDirection::eSending);
    }
    AUTO_PROFILER_LABEL("PMediaSystemResourceManager::Msg_RemoveResourceManager", OTHER);

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

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

auto PMediaSystemResourceManagerChild::OnMessageReceived(const Message& msg__) -> PMediaSystemResourceManagerChild::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 PMediaSystemResourceManager::Msg_Response__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PMediaSystemResourceManager", mozilla::ipc::ChildSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PMediaSystemResourceManagerChild",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PMediaSystemResourceManager::Msg_Response", OTHER);

            IPC::MessageReader reader__{
                    msg__,
                    this};

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

            }
            auto& aId = *maybe__aId;
            // Sentinel = 'aId'
            if ((!(((&(reader__)))->ReadSentinel(35389711)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'uint32_t'");
                return MsgValueError;
            }
            auto maybe__aSuccess = IPC::ReadParam<bool>((&(reader__)));
            if (!maybe__aSuccess) {
                FatalError("Error deserializing 'bool'");
                return MsgValueError;

            }
            auto& aSuccess = *maybe__aSuccess;
            // Sentinel = 'aSuccess'
            if ((!(((&(reader__)))->ReadSentinel(236323643)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'bool'");
                return MsgValueError;
            }
            reader__.EndRead();
            mozilla::ipc::IPCResult __ok = (static_cast<MediaSystemResourceManagerChild*>(this))->RecvResponse(std::move(aId), std::move(aSuccess));
            if ((!(__ok))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                // Error handled in mozilla::ipc::IPCResult
                return MsgProcessingError;
            }

            return MsgProcessed;
        }
    case PMediaSystemResourceManager::Msg___delete____ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PMediaSystemResourceManager", mozilla::ipc::ChildSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PMediaSystemResourceManagerChild",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PMediaSystemResourceManager::Msg___delete__", OTHER);

            mozilla::ipc::IPCResult __ok = (static_cast<MediaSystemResourceManagerChild*>(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;
        }
    default:
        return MsgNotKnown;
    }
}

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



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

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

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

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

        return {};
    }
    return static_cast<::mozilla::media::PMediaSystemResourceManagerChild*>(actor);
}

} // namespace IPC
