// Copyright (c) ZeroC, Inc.

// slice2cpp version 3.8.1
// <auto-generated>Generated from Slice file 'LocatorRegistry.ice'.</auto-generated>

#ifndef ICE_API_EXPORTS
#   define ICE_API_EXPORTS
#endif
#define ICE_BUILDING_GENERATED_CODE

#include "Ice/LocatorRegistry.h"
#include <Ice/Process.h>
#include <Ice/AsyncResponseHandler.h>
#include <Ice/DefaultSliceLoader.h>
#include <Ice/OutgoingAsync.h>
#include <algorithm>
#include <array>

#if defined(_MSC_VER)
#   pragma warning(disable : 4458) // declaration of ... hides class member
#   pragma warning(disable : 4996) // ... was declared deprecated
#elif defined(__clang__)
#   pragma clang diagnostic ignored "-Wshadow"
#   pragma clang diagnostic ignored "-Wdeprecated-declarations"
#elif defined(__GNUC__)
#   pragma GCC diagnostic ignored "-Wshadow"
#   pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif

#ifndef ICE_DISABLE_VERSION
#   if ICE_INT_VERSION / 100 != 308
#       error Ice version mismatch!
#   endif
#   if ICE_INT_VERSION % 100 >= 50
#       error Beta header file detected
#   endif
#   if ICE_INT_VERSION % 100 < 1
#       error Ice patch level mismatch!
#   endif
#endif

namespace
{
    const IceInternal::ExceptionInit<::Ice::AdapterAlreadyActiveException> iceC_Ice_AdapterAlreadyActiveException_init;
    const IceInternal::ExceptionInit<::Ice::InvalidReplicaGroupIdException> iceC_Ice_InvalidReplicaGroupIdException_init;
    const IceInternal::ExceptionInit<::Ice::ServerNotFoundException> iceC_Ice_ServerNotFoundException_init;
}

Ice::LocatorRegistryPrx::~LocatorRegistryPrx() = default;

void
Ice::LocatorRegistryPrx::setAdapterDirectProxy(std::string_view iceP_id, const std::optional<Ice::ObjectPrx>& iceP_proxy, const Ice::Context& context) const
{
    IceInternal::makePromiseOutgoing<void>(true, this, &LocatorRegistryPrx::_iceI_setAdapterDirectProxy, iceP_id, iceP_proxy, context).get();
}

std::future<void>
Ice::LocatorRegistryPrx::setAdapterDirectProxyAsync(std::string_view iceP_id, const std::optional<Ice::ObjectPrx>& iceP_proxy, const Ice::Context& context) const
{
    return IceInternal::makePromiseOutgoing<void>(false, this, &LocatorRegistryPrx::_iceI_setAdapterDirectProxy, iceP_id, iceP_proxy, context);
}

std::function<void()>
Ice::LocatorRegistryPrx::setAdapterDirectProxyAsync(std::string_view iceP_id, const std::optional<Ice::ObjectPrx>& iceP_proxy, std::function<void()> response, std::function<void(std::exception_ptr)> exception, std::function<void(bool)> sent, const Ice::Context& context) const
{
    return IceInternal::makeLambdaOutgoing<void>(std::move(response), std::move(exception), std::move(sent), this, &Ice::LocatorRegistryPrx::_iceI_setAdapterDirectProxy, iceP_id, iceP_proxy, context);
}

void
Ice::LocatorRegistryPrx::_iceI_setAdapterDirectProxy(const std::shared_ptr<IceInternal::OutgoingAsyncT<void>>& outAsync, std::string_view iceP_id, const std::optional<Ice::ObjectPrx>& iceP_proxy, const Ice::Context& context) const
{
    static constexpr std::string_view operationName = "setAdapterDirectProxy";

    _checkTwowayOnly(operationName);
    outAsync->invoke(
        operationName,
        Ice::OperationMode::Idempotent,
        std::nullopt,
        context,
        [&](Ice::OutputStream* ostr)
        {
            ostr->writeAll(iceP_id, iceP_proxy);
        },
        [](const Ice::UserException& ex)
        {
            try
            {
                ex.ice_throw();
            }
            catch (const AdapterNotFoundException&)
            {
                throw;
            }
            catch (const AdapterAlreadyActiveException&)
            {
                throw;
            }
            catch (const Ice::UserException&)
            {
            }
        });
}

