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


#include "mozilla/gmp/PGMPServiceParent.h"
#include "GMPMessageUtils.h"
#include "mozilla/ProfilerLabels.h"

#include "mozilla/gmp/PGMPContentParent.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 PGMPServiceParent::ProcessingError(
        Result aCode,
        const char* aReason) -> void
{
}

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

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

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

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

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

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

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

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

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

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

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

auto PGMPServiceParent::SendBeginShutdown() -> bool
{
    UniquePtr<IPC::Message> msg__ = PGMPService::Msg_BeginShutdown(MSG_ROUTING_CONTROL);
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};



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

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

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

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

    }
    switch (msg__.type()) {
    case PGMPService::Msg_LaunchGMP__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PGMPService", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PGMPServiceParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PGMPService::Msg_LaunchGMP", OTHER);

            IPC::MessageReader reader__{
                    msg__,
                    this};

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

            }
            auto& nodeIdVariant = *maybe__nodeIdVariant;
            // Sentinel = 'nodeIdVariant'
            if ((!(((&(reader__)))->ReadSentinel(599196969)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'NodeIdVariant'");
                return MsgValueError;
            }
            auto maybe__api = IPC::ReadParam<nsCString>((&(reader__)));
            if (!maybe__api) {
                FatalError("Error deserializing 'nsCString'");
                return MsgValueError;

            }
            auto& api = *maybe__api;
            // Sentinel = 'api'
            if ((!(((&(reader__)))->ReadSentinel(40829243)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'nsCString'");
                return MsgValueError;
            }
            auto maybe__tags = IPC::ReadParam<nsTArray<nsCString>>((&(reader__)));
            if (!maybe__tags) {
                FatalError("Error deserializing 'nsCString[]'");
                return MsgValueError;

            }
            auto& tags = *maybe__tags;
            // Sentinel = 'tags'
            if ((!(((&(reader__)))->ReadSentinel(70779312)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'nsCString[]'");
                return MsgValueError;
            }
            auto maybe__alreadyBridgedTo = IPC::ReadParam<nsTArray<ProcessId>>((&(reader__)));
            if (!maybe__alreadyBridgedTo) {
                FatalError("Error deserializing 'ProcessId[]'");
                return MsgValueError;

            }
            auto& alreadyBridgedTo = *maybe__alreadyBridgedTo;
            // Sentinel = 'alreadyBridgedTo'
            if ((!(((&(reader__)))->ReadSentinel(911607383)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'ProcessId[]'");
                return MsgValueError;
            }
            reader__.EndRead();
            mozilla::ipc::ActorId id__ = MSG_ROUTING_CONTROL;
            UniquePtr<IPC::Message> reply__(PGMPService::Reply_LaunchGMP(id__));
            reply__->set_seqno(msg__.seqno());

            RefPtr<mozilla::ipc::IPDLResolverInner> resolver__ =
                new mozilla::ipc::IPDLResolverInner(std::move(reply__), this);

            LaunchGMPResolver resolver = [resolver__ = std::move(resolver__)](GMPLaunchResult&& aParam) {
                resolver__->Resolve([&] (IPC::Message* reply__, IProtocol* self__) {
                    IPC::MessageWriter writer__(*reply__, self__);
                    IPC::WriteParam((&(writer__)), std::move(aParam));
                    // Sentinel = 'aResult'
                    ((&(writer__)))->WriteSentinel(185205473);

                    if (mozilla::ipc::LoggingEnabledFor("PGMPService", mozilla::ipc::ParentSide)) {
                        mozilla::ipc::LogMessageForProtocol(
                            "PGMPServiceParent",
                            self__->ToplevelProtocol()->OtherPidMaybeInvalid(),
                            "Sending reply ",
                            reply__->type(),
                            mozilla::ipc::MessageDirection::eSending);
                    }

                });
            };
            mozilla::ipc::IPCResult __ok = (this)->RecvLaunchGMP(std::move(nodeIdVariant), std::move(api), std::move(tags), std::move(alreadyBridgedTo), std::move(resolver));
            if ((!(__ok))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                // Error handled in mozilla::ipc::IPCResult
                return MsgProcessingError;
            }

            return MsgProcessed;
        }
    case PGMPService::Msg_GetGMPNodeId__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PGMPService", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PGMPServiceParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PGMPService::Msg_GetGMPNodeId", OTHER);

            IPC::MessageReader reader__{
                    msg__,
                    this};

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

            }
            auto& origin = *maybe__origin;
            // Sentinel = 'origin'
            if ((!(((&(reader__)))->ReadSentinel(150143625)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'nsString'");
                return MsgValueError;
            }
            auto maybe__topLevelOrigin = IPC::ReadParam<nsString>((&(reader__)));
            if (!maybe__topLevelOrigin) {
                FatalError("Error deserializing 'nsString'");
                return MsgValueError;

            }
            auto& topLevelOrigin = *maybe__topLevelOrigin;
            // Sentinel = 'topLevelOrigin'
            if ((!(((&(reader__)))->ReadSentinel(720242100)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'nsString'");
                return MsgValueError;
            }
            auto maybe__gmpName = IPC::ReadParam<nsString>((&(reader__)));
            if (!maybe__gmpName) {
                FatalError("Error deserializing 'nsString'");
                return MsgValueError;

            }
            auto& gmpName = *maybe__gmpName;
            // Sentinel = 'gmpName'
            if ((!(((&(reader__)))->ReadSentinel(187695814)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'nsString'");
                return MsgValueError;
            }
            reader__.EndRead();
            mozilla::ipc::ActorId id__ = MSG_ROUTING_CONTROL;
            UniquePtr<IPC::Message> reply__(PGMPService::Reply_GetGMPNodeId(id__));
            reply__->set_seqno(msg__.seqno());

            RefPtr<mozilla::ipc::IPDLResolverInner> resolver__ =
                new mozilla::ipc::IPDLResolverInner(std::move(reply__), this);

            GetGMPNodeIdResolver resolver = [resolver__ = std::move(resolver__)](const nsACString& aParam) {
                resolver__->Resolve([&] (IPC::Message* reply__, IProtocol* self__) {
                    IPC::MessageWriter writer__(*reply__, self__);
                    IPC::WriteParam((&(writer__)), aParam);
                    // Sentinel = 'id'
                    ((&(writer__)))->WriteSentinel(20447438);

                    if (mozilla::ipc::LoggingEnabledFor("PGMPService", mozilla::ipc::ParentSide)) {
                        mozilla::ipc::LogMessageForProtocol(
                            "PGMPServiceParent",
                            self__->ToplevelProtocol()->OtherPidMaybeInvalid(),
                            "Sending reply ",
                            reply__->type(),
                            mozilla::ipc::MessageDirection::eSending);
                    }

                });
            };
            mozilla::ipc::IPCResult __ok = (this)->RecvGetGMPNodeId(std::move(origin), std::move(topLevelOrigin), std::move(gmpName), std::move(resolver));
            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 PGMPServiceParent::OnMessageReceived(
        const Message& msg__,
        UniquePtr<Message>& reply__) -> PGMPServiceParent::Result
{
    if (!CanSend()) {
        return MsgDropped;

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



} // namespace gmp
} // namespace mozilla
