Skip to main content
Pigweed's logo Pigweed
code_xml
  1. Home
  2. Reference
  3. C/C++
  4. Comms
  5. pw_rpc
  6. pw::rpc::Rpc2ServiceFor< LegacyService > Class Template Reference
pw::rpc::Rpc2ServiceFor< LegacyService > Class Template Reference

Overview

template<typename LegacyService>
class pw::rpc::Rpc2ServiceFor< LegacyService >

Constructs and owns a pw_rpc service as a pw::rpc2::Service, and registers it with the adapter's pw::rpc::Server.

By default, finishing a pw_rpc call with a non-OK status ends the pw_rpc2 call with kCancelled. Pass DeliverNonOkResponses() as the second constructor argument to deliver response payloads for unary or client streaming methods that finish with a non-OK status.

Inheritance diagram for pw::rpc::Rpc2ServiceFor< LegacyService >:
pw::rpc::Rpc2ServiceAdapter pw::rpc2::Service pw::IntrusiveForwardList< T >::Item

Public Member Functions

template<typename... Args, typename = std::enable_if_t< !internal::kStartsWithDeliverNonOkTag<Args...>>>
 Rpc2ServiceFor (Rpc2ServerAdapter &adapter, Args &&... args)
 
template<auto... kNonOkResponseMethods, typename... Args>
 Rpc2ServiceFor (Rpc2ServerAdapter &adapter, internal::DeliverNonOkResponsesTag< kNonOkResponseMethods... > policy, Args &&... args)
 
 ~Rpc2ServiceFor ()
 
LegacyService & service ()
 Returns the wrapped pw_rpc service.
 
const LegacyService & service () const
 Returns the wrapped pw_rpc service.
 
- Public Member Functions inherited from pw::rpc::Rpc2ServiceAdapter
template<typename LegacyService >
 Rpc2ServiceAdapter (Rpc2ServerAdapter &adapter, LegacyService &service)
 
template<auto... kNonOkResponseMethods, typename LegacyService >
 Rpc2ServiceAdapter (Rpc2ServerAdapter &adapter, internal::DeliverNonOkResponsesTag< kNonOkResponseMethods... > policy, LegacyService &service)
 
 Rpc2ServiceAdapter (const Rpc2ServiceAdapter &)=delete
 
Rpc2ServiceAdapter & operator= (const Rpc2ServiceAdapter &)=delete
 

Additional Inherited Members

- Protected Member Functions inherited from pw::rpc::Rpc2ServiceAdapter
Rpc2ServerAdapter & adapter () const
 
- Protected Member Functions inherited from pw::rpc2::Service
constexpr Service (uint32_t service_id, span< const internal::Method > methods)
 
 ~Service ()
 
- Protected Member Functions inherited from pw::IntrusiveForwardList< T >::Item
constexpr Item ()=default
 

Constructor & Destructor Documentation

◆ Rpc2ServiceFor() [1/2]

template<typename LegacyService >
template<typename... Args, typename = std::enable_if_t< !internal::kStartsWithDeliverNonOkTag<Args...>>>
pw::rpc::Rpc2ServiceFor< LegacyService >::Rpc2ServiceFor ( Rpc2ServerAdapter &  adapter,
Args &&...  args 
)
inlineexplicit

Constructs the wrapped LegacyService from args and registers it with the adapter's pw::rpc::Server.

Parameters
[in]adapterThe adapter that runs the service's handlers. Must outlive this object.
[in]argsArguments forwarded to LegacyService's constructor.

◆ Rpc2ServiceFor() [2/2]

template<typename LegacyService >
template<auto... kNonOkResponseMethods, typename... Args>
pw::rpc::Rpc2ServiceFor< LegacyService >::Rpc2ServiceFor ( Rpc2ServerAdapter &  adapter,
internal::DeliverNonOkResponsesTag< kNonOkResponseMethods... >  policy,
Args &&...  args 
)
inline

Constructs the wrapped LegacyService from args, registers it with the adapter's pw::rpc::Server, and delivers the response payload (with kOk) for selected unary or client streaming methods even when their pw_rpc handler finishes with a non-OK status.

See DeliverNonOkResponses() for usage and caveats regarding early error returns.

Parameters
[in]adapterThe adapter that runs the service's handlers. Must outlive this object.
[in]policyDeliverNonOkResponses<Methods...>() for specific methods, or DeliverNonOkResponses() for all unary and client streaming methods of LegacyService.
[in]argsArguments forwarded to LegacyService's constructor.

◆ ~Rpc2ServiceFor()

template<typename LegacyService >
pw::rpc::Rpc2ServiceFor< LegacyService >::~Rpc2ServiceFor ( )
inline

Unregisters the service from the adapter's pw::rpc::Server.

Precondition
The pw::rpc2::Server this service was registered with must be closed, and Rpc2ServerAdapter::Stop() must have been called.

Member Function Documentation

◆ service()

template<typename LegacyService >
const LegacyService & pw::rpc::Rpc2ServiceFor< LegacyService >::service ( ) const
inline

Returns the wrapped pw_rpc service.


The documentation for this class was generated from the following file: