LogCabin
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Private Member Functions | Private Attributes | Friends
LogCabin::RPC::ServerRPC Class Reference

This class represents the server side of a remote procedure call. More...

#include <ServerRPC.h>

List of all members.

Public Member Functions

 ServerRPC ()
 Default constructor for empty RPC that can't be replied to.
 ServerRPC (ServerRPC &&other)
 Move constructor.
 ~ServerRPC ()
 Destructor.
ServerRPCoperator= (ServerRPC &&other)
 Move assignment.
bool needsReply () const
 Returns whether this RPC is waiting for a reply.
uint16_t getService () const
 This identifies which Service the RPC is destined for.
uint8_t getServiceSpecificErrorVersion () const
 This tells the Service what service-specific errors the client understands.
uint16_t getOpCode () const
 Return which RPC is being executed, scoped to the service.
bool getRequest (google::protobuf::Message &request)
 Parse the request out of the RPC.
bool getRequest (Core::Buffer &buffer) const
 Copy the request out of the RPC.
void reply (const google::protobuf::Message &payload)
 Send a normal response back to the client.
void returnError (const google::protobuf::Message &serviceSpecificError)
 Send a service-specific error back to the client.
void rejectInvalidService ()
 Reject the RPC on the grounds that it specifies an invalid service ID.
void rejectInvalidRequest ()
 Reject the RPC on the grounds that it specifies an invalid request.
void closeSession ()
 Close the session on which this request originated.

Private Member Functions

 ServerRPC (OpaqueServerRPC opaqueRPC)
 Constructor for ServerRPC.
void reject (RPC::Protocol::Status status)
 Reject the RPC.
 ServerRPC (const ServerRPC &)
ServerRPCoperator= (const ServerRPC &)

Private Attributes

OpaqueServerRPC opaqueRPC
 The underlying transport-level RPC object.
bool active
 Set to true if the RPC needs a reply, false otherwise.
uint16_t service
 See getService().
uint8_t serviceSpecificErrorVersion
 See getServiceSpecificErrorVersion().
uint16_t opCode
 See getOpCode().

Friends

class Server

Detailed Description

This class represents the server side of a remote procedure call.

A Server creates an instance when an RPC is initiated. This is used to send the reply.

This class may be used from any thread, but each object is meant to be accessed by only one thread at a time.

Definition at line 37 of file ServerRPC.h.


Constructor & Destructor Documentation

LogCabin::RPC::ServerRPC::ServerRPC ( OpaqueServerRPC  opaqueRPC) [explicit, private]

Constructor for ServerRPC.

This is called by Server only.

Definition at line 29 of file ServerRPC.cc.

Default constructor for empty RPC that can't be replied to.

This is useful as a placeholder for a real ServerRPC.

Definition at line 60 of file ServerRPC.cc.

Move constructor.

Definition at line 69 of file ServerRPC.cc.

Destructor.

Definition at line 79 of file ServerRPC.cc.


Member Function Documentation

ServerRPC & LogCabin::RPC::ServerRPC::operator= ( ServerRPC &&  other)

Move assignment.

Definition at line 89 of file ServerRPC.cc.

bool LogCabin::RPC::ServerRPC::needsReply ( ) const [inline]

Returns whether this RPC is waiting for a reply.

Returns:
True if the owner needs to take action based on this RPC; false if the RPC is not valid or has already been replied to. If this returns false, the caller should discard this ServerRPC object.

Definition at line 74 of file ServerRPC.h.

uint16_t LogCabin::RPC::ServerRPC::getService ( ) const [inline]

This identifies which Service the RPC is destined for.

The Server class uses this to dispatch to the appropriate Service.

Definition at line 82 of file ServerRPC.h.

This tells the Service what service-specific errors the client understands.

Services should take care not to send a client a service-specific error that it doesn't understand.

Definition at line 91 of file ServerRPC.h.

uint16_t LogCabin::RPC::ServerRPC::getOpCode ( ) const [inline]

Return which RPC is being executed, scoped to the service.

Definition at line 98 of file ServerRPC.h.

bool LogCabin::RPC::ServerRPC::getRequest ( google::protobuf::Message &  request)

Parse the request out of the RPC.

Parameters:
[out]requestAn empty protocol buffer the request will be be unpacked into.
Returns:
True if 'request' contains a valid RPC request which needs to be handled; false otherwise. If this returns false, the caller should discard this ServerRPC object.

Definition at line 101 of file ServerRPC.cc.

Copy the request out of the RPC.

Parameters:
[out]bufferAn empty buffer that the request will be copied into.
Returns:
True if 'request' contains a valid RPC request which needs to be handled; false otherwise. If this returns false, the caller should discard this ServerRPC object.

Definition at line 114 of file ServerRPC.cc.

void LogCabin::RPC::ServerRPC::reply ( const google::protobuf::Message &  payload)

Send a normal response back to the client.

Parameters:
payloadA protocol buffer to serialize into the response.

Definition at line 132 of file ServerRPC.cc.

void LogCabin::RPC::ServerRPC::returnError ( const google::protobuf::Message &  serviceSpecificError)

Send a service-specific error back to the client.

Parameters:
serviceSpecificErrorDetails explaining the error to send back to the client.

Definition at line 148 of file ServerRPC.cc.

Reject the RPC on the grounds that it specifies an invalid service ID.

Definition at line 164 of file ServerRPC.cc.

Reject the RPC on the grounds that it specifies an invalid request.

Definition at line 170 of file ServerRPC.cc.

Close the session on which this request originated.

This is an impolite thing to do to a client but can be useful occasionally, for example for testing.

Definition at line 176 of file ServerRPC.cc.

Reject the RPC.

Parameters:
statusThis should be INVALID_VERSION, INVALID_SERVICE, or INVALID_REQUEST.

Definition at line 183 of file ServerRPC.cc.

ServerRPC& LogCabin::RPC::ServerRPC::operator= ( const ServerRPC ) [private]

Friends And Related Function Documentation

friend class Server [friend]

Definition at line 182 of file ServerRPC.h.


Member Data Documentation

The underlying transport-level RPC object.

It doesn't know how to interpret the raw bytes of the RPC, but it gets them from here to there.

Definition at line 168 of file ServerRPC.h.

Set to true if the RPC needs a reply, false otherwise.

Definition at line 173 of file ServerRPC.h.

See getService().

Definition at line 176 of file ServerRPC.h.

See getServiceSpecificErrorVersion().

Definition at line 178 of file ServerRPC.h.

See getOpCode().

Definition at line 180 of file ServerRPC.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines