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


#include "mozilla/dom/PSerialManagerChild.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/dom/SerialManagerChild.h"
#include "mozilla/dom/SerialPortIPCTypes.h"

#include "mozilla/dom/PWindowGlobalChild.h"
#include "mozilla/dom/PSerialPortChild.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 PSerialManagerChild::Recv__delete__() -> mozilla::ipc::IPCResult
{
    return IPC_OK();
}

MOZ_IMPLICIT PSerialManagerChild::PSerialManagerChild() :
    mozilla::ipc::IRefCountedProtocol(kProtocolId, mozilla::ipc::ChildSide)
{
    MOZ_COUNT_CTOR(PSerialManagerChild);
}

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

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

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

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

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

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

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

auto PSerialManagerChild::SendRequestPort(
        mozilla::Span<IPCSerialPortFilter const> filters,
        mozilla::Span<nsString const> allowedBluetoothServiceClassIds,
        const bool& autoselect,
        mozilla::ipc::ResolveCallback<std::tuple<IPCRequestPortResult, Endpoint<::mozilla::dom::PSerialPortChild>>>&& aResolve,
        mozilla::ipc::RejectCallback&& aReject) -> void
{
    UniquePtr<IPC::Message> msg__ = PSerialManager::Msg_RequestPort(Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

    IPC::WriteParam((&(writer__)), filters);
    // Sentinel = 'filters'
    ((&(writer__)))->WriteSentinel(196674298);
    IPC::WriteParam((&(writer__)), allowedBluetoothServiceClassIds);
    // Sentinel = 'allowedBluetoothServiceClassIds'
    ((&(writer__)))->WriteSentinel(3390639238);
    IPC::WriteParam((&(writer__)), autoselect);
    // Sentinel = 'autoselect'
    ((&(writer__)))->WriteSentinel(392037434);


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

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

            }
            auto& result = *maybe__result;
            // Sentinel = 'result'
            if ((!((aReader)->ReadSentinel(153223840)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'IPCRequestPortResult'");
                return MsgValueError;
            }
            auto maybe__childEndpoint = IPC::ReadParam<Endpoint<::mozilla::dom::PSerialPortChild>>(aReader);
            if (!maybe__childEndpoint) {
                (aReader)->FatalError("Error deserializing 'Endpoint<::mozilla::dom::PSerialPortChild>'");
                return MsgValueError;

            }
            auto& childEndpoint = *maybe__childEndpoint;
            // Sentinel = 'childEndpoint'
            if ((!((aReader)->ReadSentinel(606864710)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'Endpoint<::mozilla::dom::PSerialPortChild>'");
                return MsgValueError;
            }


            aReader->EndRead();

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

auto PSerialManagerChild::SendRequestPort(
        mozilla::Span<IPCSerialPortFilter const> filters,
        mozilla::Span<nsString const> allowedBluetoothServiceClassIds,
        const bool& autoselect) -> RefPtr<RequestPortPromise>
{
    RefPtr<MozPromise<std::tuple<IPCRequestPortResult, Endpoint<::mozilla::dom::PSerialPortChild>>, ResponseRejectReason, true>::Private> promise__ = new MozPromise<std::tuple<IPCRequestPortResult, Endpoint<::mozilla::dom::PSerialPortChild>>, ResponseRejectReason, true>::Private(__func__);
    promise__->UseDirectTaskDispatch(__func__);
    SendRequestPort(std::forward<mozilla::Span<IPCSerialPortFilter const>>(filters), std::forward<mozilla::Span<nsString const>>(allowedBluetoothServiceClassIds), std::forward<const bool&>(autoselect), [promise__](std::tuple<IPCRequestPortResult, Endpoint<::mozilla::dom::PSerialPortChild>>&& aValue) {
        promise__->Resolve(std::move(aValue), __func__);
    }, [promise__](ResponseRejectReason&& aReason) {
        promise__->Reject(std::move(aReason), __func__);
    });
    return promise__;
}

auto PSerialManagerChild::SendSimulateDeviceConnection(
        const nsAString& deviceId,
        const nsAString& devicePath,
        const uint16_t& vendorId,
        const uint16_t& productId,
        const nsAString& bluetoothServiceClassId,
        mozilla::ipc::ResolveCallback<nsresult>&& aResolve,
        mozilla::ipc::RejectCallback&& aReject) -> void
{
    UniquePtr<IPC::Message> msg__ = PSerialManager::Msg_SimulateDeviceConnection(Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

    IPC::WriteParam((&(writer__)), deviceId);
    // Sentinel = 'deviceId'
    ((&(writer__)))->WriteSentinel(242025246);
    IPC::WriteParam((&(writer__)), devicePath);
    // Sentinel = 'devicePath'
    ((&(writer__)))->WriteSentinel(369886206);
    IPC::WriteParam((&(writer__)), vendorId);
    // Sentinel = 'vendorId'
    ((&(writer__)))->WriteSentinel(252379964);
    IPC::WriteParam((&(writer__)), productId);
    // Sentinel = 'productId'
    ((&(writer__)))->WriteSentinel(319882159);
    IPC::WriteParam((&(writer__)), bluetoothServiceClassId);
    // Sentinel = 'bluetoothServiceClassId'
    ((&(writer__)))->WriteSentinel(1912211787);


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

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

            }
            auto& rv = *maybe__rv;
            // Sentinel = 'rv'
            if ((!((aReader)->ReadSentinel(22806761)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'nsresult'");
                return MsgValueError;
            }


            aReader->EndRead();

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

auto PSerialManagerChild::SendSimulateDeviceConnection(
        const nsAString& deviceId,
        const nsAString& devicePath,
        const uint16_t& vendorId,
        const uint16_t& productId,
        const nsAString& bluetoothServiceClassId) -> RefPtr<SimulateDeviceConnectionPromise>
{
    RefPtr<MozPromise<nsresult, ResponseRejectReason, true>::Private> promise__ = new MozPromise<nsresult, ResponseRejectReason, true>::Private(__func__);
    promise__->UseDirectTaskDispatch(__func__);
    SendSimulateDeviceConnection(std::forward<const nsAString&>(deviceId), std::forward<const nsAString&>(devicePath), std::forward<const uint16_t&>(vendorId), std::forward<const uint16_t&>(productId), std::forward<const nsAString&>(bluetoothServiceClassId), [promise__](nsresult&& aValue) {
        promise__->Resolve(std::move(aValue), __func__);
    }, [promise__](ResponseRejectReason&& aReason) {
        promise__->Reject(std::move(aReason), __func__);
    });
    return promise__;
}

auto PSerialManagerChild::SendSimulateDeviceDisconnection(
        const nsAString& deviceId,
        mozilla::ipc::ResolveCallback<nsresult>&& aResolve,
        mozilla::ipc::RejectCallback&& aReject) -> void
{
    UniquePtr<IPC::Message> msg__ = PSerialManager::Msg_SimulateDeviceDisconnection(Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

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


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

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

            }
            auto& rv = *maybe__rv;
            // Sentinel = 'rv'
            if ((!((aReader)->ReadSentinel(22806761)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'nsresult'");
                return MsgValueError;
            }


            aReader->EndRead();

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

auto PSerialManagerChild::SendSimulateDeviceDisconnection(const nsAString& deviceId) -> RefPtr<SimulateDeviceDisconnectionPromise>
{
    RefPtr<MozPromise<nsresult, ResponseRejectReason, true>::Private> promise__ = new MozPromise<nsresult, ResponseRejectReason, true>::Private(__func__);
    promise__->UseDirectTaskDispatch(__func__);
    SendSimulateDeviceDisconnection(std::forward<const nsAString&>(deviceId), [promise__](nsresult&& aValue) {
        promise__->Resolve(std::move(aValue), __func__);
    }, [promise__](ResponseRejectReason&& aReason) {
        promise__->Reject(std::move(aReason), __func__);
    });
    return promise__;
}

auto PSerialManagerChild::SendRemoveAllMockDevices(
        mozilla::ipc::ResolveCallback<nsresult>&& aResolve,
        mozilla::ipc::RejectCallback&& aReject) -> void
{
    UniquePtr<IPC::Message> msg__ = PSerialManager::Msg_RemoveAllMockDevices(Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};



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

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

            }
            auto& rv = *maybe__rv;
            // Sentinel = 'rv'
            if ((!((aReader)->ReadSentinel(22806761)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'nsresult'");
                return MsgValueError;
            }


            aReader->EndRead();

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

auto PSerialManagerChild::SendRemoveAllMockDevices() -> RefPtr<RemoveAllMockDevicesPromise>
{
    RefPtr<MozPromise<nsresult, ResponseRejectReason, true>::Private> promise__ = new MozPromise<nsresult, ResponseRejectReason, true>::Private(__func__);
    promise__->UseDirectTaskDispatch(__func__);
    SendRemoveAllMockDevices([promise__](nsresult&& aValue) {
        promise__->Resolve(std::move(aValue), __func__);
    }, [promise__](ResponseRejectReason&& aReason) {
        promise__->Reject(std::move(aReason), __func__);
    });
    return promise__;
}

auto PSerialManagerChild::SendResetToDefaultMockDevices(
        mozilla::ipc::ResolveCallback<nsresult>&& aResolve,
        mozilla::ipc::RejectCallback&& aReject) -> void
{
    UniquePtr<IPC::Message> msg__ = PSerialManager::Msg_ResetToDefaultMockDevices(Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};



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

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

            }
            auto& rv = *maybe__rv;
            // Sentinel = 'rv'
            if ((!((aReader)->ReadSentinel(22806761)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'nsresult'");
                return MsgValueError;
            }


            aReader->EndRead();

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

auto PSerialManagerChild::SendResetToDefaultMockDevices() -> RefPtr<ResetToDefaultMockDevicesPromise>
{
    RefPtr<MozPromise<nsresult, ResponseRejectReason, true>::Private> promise__ = new MozPromise<nsresult, ResponseRejectReason, true>::Private(__func__);
    promise__->UseDirectTaskDispatch(__func__);
    SendResetToDefaultMockDevices([promise__](nsresult&& aValue) {
        promise__->Resolve(std::move(aValue), __func__);
    }, [promise__](ResponseRejectReason&& aReason) {
        promise__->Reject(std::move(aReason), __func__);
    });
    return promise__;
}

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

auto PSerialManagerChild::OnMessageReceived(const Message& msg__) -> PSerialManagerChild::Result
{
    if (!CanSend()) {
        if (mozilla::ipc::LoggingEnabledFor("PSerialManager", mozilla::ipc::ChildSide)) {
            mozilla::ipc::LogMessageForProtocol(
                "PSerialManagerChild",
                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 PSerialManager::Reply_RequestPort__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PSerialManager", mozilla::ipc::ChildSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PSerialManagerChild",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }

            AUTO_PROFILER_LABEL("PSerialManager::Msg_RequestPort", OTHER);


            return mAsyncCallbacks.GotReply(this, msg__);
        }
    case PSerialManager::Reply_SimulateDeviceConnection__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PSerialManager", mozilla::ipc::ChildSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PSerialManagerChild",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }

            AUTO_PROFILER_LABEL("PSerialManager::Msg_SimulateDeviceConnection", OTHER);


            return mAsyncCallbacks.GotReply(this, msg__);
        }
    case PSerialManager::Reply_SimulateDeviceDisconnection__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PSerialManager", mozilla::ipc::ChildSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PSerialManagerChild",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }

            AUTO_PROFILER_LABEL("PSerialManager::Msg_SimulateDeviceDisconnection", OTHER);


            return mAsyncCallbacks.GotReply(this, msg__);
        }
    case PSerialManager::Reply_RemoveAllMockDevices__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PSerialManager", mozilla::ipc::ChildSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PSerialManagerChild",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }

            AUTO_PROFILER_LABEL("PSerialManager::Msg_RemoveAllMockDevices", OTHER);


            return mAsyncCallbacks.GotReply(this, msg__);
        }
    case PSerialManager::Reply_ResetToDefaultMockDevices__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PSerialManager", mozilla::ipc::ChildSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PSerialManagerChild",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }

            AUTO_PROFILER_LABEL("PSerialManager::Msg_ResetToDefaultMockDevices", OTHER);


            return mAsyncCallbacks.GotReply(this, msg__);
        }
    case PSerialManager::Msg___delete____ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PSerialManager", mozilla::ipc::ChildSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PSerialManagerChild",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PSerialManager::Msg___delete__", OTHER);

            DoomSubtree();
            mozilla::ipc::IPCResult __ok = (static_cast<::mozilla::dom::SerialManagerChild*>(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 PSerialManagerChild::OnMessageReceived(
        const Message& msg__,
        UniquePtr<Message>& reply__) -> PSerialManagerChild::Result
{
    if (!CanSend()) {
        return MsgDropped;

    }
    return MsgNotKnown;
}



} // namespace dom
} // namespace mozilla
