Provides thread-local access to the current gRPC server context during request handling.
More...
#include "rpc/grpc_context_observer.hpp"
|
| class | Enable |
| | RAII helper for activating the gRPC context observer for the current thread. More...
|
| |
|
| const GrpcServerContext & | context () const noexcept |
| | Returns the underlying gRPC server context.
|
| |
| std::vector< std::string > | get_client_metadata_field_values (const std::string &key) const |
| | Retrieves all values for a given metadata key from the client's initial metadata.
|
| |
|
| static const boost::optional< const GrpcContextObserver > & | current () noexcept |
| | Returns the current thread-local gRPC context observer, if one is active.
|
| |
Provides thread-local access to the current gRPC server context during request handling.
This class allows code to access gRPC metadata and context information without explicit parameter passing. The context is automatically made available when processing gRPC requests and remains valid for the duration of the request.
- Note
- Access to the context is thread-safe via thread-local storage.
◆ context()
| const GrpcServerContext & viam::sdk::GrpcContextObserver::context |
( |
| ) |
const |
|
noexcept |
Returns the underlying gRPC server context.
- Returns
- Reference to the gRPC server context for the current request.
- Warning
- The returned
GrpcServerContext reference is valid only for the duration of the gRPC call and only on the thread that received it. Do not store the reference or pass it to other threads.
◆ current()
| static const boost::optional< const GrpcContextObserver > & viam::sdk::GrpcContextObserver::current |
( |
| ) |
|
|
staticnoexcept |
Returns the current thread-local gRPC context observer, if one is active.
- Returns
- An optional containing the active observer, or an empty optional if no gRPC request is currently being processed on this thread.
- Warning
- The returned
GrpcContextObserver reference is valid only for the duration of the gRPC call and only on the thread that received it. Do not store the reference or pass it to other threads.
◆ get_client_metadata_field_values()
| std::vector< std::string > viam::sdk::GrpcContextObserver::get_client_metadata_field_values |
( |
const std::string & | key | ) |
const |
Retrieves all values for a given metadata key from the client's initial metadata.
Client metadata is sent at the beginning of each gRPC call and can contain multiple values for the same key. This method returns all values associated with the specified key.
- Parameters
-
| key | The metadata key to look up (case-sensitive). |
- Returns
- A vector of all string values associated with the key. Returns an empty vector if the key is not found in the metadata. The returned strings are copies and remain valid after the gRPC call completes.
The documentation for this class was generated from the following file: