Viam C++ SDK current
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Friends | List of all members
viam::sdk::GrpcContextObserver Class Reference

Provides thread-local access to the current gRPC server context during request handling. More...

#include "rpc/grpc_context_observer.hpp"

Classes

class  Enable
 RAII helper for activating the gRPC context observer for the current thread. More...
 

Public Member Functions

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 Public Member Functions

static const boost::optional< const GrpcContextObserver > & current () noexcept
 Returns the current thread-local gRPC context observer, if one is active.
 

Friends

class Enable
 

Detailed Description

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.

Member Function Documentation

◆ 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
keyThe 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: