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

Overview

template<typename Response>
class pw::rpc::PwpbUnaryResponder< Response >

Sends the pw_protobuf response for an asynchronous unary RPC on a server.

Template Parameters
ResponseThe generated pw_protobuf response message struct type.
Inheritance diagram for pw::rpc::PwpbUnaryResponder< Response >:
pw::rpc::internal::PwpbServerCall

Public Member Functions

constexpr PwpbUnaryResponder ()=default
 Creates an inactive PwpbUnaryResponder into which an active call can be moved.
 
 PwpbUnaryResponder (PwpbUnaryResponder &&)=default
 
PwpbUnaryResponder & operator= (PwpbUnaryResponder &&)=default
 
Status Finish (const Response &response, Status status=OkStatus())
 Sends the unary Response message and status, closing the RPC.
 
Status TryFinish (const Response &response, Status status=OkStatus())
 Attempts to close the RPC and send the unary Response message and status to the client.
 

Static Public Member Functions

template<auto kMethod, typename ServiceImpl >
static PwpbUnaryResponder Open (Server &server, uint32_t channel_id, ServiceImpl &service)
 Creates a PwpbUnaryResponder that is ready to send responses for a particular RPC.
 

Friends

class internal::Call
 
class internal::PwpbMethod
 
class Server
 
template<typename , typename , uint32_t >
class internal::test::InvocationContext
 

Member Function Documentation

◆ Finish()

template<typename Response >
Status pw::rpc::PwpbUnaryResponder< Response >::Finish ( const Response &  response,
Status  status = OkStatus() 
)
inline

Sends the unary Response message and status, closing the RPC.

Parameters
[in]responseThe Response message struct to encode and send.
[in]statusThe overall status of the RPC to send to the client.
Returns
  • OK: The response was successfully sent.
  • FAILED_PRECONDITION: The responder is closed.
  • INTERNAL: pw_rpc was unable to encode the pw_protobuf message.
  • Other error codes from the ChannelOutput implementation if sending the packet failed.

◆ Open()

template<typename Response >
template<auto kMethod, typename ServiceImpl >
static PwpbUnaryResponder pw::rpc::PwpbUnaryResponder< Response >::Open ( Server &  server,
uint32_t  channel_id,
ServiceImpl &  service 
)
inlinestatic

Creates a PwpbUnaryResponder that is ready to send responses for a particular RPC.

This can be used for testing or to send responses to an RPC that has not been started by a client.

Template Parameters
kMethodPointer to the generated service method.
ServiceImplThe service implementation class.
Parameters
[in,out]serverThe RPC Server on which to open the call.
[in]channel_idThe ID of the channel on which to send the response.
[in,out]serviceThe registered service instance handling the RPC.
Returns
An active PwpbUnaryResponder bound to the specified channel and method.

◆ TryFinish()

template<typename Response >
Status pw::rpc::PwpbUnaryResponder< Response >::TryFinish ( const Response &  response,
Status  status = OkStatus() 
)
inline

Attempts to close the RPC and send the unary Response message and status to the client.

Unlike Finish(), the call remains open if sending the packet fails, allowing the caller to retry.

Parameters
[in]responseThe Response message struct to encode and send.
[in]statusThe overall status of the RPC to send to the client.
Returns
  • OK: The response was successfully sent and the call was closed.
  • FAILED_PRECONDITION: The responder is closed.
  • INTERNAL: pw_rpc was unable to encode the pw_protobuf message.
  • Other error codes from the ChannelOutput implementation if sending the packet failed (the call remains active).

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