Eile Mit Weile
Loading...
Searching...
No Matches
RequestResponse Class Reference

Derivative of ServerResponse that is sent as a response to a ClientRequest. More...

#include <RequestResponse.hpp>

Inheritance diagram for RequestResponse:
ServerResponse Serializable

Public Member Functions

 RequestResponse (const std::string &game_id, std::string req_id, bool success, rapidjson::Value *state_json, std::string err)
 
 ~RequestResponse ()
 
void WriteIntoJson (rapidjson::Value &json, rapidjson::Document::AllocatorType &allocator) const override
 
- Public Member Functions inherited from ServerResponse
ResponseType GetType () const
 
std::string GetGameId () const
 
void WriteIntoJson (rapidjson::Value &json, rapidjson::Document::AllocatorType &allocator) const override
 
virtual void Process () const
 
- Public Member Functions inherited from Serializable
virtual rapidjson::DocumentToJson () const
 

Static Public Member Functions

static RequestResponseFromJson (const rapidjson::Value &json)
 
- Static Public Member Functions inherited from ServerResponse
static ServerResponseFromJson (const rapidjson::Value &json)
 

Private Member Functions

 RequestResponse (const BaseClassProperties &props, std::string req_id, bool success, rapidjson::Value *state_json, std::string &err)
 

Private Attributes

bool _success
 
std::string _err
 
std::string _req_id
 
rapidjson::Value_state_json = nullptr
 

Additional Inherited Members

- Protected Member Functions inherited from ServerResponse
 ServerResponse (const BaseClassProperties &)
 
- Static Protected Member Functions inherited from ServerResponse
static BaseClassProperties CreateBaseClassProperties (ResponseType type, const std::string &game_id)
 
static BaseClassProperties ExtractBaseClassProperties (const rapidjson::Value &json)
 
- Protected Attributes inherited from ServerResponse
std::string _game_id
 
ResponseType _type
 

Detailed Description

Derivative of ServerResponse that is sent as a response to a ClientRequest.

Note: This class design is taken from https://gitlab.ethz.ch/hraymond/cse-lama-example-project. RequestResponse is a derivative of ServerResponse. Due to static allocation, ServerResponse can call RequestResponse's FromJson method. We think this is very bad design, but changing it would require a lot of refactoring so we decided to leave it as it is. Furthermore, **Process is only declared/defined for the client executable**. This means that this class definition differs between the client and the server executable. Again, we think this is bad design, but we decided to leave it as it is as trying to change it would require a lot of refactoring.

Constructor & Destructor Documentation

◆ RequestResponse() [1/2]

RequestResponse::RequestResponse ( const BaseClassProperties props,
std::string  req_id,
bool  success,
rapidjson::Value state_json,
std::string &  err 
)
private

Creates a RequestResponse defining all member vars with args using BaseClassProperties

◆ RequestResponse() [2/2]

RequestResponse::RequestResponse ( const std::string &  game_id,
std::string  req_id,
bool  success,
rapidjson::Value state_json,
std::string  err 
)

Creates a RequestResponse defining all member vars with args but wihtout using BaseClassProperties

◆ ~RequestResponse()

RequestResponse::~RequestResponse ( )

Deletes dynamically allocated _state_json (if it exists).

Member Function Documentation

◆ FromJson()

RequestResponse * RequestResponse::FromJson ( const rapidjson::Value json)
static

Deserializes a RequestResponse from the given json.

◆ WriteIntoJson()

void RequestResponse::WriteIntoJson ( rapidjson::Value json,
rapidjson::Document::AllocatorType &  allocator 
) const
overridevirtual

Serializes this RequestResponse into the given json.

Implements Serializable.

Member Data Documentation

◆ _err

std::string RequestResponse::_err
private

Error message if the request was not successful.

◆ _req_id

std::string RequestResponse::_req_id
private

The id of the request this ServerResponse is a response to.

◆ _state_json

rapidjson::Value* RequestResponse::_state_json = nullptr
private

The state of the game as a serialized json value.

◆ _success

bool RequestResponse::_success
private

Whether the request was successful.


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