이 페이지에서

QGrpcInterceptorChain Class

일련의 인터셉터를 저장하고 관리합니다. 더 보기...

헤더: #include <QGrpcInterceptorChain>
CMake: find_package(Qt6 REQUIRED COMPONENTS Grpc)
target_link_libraries(mytarget PRIVATE Qt6::Grpc)
다음부터: Qt 6.11

공개 함수

QGrpcInterceptorChain()
QGrpcInterceptorChain(const QGrpcInterceptorChain &)
~QGrpcInterceptorChain()
bool add(T *interceptor)
bool add(std::unique_ptr<T> &&interceptor)
QtGrpc::InterceptorCapabilities capabilities() const
QtGrpc::InterceptorCapabilities capabilitiesAt(qsizetype index) const
void clear()
bool empty() const
bool hasHandlerFor(QtGrpc::InterceptorCapability cap) const
bool isEmpty() const
bool set(Ts *... interceptors)
bool set(std::unique_ptr<Ts> &&... interceptors)
qsizetype size() const
void swap(QGrpcInterceptorChain &other)
QGrpcInterceptorChain &operator=(const QGrpcInterceptorChain &)

상세 설명

QGrpcInterceptorChain은 RPC의 여러 단계를 관찰하거나 수정하는 인터셉터 인스턴스를 저장합니다. 이 체인은 생성 과정에서 채널로 전달되며, 채널은 수명 주기 동안 이 체인을 소유합니다.

RPC의 수명 주기가 진행됨에 따라, 채널은 해당 인터셉션 지점에서 체인에 저장된 인터셉터를 호출합니다.

인터셉터는 정의된 순서대로 체인에 추가됩니다. 이 순서는 중요하며, RPC의 아웃바운드 및 인바운드 단계에서 인터셉터가 호출되는 방식을 결정합니다. 자세한 내용은 Qt GRPC 인터셉터 개요의 ‘방향 및 흐름’ 섹션을 참조하십시오.

인터셉터는 다음 두 가지 주요 소유권 모델을 사용하여 추가할 수 있습니다.

  • 소유(Owning): ` std::unique_ptr<T>`을 사용하여 인터셉터를 추가합니다. 성공 시 체인이 소유권을 인수하며, 체인(그리고 이에 따라 채널)이 소멸될 때 인터셉터를 소멸시킵니다.
  • 비소유(Non-owning): 원시 포인터( T*)를 사용하여 인터셉터를 추가합니다. 체인은 소유권을 인수하지 않습니다. 호출자는 채널이 인터셉터를 호출할 수 있는 기간 동안 인터셉터 객체가 유효하게 유지되도록 보장해야 합니다.

두 모델 모두 동일한 체인 내에서 결합될 수 있습니다. 소유형과 비소유형 인터셉터를 혼합하는 것은 지원되지만, 비소유형 인터셉터가 이를 사용할 수 있는 모든 채널보다 오래 유지되도록 주의해야 합니다.

참고: QGrpcInterceptorChain은 복사할 수 없으며 이동만 가능합니다.

QtGrpc::InterceptorCapability도 참조하십시오 .

멤버 함수 문서

QGrpcInterceptorChain::QGrpcInterceptorChain()

빈 인터셉터 체인을 생성합니다.

[delete] QGrpcInterceptorChain::QGrpcInterceptorChain(const QGrpcInterceptorChain &)

QGrpcInterceptorChain 의 인스턴스를 복사 생성합니다. 이 함수는 삭제되었습니다.

[noexcept] QGrpcInterceptorChain::~QGrpcInterceptorChain()

요격체 사슬을 파괴합니다.

template <typename T> requires QtGrpcPrivate::if_interceptor<T> bool QGrpcInterceptorChain::add(T *interceptor)

소유권을 양도하지 않고 체인에 interceptor 를 추가합니다.

인터셉터가 추가된 경우 true 를 반환하고, 그렇지 않은 경우 false 를 반환합니다.

원시 포인터를 사용하여 인터셉터를 설정할 경우, 호출자가 소유권을 보유합니다. ` QGrpcInterceptorChain `은 제공된 인터셉터에 대한 비소유 참조를 저장합니다.

인터셉터 체인은 채널로 이전되며 채널이 이를 소유하게 됩니다. 따라서 해당 체인을 사용하는 채널의 전체 수명 기간 동안 모든 인터셉터 객체는 유효한 상태를 유지해야 합니다.

다음 코드는 사용자 정의 삭제기를 사용하여 인터셉터의 수명을 단일 채널에 연동하는 방법을 보여줍니다:

auto *metricsInterceptor = new MetricsInterceptor();
auto *authInterceptor = new AuthInterceptor();
~~~
QGrpcInterceptorChain chain;
if (!chain.add(metricsInterceptor))
    qFatal("Failed to add metrics interceptor");
if (!chain.add(authInterceptor))
    qFatal("Failed to add auth interceptor");

auto channel = std::shared_ptr<QGrpcHttp2Channel>(
    new QGrpcHttp2Channel(QUrl("you_uri:port"), std::move(chain)),
    [&metricsInterceptor, &authInterceptor](QGrpcHttp2Channel* ptr) {
        delete ptr;
        qDebug() << "Channel destroyed.";
       // 이 인터셉터들이 다른 채널과 공유되지 않는다면,
        // 이곳에서 해당 인터셉터들을 삭제하는 것이 적절합니다. 그렇지 않은 경우,
        //  해당 인터셉터들의  수명은 외부에서 관리해야 합니다.
       delete metricsInterceptor;
        delete authInterceptor;
        metricsInterceptor = nullptr;
        authInterceptor = nullptr;
    }
);

각 인터셉터 유형은 인터셉트 기능을 제공하기 위해 적어도 하나의 인터셉터 인터페이스(예: QGrpcStartInterceptor 또는 QGrpcFinishedInterceptor)를 구현해야 합니다.

set() 및 clear()도 참조하십시오 .

template <typename T> requires QtGrpcPrivate::if_interceptor<T> bool QGrpcInterceptorChain::add(std::unique_ptr<T> &&interceptor)

interceptor 을 체인에 추가하고 해당 객체의 소유권을 인수합니다.

인터셉터가 추가된 경우 true 을 반환하고, 그렇지 않은 경우 false 을 반환합니다.

interceptor 의 소유권은 인터셉터가 성공적으로 추가된 경우에만 체인으로 이전됩니다. 함수가 false 을 반환하면 소유권은 호출자에게 남아 있습니다.

각 인터셉터 유형은 인터셉션 기능을 제공하기 위해 적어도 하나의 인터셉터 인터페이스(예: ` QGrpcStartInterceptor ` 또는 ` QGrpcFinishedInterceptor`)를 구현해야 합니다.

set() 및 clear()도 참조하십시오 .

[noexcept] QtGrpc::InterceptorCapabilities QGrpcInterceptorChain::capabilities() const

체인에 저장된 모든 인터셉터의 기능을 통합하여 반환합니다.

반환되는 값은 인터셉터들이 제공하는 기능들의 비트별 OR 연산 결과입니다.

hasHandlerFor(), capabilitiesAt() 및 QtGrpc::InterceptorCapability도 참조하십시오 .

QtGrpc::InterceptorCapabilities QGrpcInterceptorChain::capabilitiesAt(qsizetype index) const

index 에서 인터셉터가 제공하는 기능을 반환합니다.

경고: 체인에 유효하지 않은 index 를 사용하여 이 함수를호출하면 정의되지 않은 동작이 발생합니다.

capabilities() 및 size()도 참조하십시오 .

void QGrpcInterceptorChain::clear()

체인에서 모든 인터셉터를 제거합니다.

체인에서 모든 인터셉터를 제거합니다. 체인이 소유한 모든 인터셉터는 파기됩니다.

add() 및 set()도 참조하십시오 .

[noexcept] bool QGrpcInterceptorChain::empty() const

체인에 인터셉터가 포함되어 있지 않으면 ` true `를 반환하고, 그렇지 않으면 ` false`를 반환합니다.

size() 및 isEmpty()도 참조하십시오 .

[noexcept] bool QGrpcInterceptorChain::hasHandlerFor(QtGrpc::InterceptorCapability cap) const

체인에 cap 기능에 대한 핸들러를 제공하는 인터셉터가 하나 이상 포함되어 있으면 true 를 반환하고, 그렇지 않으면 false 를 반환합니다.

capabilities() 및 capabilitiesAt()도 참조하십시오 .

[noexcept] bool QGrpcInterceptorChain::isEmpty() const

체인에 인터셉터가 포함되어 있지 않으면 true 를 반환하고, 그렇지 않으면 false 를 반환합니다.

size() 및 empty()도 참조하십시오 .

template <typename... Ts> requires QtGrpcPrivate::if_interceptor<Ts...> bool QGrpcInterceptorChain::set(Ts *... interceptors)

체인 내의 내용을 interceptors 로 대체하되, 해당 항목에 대한 소유권을 취득하지는 않습니다.

모든 인터셉터가 성공적으로 추가된 경우 ` true `를 반환하고, 그렇지 않은 경우 ` false `를 반환하며 체인을 변경하지 않습니다.

생 포인터를 사용하여 인터셉터를 설정할 경우, 호출자가 소유권을 보유합니다. ` QGrpcInterceptorChain `는 제공된 인터셉터에 대한 소유권이 없는 참조를 저장합니다.

인터셉터 체인은 채널로 이전되어 채널이 소유하게 됩니다. 따라서 모든 인터셉터 객체는 해당 체인을 사용하는 채널의 전체 수명 기간 동안 유효한 상태를 유지해야 합니다.

다음 코드는 사용자 정의 델리터를 사용하여 인터셉터의 수명을 단일 채널에 연동하는 방법을 보여줍니다:

auto *metricsInterceptor = new MetricsInterceptor();
auto *authInterceptor = new AuthInterceptor();
~~~
QGrpcInterceptorChain chain;
if (!chain.set(metricsInterceptor, authInterceptor))
    qFatal("Failed to set interceptors to chain");

auto channel = std::shared_ptr<QGrpcHttp2Channel>(
    new QGrpcHttp2Channel(QUrl("you_uri:port"), std::move(chain)),
    [&metricsInterceptor, &authInterceptor](QGrpcHttp2Channel* ptr) {
        delete ptr;
        qDebug() << "Channel destroyed.";
       // 이 인터셉터들이 다른 채널과 공유되지 않는다면,
        // 이곳에서 이를 삭제하는 것이 적절합니다. 그렇지 않은 경우,
        //  해당 인터셉터들의  수명은 외부에서 관리해야 합니다.
       delete metricsInterceptor;
        delete authInterceptor;
        metricsInterceptor = nullptr;
        authInterceptor = nullptr;
    }
);

각 인터셉터 유형은 인터셉션 기능을 제공하기 위해 적어도 하나의 인터셉터 인터페이스(예: QGrpcStartInterceptor 또는 QGrpcFinishedInterceptor)를 구현해야 합니다.

add() 및 clear()도 참조하십시오 .

template <typename... Ts> requires QtGrpcPrivate::if_interceptor<Ts...> bool QGrpcInterceptorChain::set(std::unique_ptr<Ts> &&... interceptors)

체인 내의 내용을 interceptors 로 대체하고 해당 항목에 대한 소유권을 가져옵니다.

모든 인터셉터가 성공적으로 추가된 경우 ` true `를 반환하고, 그렇지 않은 경우 ` false `를 반환하며 체인을 변경하지 않습니다.

인터셉터는 이 함수에 전달된 순서대로 처리됩니다. 모든 추가가 성공하면 체인은 해당 순서대로 새로운 인터셉터로 대체됩니다.

소유권은 인터셉터가 처리됨에 따라 점진적으로 이전됩니다. 작업이 실패할 경우, 실패 전에 성공적으로 추가된 인터셉터는 모두 파괴되지만, 나머지(아직 처리되지 않은) unique_ptr은 유효한 상태로 유지됩니다.

각 인터셉터 유형은 인터셉션 기능을 제공하기 위해 적어도 하나의 인터셉터 인터페이스(예: QGrpcStartInterceptor 또는 QGrpcFinishedInterceptor)를 구현해야 합니다.

add() 및 clear()도 참조하십시오 .

[noexcept] qsizetype QGrpcInterceptorChain::size() const

체인에 저장된 인터셉터의 개수를 반환합니다.

isEmpty()도 참조하십시오 .

[noexcept] void QGrpcInterceptorChain::swap(QGrpcInterceptorChain &other)

other 를 이 객체로 교체합니다. 이 작업은 매우 빠르며 실패하는 일이 없습니다.

[delete] QGrpcInterceptorChain &QGrpcInterceptorChain::operator=(const QGrpcInterceptorChain &)

other 를 이 QGrpcInterceptorChain 인스턴스에 복사-할당합니다. 이 함수는 삭제되었습니다.

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.