void
Ice::LocatorRegistryPrx::setReplicatedAdapterDirectProxy(std::string_view iceP_adapterId, std::string_view iceP_replicaGroupId, const std::optional<Ice::ObjectPrx>& iceP_proxy, const Ice::Context& context) const
{
    IceInternal::makePromiseOutgoing<void>(true, this, &LocatorRegistryPrx::_iceI_setReplicatedAdapterDirectProxy, iceP_adapterId, iceP_replicaGroupId, iceP_proxy, context).get();
}

std::future<void>
Ice::LocatorRegistryPrx::setReplicatedAdapterDirectProxyAsync(std::string_view iceP_adapterId, std::string_view iceP_replicaGroupId, const std::optional<Ice::ObjectPrx>& iceP_proxy, const Ice::Context& context) const
{
    return IceInternal::makePromiseOutgoing<void>(false, this, &LocatorRegistryPrx::_iceI_setReplicatedAdapterDirectProxy, iceP_adapterId, iceP_replicaGroupId, iceP_proxy, context);
}

std::function<void()>
Ice::LocatorRegistryPrx::setReplicatedAdapterDirectProxyAsync(std::string_view iceP_adapterId, std::string_view iceP_replicaGroupId, const std::optional<Ice::ObjectPrx>& iceP_proxy, std::function<void()> response, std::function<void(std::exception_ptr)> exception, std::function<void(bool)> sent, const Ice::Context& context) const
{
    return IceInternal::makeLambdaOutgoing<void>(std::move(response), std::move(exception), std::move(sent), this, &Ice::LocatorRegistryPrx::_iceI_setReplicatedAdapterDirectProxy, iceP_adapterId, iceP_replicaGroupId, iceP_proxy, context);
}

void
Ice::LocatorRegistryPrx::_iceI_setReplicatedAdapterDirectProxy(const std::shared_ptr<IceInternal::OutgoingAsyncT<void>>& outAsync, std::string_view iceP_adapterId, std::string_view iceP_replicaGroupId, const std::optional<Ice::ObjectPrx>& iceP_proxy, const Ice::Context& context) const
{
    static constexpr std::string_view operationName = "setReplicatedAdapterDirectProxy";

    _checkTwowayOnly(operationName);
    outAsync->invoke(
        operationName,
        Ice::OperationMode::Idempotent,
        std::nullopt,
        context,
        [&](Ice::OutputStream* ostr)
        {
            ostr->writeAll(iceP_adapterId, iceP_replicaGroupId, iceP_proxy);
        },
        [](const Ice::UserException& ex)
        {
            try
            {
                ex.ice_throw();
            }
            catch (const AdapterNotFoundException&)
            {
                throw;
            }
            catch (const AdapterAlreadyActiveException&)
            {
                throw;
            }
            catch (const InvalidReplicaGroupIdException&)
            {
                throw;
            }
            catch (const Ice::UserException&)
            {
            }
        });
}

void
Ice::LocatorRegistryPrx::setServerProcessProxy(std::string_view iceP_id, const std::optional<ProcessPrx>& iceP_proxy, const Ice::Context& context) const
{
    IceInternal::makePromiseOutgoing<void>(true, this, &LocatorRegistryPrx::_iceI_setServerProcessProxy, iceP_id, iceP_proxy, context).get();
}

std::future<void>
Ice::LocatorRegistryPrx::setServerProcessProxyAsync(std::string_view iceP_id, const std::optional<ProcessPrx>& iceP_proxy, const Ice::Context& context) const
{
    return IceInternal::makePromiseOutgoing<void>(false, this, &LocatorRegistryPrx::_iceI_setServerProcessProxy, iceP_id, iceP_proxy, context);
}

std::function<void()>
Ice::LocatorRegistryPrx::setServerProcessProxyAsync(std::string_view iceP_id, const std::optional<ProcessPrx>& iceP_proxy, std::function<void()> response, std::function<void(std::exception_ptr)> exception, std::function<void(bool)> sent, const Ice::Context& context) const
{
    return IceInternal::makeLambdaOutgoing<void>(std::move(response), std::move(exception), std::move(sent), this, &Ice::LocatorRegistryPrx::_iceI_setServerProcessProxy, iceP_id, iceP_proxy, context);
}

