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::PwpbServerWriter< Response > Class Template Reference
pw::rpc::PwpbServerWriter< Response > Class Template Reference

Overview

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

Sends streamed pw_protobuf responses for a server streaming RPC on a server.

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

Public Member Functions

constexpr PwpbServerWriter ()=default
 Creates an inactive PwpbServerWriter into which an active call can be moved.
 
 PwpbServerWriter (PwpbServerWriter &&)=default
 
PwpbServerWriter & operator= (PwpbServerWriter &&)=default
 
Status Write (const Response &response)
 Encodes and sends a streamed Response message to the client.
 
Status Finish (Status status=OkStatus())
 Closes the RPC and sends the final status to the client.
 
Status TryFinish (Status status=OkStatus())
 Attempts to close the RPC and send the final status to the client.
 

Static Public Member Functions

template<auto kMethod, typename ServiceImpl >
static PwpbServerWriter Open (Server &server, uint32_t channel_id, ServiceImpl &service)
 Creates a PwpbServerWriter 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::PwpbServerWriter< Response >::Finish ( Status  status = OkStatus())
inline

Closes the RPC and sends the final status to the client.

Parameters
[in]statusThe overall status of the RPC to send to the client.
Returns
  • OK: The final packet was successfully sent.
  • FAILED_PRECONDITION: The writer is closed.
  • Other error codes from the ChannelOutput implementation if sending the packet failed.

◆ Open()

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

Creates a PwpbServerWriter 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 responses.
[in,out]serviceThe registered service instance handling the RPC.
Returns
An active PwpbServerWriter bound to the specified channel and method.

◆ TryFinish()

template<typename Response >
Status pw::rpc::PwpbServerWriter< Response >::TryFinish ( Status  status = OkStatus())
inline

Attempts to close the RPC and send the final status to the client.

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

Parameters
[in]statusThe overall status of the RPC to send to the client.
Returns
  • OK: The final packet was successfully sent and the call was closed.
  • FAILED_PRECONDITION: The writer is closed.
  • Other error codes from the ChannelOutput implementation if sending the packet failed (the call remains active).

◆ Write()

template<typename Response >
Status pw::rpc::PwpbServerWriter< Response >::Write ( const Response &  response)
inline

Encodes and sends a streamed Response message to the client.

Parameters
[in]responseThe Response message struct to encode and send.
Returns
  • OK: The response was successfully sent.
  • FAILED_PRECONDITION: The writer 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 documentation for this class was generated from the following file: