QGrpcInterceptorChain Class
一連のインターセプターを保存および管理します。詳細...
| ヘッダー: | #include <QGrpcInterceptorChain> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Grpc) target_link_libraries(mytarget PRIVATE Qt6::Grpc) |
| 以下より: | Qt 6.11 |
- 継承されたメンバを含むすべてのメンバの一覧
- QGrpcInterceptorChainは、Qt GRPC のインターセプタの一部です。
パブリック関数
| 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 インターセプタの概要』の「方向とフロー」のセクションを参照してください。
インターセプタは、主に 2 つの所有権モデルを使用して追加できます。
- 所有型(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 = newMetricsInterceptor();
auto *authInterceptor = newAuthInterceptor();
~~~
QGrpcInterceptorChain chain;
if(!chain.add(metricsInterceptor))
qFatal("Failed to add metrics interceptor");
if(!chain.add(authInterceptor))
qFatal("Failed to add auth interceptor");
autochannel=std::shared_ptr<QGrpcHttp2Channel>(
newQGrpcHttp2Channel(QUrl("you_uri:port"),std::move(chain)),
[&metricsInterceptor, &authInterceptor](QGrpcHttp2Channel*ptr) {
deleteptr;
qDebug() << "Channel destroyed.";
// これらのインターセプターが他のチャネルと共有されていない場合、
// ここでそれらを削除するのが適切です。そうでない場合は、
// それらの ライフサイクルを外部で管理する必要があります。
deletemetricsInterceptor;
deleteauthInterceptor;
metricsInterceptor=nullptr;
authInterceptor=nullptr;
}
);各インターセプタ型は、インターセプト機能を提供するために、少なくとも1つのインターセプタインターフェース(例:QGrpcStartInterceptor またはQGrpcFinishedInterceptor )を実装する必要があります。
template <typename T> requires QtGrpcPrivate::if_interceptor<T> bool QGrpcInterceptorChain::add(std::unique_ptr<T> &&interceptor)
interceptor をチェーンに追加し、その所有権を取得します。
インターセプターが追加された場合は `true ` を返し、そうでない場合は `false` を返します。
interceptor の所有権は、インターセプタが正常に追加された場合にのみチェーンに移転されます。関数がfalse を返した場合、所有権は呼び出し元に留まります。
各インターセプタ型は、インターセプト機能を提供するために、少なくとも1つのインターセプタインターフェース(例:QGrpcStartInterceptor またはQGrpcFinishedInterceptor )を実装する必要があります。
[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()
チェーンをクリアします。
チェーンからすべてのインターセプタを削除します。チェーンが所有するインターセプタはすべて破棄されます。
[noexcept] bool QGrpcInterceptorChain::empty() const
チェーンにインターセプターが含まれていない場合は `true ` を返し、それ以外の場合は `false` を返します。
size() およびisEmpty()も参照してください 。
[noexcept] bool QGrpcInterceptorChain::hasHandlerFor(QtGrpc::InterceptorCapability cap) const
チェーンに、機能cap のハンドラを提供するインターセプタが少なくとも1つ含まれている場合は、true を返します。それ以外の場合は、false を返します。
capabilities() およびcapabilitiesAt()も参照してください 。
[noexcept] bool QGrpcInterceptorChain::isEmpty() const
チェーンにインターセプターが含まれていない場合は `true ` を返し、それ以外の場合は `false` を返します。
template <typename... Ts> requires QtGrpcPrivate::if_interceptor<Ts...> bool QGrpcInterceptorChain::set(Ts *... interceptors)
チェーン内の内容を、所有権を取得することなく「interceptors 」に置き換えます。
すべてのインターセプターが正常に追加された場合は `true ` を返し、そうでない場合は `false ` を返し、チェーンは変更されません。
生ポインタを使用してインターセプタを設定する場合、呼び出し元が所有権を保持します。QGrpcInterceptorChain は、指定されたインターセプタへの非所有参照を格納します。
インターセプターチェーンはチャネルに引き渡され、チャネルが所有権を持ちます。その結果、チェーンを使用するチャネルの存続期間全体を通じて、すべてのインターセプターオブジェクトは有効な状態を維持する必要があります。
以下のコードは、カスタムデリータを使用してインターセプタのライフタイムを単一のチャネルに紐付ける方法を示しています。
auto *metricsInterceptor = newMetricsInterceptor();
auto *authInterceptor = newAuthInterceptor();
~~~
QGrpcInterceptorChain chain;
if(!chain.set(metricsInterceptor,authInterceptor))
qFatal("Failed to set interceptors to chain");
autochannel=std::shared_ptr<QGrpcHttp2Channel>(
newQGrpcHttp2Channel(QUrl("you_uri:port"),std::move(chain)),
[&metricsInterceptor, &authInterceptor](QGrpcHttp2Channel*ptr) {
deleteptr;
qDebug() << "Channel destroyed.";
// これらのインターセプターが他のチャネルと共有されていない場合、
// ここでそれらを削除するのが適切です。そうでない場合は、
// それらの ライフタイムを外部で管理する必要があります。
deletemetricsInterceptor;
deleteauthInterceptor;
metricsInterceptor=nullptr;
authInterceptor=nullptr;
}
);各インターセプタ型は、インターセプト機能を提供するために、少なくとも1つのインターセプタインターフェース(例:QGrpcStartInterceptor やQGrpcFinishedInterceptor )を実装する必要があります。
template <typename... Ts> requires QtGrpcPrivate::if_interceptor<Ts...> bool QGrpcInterceptorChain::set(std::unique_ptr<Ts> &&... interceptors)
チェーンの内容を `interceptors ` に置き換え、その所有権を取得します。
すべてのインターセプタが正常に追加された場合は `true ` を返し、そうでない場合は `false ` を返し、チェーンは変更されません。
インターセプタは、この関数に渡された順序で処理されます。すべての追加に成功した場合、チェーンはその順序で新しいインターセプタに置き換えられます。
所有権は、インターセプタが処理されるにつれて段階的に移譲されます。操作が失敗した場合、失敗前に正常に追加されたインターセプタは破棄されますが、残りの(まだ処理されていない)unique_ptrは有効なままとなります。
各インターセプタ型は、インターセプト機能を提供するために、少なくとも1つのインターセプタインターフェース(例:QGrpcStartInterceptor またはQGrpcFinishedInterceptor )を実装する必要があります。
[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.