void
Ice::LocatorRegistryPrx::_iceI_setServerProcessProxy(const std::shared_ptr<IceInternal::OutgoingAsyncT<void>>& outAsync, std::string_view iceP_id, const std::optional<ProcessPrx>& iceP_proxy, const Ice::Context& context) const
{
    static constexpr std::string_view operationName = "setServerProcessProxy";

    _checkTwowayOnly(operationName);
    outAsync->invoke(
        operationName,
        Ice::OperationMode::Idempotent,
        std::nullopt,
        context,
        [&](Ice::OutputStream* ostr)
        {
            ostr->writeAll(iceP_id, iceP_proxy);
        },
        [](const Ice::UserException& ex)
        {
            try
            {
                ex.ice_throw();
            }
            catch (const ServerNotFoundException&)
            {
                throw;
            }
            catch (const Ice::UserException&)
            {
            }
        });
}

const char*
Ice::LocatorRegistryPrx::ice_staticId() noexcept
{
    return "::Ice::LocatorRegistry";
}

const char*
Ice::AdapterAlreadyActiveException::ice_staticId() noexcept
{
    return "::Ice::AdapterAlreadyActiveException";
}

const char*
Ice::AdapterAlreadyActiveException::ice_id() const noexcept
{
    return ice_staticId();
}

void
Ice::AdapterAlreadyActiveException::ice_throw() const
{
    throw *this;
}

void
Ice::AdapterAlreadyActiveException::_writeImpl(Ice::OutputStream* ostr) const
{
    ostr->startSlice(ice_staticId(), -1, true);
    ostr->endSlice();
}

void
Ice::AdapterAlreadyActiveException::_readImpl(Ice::InputStream* istr)
{
    istr->startSlice();
    istr->endSlice();
}

const char*
Ice::InvalidReplicaGroupIdException::ice_staticId() noexcept
{
    return "::Ice::InvalidReplicaGroupIdException";
}

const char*
Ice::InvalidReplicaGroupIdException::ice_id() const noexcept
{
    return ice_staticId();
}

void
Ice::InvalidReplicaGroupIdException::ice_throw() const
{
    throw *this;
}

void
Ice::InvalidReplicaGroupIdException::_writeImpl(Ice::OutputStream* ostr) const
{
    ostr->startSlice(ice_staticId(), -1, true);
    ostr->endSlice();
}

void
Ice::InvalidReplicaGroupIdException::_readImpl(Ice::InputStream* istr)
{
    istr->startSlice();
    istr->endSlice();
}

const char*
Ice::ServerNotFoundException::ice_staticId() noexcept
{
    return "::Ice::ServerNotFoundException";
}

const char*
Ice::ServerNotFoundException::ice_id() const noexcept
{
    return ice_staticId();
}

void
Ice::ServerNotFoundException::ice_throw() const
{
    throw *this;
}

void
Ice::ServerNotFoundException::_writeImpl(Ice::OutputStream* ostr) const
{
    ostr->startSlice(ice_staticId(), -1, true);
    ostr->endSlice();
}

void
Ice::ServerNotFoundException::_readImpl(Ice::InputStream* istr)
{
    istr->startSlice();
    istr->endSlice();
}

void
Ice::LocatorRegistry::dispatch(Ice::IncomingRequest& request, std::function<void(Ice::OutgoingResponse)> sendResponse)
{
    static constexpr std::array<std::string_view, 7> allOperations{"ice_id", "ice_ids", "ice_isA", "ice_ping", "setAdapterDirectProxy", "setReplicatedAdapterDirectProxy", "setServerProcessProxy"};

    const Ice::Current& current = request.current();
    auto r = std::equal_range(allOperations.begin(), allOperations.end(), current.operation); // NOLINT(modernize-use-ranges)
    if (r.first == r.second)
    {
        sendResponse(Ice::makeOutgoingResponse(std::make_exception_ptr(Ice::OperationNotExistException{__FILE__, __LINE__}), current));
        return;
    }

    switch (r.first - allOperations.begin())
    {
        case 0:
        {
            _iceD_ice_id(request, std::move(sendResponse));
            break;
        }
        case 1:
        {
            _iceD_ice_ids(request, std::move(sendResponse));
            break;
        }
        case 2:
        {
            _iceD_ice_isA(request, std::move(sendResponse));
            break;
        }
        case 3:
        {
            _iceD_ice_ping(request, std::move(sendResponse));
            break;
        }
        case 4:
        {
            _iceD_setAdapterDirectProxy(request, std::move(sendResponse));
            break;
        }
        case 5:
        {
            _iceD_setReplicatedAdapterDirectProxy(request, std::move(sendResponse));
            break;
        }
        case 6:
        {
            _iceD_setServerProcessProxy(request, std::move(sendResponse));
            break;
        }
        default:
        {
            assert(false);
            sendResponse(Ice::makeOutgoingResponse(std::make_exception_ptr(Ice::OperationNotExistException{__FILE__, __LINE__}), current));
        }
    }
}

std::vector<std::string>
Ice::LocatorRegistry::ice_ids(const Ice::Current&) const
{
    static const std::vector<std::string> allTypeIds = {"::Ice::LocatorRegistry", "::Ice::Object"};
    return allTypeIds;
}

std::string
Ice::LocatorRegistry::ice_id(const Ice::Current&) const
{
    return std::string{ice_staticId()};
}

void
Ice::LocatorRegistry::_iceD_setAdapterDirectProxy(
    Ice::IncomingRequest& request,
    std::function<void(Ice::OutgoingResponse)> sendResponse) // NOLINT(performance-unnecessary-value-param)
{
    auto istr = &request.inputStream();
    istr->startEncapsulation();
    std::string iceP_id;
    std::optional<Ice::ObjectPrx> iceP_proxy;
    istr->readAll(iceP_id, iceP_proxy);
    istr->endEncapsulation();
    this->setAdapterDirectProxy(std::move(iceP_id), std::move(iceP_proxy), request.current());
    sendResponse(Ice::makeEmptyOutgoingResponse(request.current()));
}

void
Ice::LocatorRegistry::_iceD_setReplicatedAdapterDirectProxy(
    Ice::IncomingRequest& request,
    std::function<void(Ice::OutgoingResponse)> sendResponse) // NOLINT(performance-unnecessary-value-param)
{
    auto istr = &request.inputStream();
    istr->startEncapsulation();
    std::string iceP_adapterId;
    std::string iceP_replicaGroupId;
    std::optional<Ice::ObjectPrx> iceP_proxy;
    istr->readAll(iceP_adapterId, iceP_replicaGroupId, iceP_proxy);
    istr->endEncapsulation();
    this->setReplicatedAdapterDirectProxy(std::move(iceP_adapterId), std::move(iceP_replicaGroupId), std::move(iceP_proxy), request.current());
    sendResponse(Ice::makeEmptyOutgoingResponse(request.current()));
}

void
Ice::LocatorRegistry::_iceD_setServerProcessProxy(
    Ice::IncomingRequest& request,
    std::function<void(Ice::OutgoingResponse)> sendResponse) // NOLINT(performance-unnecessary-value-param)
{
    auto istr = &request.inputStream();
    istr->startEncapsulation();
    std::string iceP_id;
    std::optional<ProcessPrx> iceP_proxy;
    istr->readAll(iceP_id, iceP_proxy);
    istr->endEncapsulation();
    this->setServerProcessProxy(std::move(iceP_id), std::move(iceP_proxy), request.current());
    sendResponse(Ice::makeEmptyOutgoingResponse(request.current()));
}

const char*
Ice::LocatorRegistry::ice_staticId() noexcept
{
    return "::Ice::LocatorRegistry";
}

void
Ice::AsyncLocatorRegistry::dispatch(Ice::IncomingRequest& request, std::function<void(Ice::OutgoingResponse)> sendResponse)
{
    static constexpr std::array<std::string_view, 7> allOperations{"ice_id", "ice_ids", "ice_isA", "ice_ping", "setAdapterDirectProxy", "setReplicatedAdapterDirectProxy", "setServerProcessProxy"};

    const Ice::Current& current = request.current();
    auto r = std::equal_range(allOperations.begin(), allOperations.end(), current.operation); // NOLINT(modernize-use-ranges)
    if (r.first == r.second)
    {
        sendResponse(Ice::makeOutgoingResponse(std::make_exception_ptr(Ice::OperationNotExistException{__FILE__, __LINE__}), current));
        return;
    }

    switch (r.first - allOperations.begin())
    {
        case 0:
        {
            _iceD_ice_id(request, std::move(sendResponse));
            break;
        }
        case 1:
        {
            _iceD_ice_ids(request, std::move(sendResponse));
            break;
        }
        case 2:
        {
            _iceD_ice_isA(request, std::move(sendResponse));
            break;
        }
        case 3:
        {
            _iceD_ice_ping(request, std::move(sendResponse));
            break;
        }
        case 4:
        {
            _iceD_setAdapterDirectProxy(request, std::move(sendResponse));
            break;
        }
        case 5:
        {
            _iceD_setReplicatedAdapterDirectProxy(request, std::move(sendResponse));
            break;
        }
        case 6:
        {
            _iceD_setServerProcessProxy(request, std::move(sendResponse));
            break;
        }
        default:
        {
            assert(false);
            sendResponse(Ice::makeOutgoingResponse(std::make_exception_ptr(Ice::OperationNotExistException{__FILE__, __LINE__}), current));
        }
    }
}

std::vector<std::string>
Ice::AsyncLocatorRegistry::ice_ids(const Ice::Current&) const
{
    static const std::vector<std::string> allTypeIds = {"::Ice::LocatorRegistry", "::Ice::Object"};
    return allTypeIds;
}

std::string
Ice::AsyncLocatorRegistry::ice_id(const Ice::Current&) const
{
    return std::string{ice_staticId()};
}

void
Ice::AsyncLocatorRegistry::_iceD_setAdapterDirectProxy(
    Ice::IncomingRequest& request,
    std::function<void(Ice::OutgoingResponse)> sendResponse)
{
    auto istr = &request.inputStream();
    istr->startEncapsulation();
    std::string iceP_id;
    std::optional<Ice::ObjectPrx> iceP_proxy;
    istr->readAll(iceP_id, iceP_proxy);
    istr->endEncapsulation();
    auto responseHandler = std::make_shared<IceInternal::AsyncResponseHandler>(std::move(sendResponse), request.current());
    try
    {
        this->setAdapterDirectProxyAsync(std::move(iceP_id), std::move(iceP_proxy), [responseHandler] { responseHandler->sendEmptyResponse(); }, [responseHandler](std::exception_ptr ex) { responseHandler->sendException(ex); }, responseHandler->current());
    }
    catch (...)
    {
        responseHandler->sendException(std::current_exception());
    }
}

void
Ice::AsyncLocatorRegistry::_iceD_setReplicatedAdapterDirectProxy(
    Ice::IncomingRequest& request,
    std::function<void(Ice::OutgoingResponse)> sendResponse)
{
    auto istr = &request.inputStream();
    istr->startEncapsulation();
    std::string iceP_adapterId;
    std::string iceP_replicaGroupId;
    std::optional<Ice::ObjectPrx> iceP_proxy;
    istr->readAll(iceP_adapterId, iceP_replicaGroupId, iceP_proxy);
    istr->endEncapsulation();
    auto responseHandler = std::make_shared<IceInternal::AsyncResponseHandler>(std::move(sendResponse), request.current());
    try
    {
        this->setReplicatedAdapterDirectProxyAsync(std::move(iceP_adapterId), std::move(iceP_replicaGroupId), std::move(iceP_proxy), [responseHandler] { responseHandler->sendEmptyResponse(); }, [responseHandler](std::exception_ptr ex) { responseHandler->sendException(ex); }, responseHandler->current());
    }
    catch (...)
    {
        responseHandler->sendException(std::current_exception());
    }
}

void
Ice::AsyncLocatorRegistry::_iceD_setServerProcessProxy(
    Ice::IncomingRequest& request,
    std::function<void(Ice::OutgoingResponse)> sendResponse)
{
    auto istr = &request.inputStream();
    istr->startEncapsulation();
    std::string iceP_id;
    std::optional<ProcessPrx> iceP_proxy;
    istr->readAll(iceP_id, iceP_proxy);
    istr->endEncapsulation();
    auto responseHandler = std::make_shared<IceInternal::AsyncResponseHandler>(std::move(sendResponse), request.current());
    try
    {
        this->setServerProcessProxyAsync(std::move(iceP_id), std::move(iceP_proxy), [responseHandler] { responseHandler->sendEmptyResponse(); }, [responseHandler](std::exception_ptr ex) { responseHandler->sendException(ex); }, responseHandler->current());
    }
    catch (...)
    {
        responseHandler->sendException(std::current_exception());
    }
}

const char*
Ice::AsyncLocatorRegistry::ice_staticId() noexcept
{
    return "::Ice::LocatorRegistry";
}
