MySQL 8.0.39
Source Code Documentation
RestApiComponent Class Reference

#include <rest_api_component.h>

Public Types

using JsonDocument = rapidjson::GenericDocument< rapidjson::UTF8<>, rapidjson::CrtAllocator >
 
using JsonValue = rapidjson::GenericValue< rapidjson::UTF8<>, JsonDocument::AllocatorType >
 
using JsonPointer = rapidjson::GenericPointer< JsonValue, JsonDocument::AllocatorType >
 
using SpecProcessor = void(*)(JsonDocument &spec_doc)
 processor for the RestAPI's spec. More...
 

Public Member Functions

void init (std::shared_ptr< RestApi > srv)
 initialize component. More...
 
bool try_process_spec (SpecProcessor processor)
 try to process the RestAPI's spec. More...
 
void remove_process_spec (SpecProcessor processor)
 remove processor from backlog if exists. More...
 
void add_path (const std::string &path, std::unique_ptr< BaseRestApiHandler > handler)
 added handler for a path. More...
 
void remove_path (const std::string &path)
 remove a path. More...
 

Static Public Member Functions

static RestApiComponentget_instance ()
 get singleton instance of the component. More...
 

Private Member Functions

 RestApiComponent (RestApiComponent const &)=delete
 
void operator= (RestApiComponent const &)=delete
 
 RestApiComponent ()=default
 

Private Attributes

std::mutex spec_mu_
 
std::vector< SpecProcessorspec_processors_
 
std::vector< std::pair< std::string, std::unique_ptr< BaseRestApiHandler > > > add_path_backlog_
 
std::weak_ptr< RestApisrv_
 

Member Typedef Documentation

◆ JsonDocument

using RestApiComponent::JsonDocument = rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator>

◆ JsonPointer

using RestApiComponent::JsonPointer = rapidjson::GenericPointer<JsonValue, JsonDocument::AllocatorType>

◆ JsonValue

using RestApiComponent::JsonValue = rapidjson::GenericValue<rapidjson::UTF8<>, JsonDocument::AllocatorType>

◆ SpecProcessor

using RestApiComponent::SpecProcessor = void (*)(JsonDocument &spec_doc)

processor for the RestAPI's spec.

Parameters
spec_docJSON document to modify

Constructor & Destructor Documentation

◆ RestApiComponent() [1/2]

RestApiComponent::RestApiComponent ( RestApiComponent const &  )
privatedelete

◆ RestApiComponent() [2/2]

RestApiComponent::RestApiComponent ( )
privatedefault

Member Function Documentation

◆ add_path()

void RestApiComponent::add_path ( const std::string &  path,
std::unique_ptr< BaseRestApiHandler handler 
)

added handler for a path.

path must be unique

Parameters
pathregex for the path
handlerhandler for the path

◆ get_instance()

RestApiComponent & RestApiComponent::get_instance ( )
static

get singleton instance of the component.

◆ init()

void RestApiComponent::init ( std::shared_ptr< RestApi srv)

initialize component.

registers RestApi with the component and actives the processing of the backlogs for:

  • try_process_spec()
  • add_path()

◆ operator=()

void RestApiComponent::operator= ( RestApiComponent const &  )
privatedelete

◆ remove_path()

void RestApiComponent::remove_path ( const std::string &  path)

remove a path.

must be called before the plugin gets unloaded that added the handler in the first place.

◆ remove_process_spec()

void RestApiComponent::remove_process_spec ( SpecProcessor  processor)

remove processor from backlog if exists.

Parameters
processordocument processor

◆ try_process_spec()

bool RestApiComponent::try_process_spec ( SpecProcessor  processor)

try to process the RestAPI's spec.

if the component hasn't been initialized from the rest_api plugin yet, false is returned and the processor is added to a backlog which is processed when init() is called.

As the rest_api may fail to load, the caller should remove itself again with remove_process_spec() in that case.

That's not needed in case try_process_spec() returns true.

Parameters
processordocument processor
Returns
success
Return values
truespec was processed.
falseprocessor added to backlog.

Member Data Documentation

◆ add_path_backlog_

std::vector<std::pair<std::string, std::unique_ptr<BaseRestApiHandler> > > RestApiComponent::add_path_backlog_
private

◆ spec_mu_

std::mutex RestApiComponent::spec_mu_
private

◆ spec_processors_

std::vector<SpecProcessor> RestApiComponent::spec_processors_
private

◆ srv_

std::weak_ptr<RestApi> RestApiComponent::srv_
private

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