Dripline-Cpp  v2.4.2
Dripline Implementation in C++
Public Member Functions | Protected Member Functions | Private Member Functions | List of all members
endpoint Class Reference

Basic Dripline object capable of receiving and acting on messages. More...

#include <endpoint.hh>

Inheritance diagram for endpoint:
Inheritance graph

Public Member Functions

 endpoint (const std::string &a_name)
 
 endpoint (const endpoint &a_orig)
 
 endpoint (endpoint &&a_orig)
 
virtual ~endpoint ()
 
endpointoperator= (const endpoint &a_orig)
 
endpointoperator= (endpoint &&a_orig)
 
 snake_case_mv_referrable (std::string, name)
 
 snake_case_mv_referrable (service_ptr_t, service)
 
reply_ptr_t submit_request_message (const request_ptr_t a_request)
 Directly submit a request message to this endpoint. More...
 
void submit_reply_message (const reply_ptr_t a_reply)
 Directly submit a reply message to this endpoint. More...
 
void submit_alert_message (const alert_ptr_t a_alert)
 Directly submit an alert message to this endpoint. More...
 
virtual reply_ptr_t on_request_message (const request_ptr_t a_request)
 Default request handler; passes request to initial request functions. More...
 
virtual void on_reply_message (const reply_ptr_t a_reply)
 
virtual void on_alert_message (const alert_ptr_t a_alert)
 
virtual reply_ptr_t do_run_request (const request_ptr_t a_request)
 
virtual reply_ptr_t do_get_request (const request_ptr_t a_request)
 
virtual reply_ptr_t do_set_request (const request_ptr_t a_request)
 
virtual reply_ptr_t do_cmd_request (const request_ptr_t a_request)
 
void sort_message (const message_ptr_t a_request)
 
uuid_t enable_lockout (const scarab::param_node &a_tag)
 enable lockout with randomly-generated key More...
 
uuid_t enable_lockout (const scarab::param_node &a_tag, uuid_t a_key)
 enable lockout with user-supplied key More...
 
bool disable_lockout (const uuid_t &a_key, bool a_force=false)
 
bool is_locked () const
 
bool check_key (const uuid_t &a_key) const
 

Protected Member Functions

virtual void send_reply (reply_ptr_t a_reply) const
 
bool authenticate (const uuid_t &a_key) const
 Returns true if the server is unlocked or if it's locked and the key matches the lockout key; returns false otherwise. More...
 
 snake_case_mv_referrable (scarab::param_node, lockout_tag)
 
 snake_case_mv_accessible (uuid_t, lockout_key)
 

Private Member Functions

reply_ptr_t __do_run_request (const request_ptr_t a_request)
 
reply_ptr_t __do_get_request (const request_ptr_t a_request)
 
reply_ptr_t __do_set_request (const request_ptr_t a_request)
 
reply_ptr_t __do_cmd_request (const request_ptr_t a_request)
 
reply_ptr_t handle_lock_request (const request_ptr_t a_request)
 
reply_ptr_t handle_unlock_request (const request_ptr_t a_request)
 
reply_ptr_t handle_is_locked_request (const request_ptr_t a_request)
 
reply_ptr_t handle_set_condition_request (const request_ptr_t a_request)
 
reply_ptr_t handle_ping_request (const request_ptr_t a_request)
 
virtual reply_ptr_t __do_handle_set_condition_request (const request_ptr_t a_request)
 Default set-condition: no action taken; override for different behavior. More...
 

Detailed Description

Basic Dripline object capable of receiving and acting on messages.

Author
N.S. Oblath

This class encapsulates the basic behavior of a Dripline endpoint. It can receive and handle messages, and in particular can act on the different request message operations.

An implementation of a particular endpoint should be a class that inherits from endpoint.

An endpoint typically operates as part of a service, and it maintains a link to that service that is primarily used to send messages.

The main behaviors of the endpoint will be broken down by section:

Direct message submission

Messages can be submitted directly to an endpoint using submit_request_message(), submit_reply_message(), and submit_alert_message(). submit_request_message() will return a reply_package_ptr to be used to get the endpoint's reply.

Message handling

Requests

Basic request handling is performed by the on_request_message() function. This can be overridden, but in most cases should not need to be. This function performs the following tasks:

  1. Checks that the request message and the lockout key it contains are valid (does not authenticate the lockout key).
  2. Passes the reqest to the __do_[OP]_request() function according to the request's operation type.
  3. Receives a reply object from the __do_[OP]_request() function
  4. If a valid reply was received (i.e. it has a reply-to address), sends the reply. Otherwise prints a message to the terminal with the results.

Each message operation is handled in two functions: __do_[OP]_request() and do_[OP]_request(). The former takes care of built-in Dripline-standard behavior and should not be overridden. Endpoint-specific behavior should be implemented by overriding the latter.

OP_GET

__do_get_request(): handles get-is-locked if relevant; otherwise calls do_get_request(). do_get_request()`: override this to add get-handling behavior. Default sends an error reply.

OP_SET

__do_set_request(): authenticates the lockout key, then calls do_set_request(). do_set_request()`: override this to add set-handling behavior. Default sends an error reply.

OP_CMD

__do_cmd_request(): authenticates the lockout key. If relevant, handles cmd-lock, cmd-unlock, cmd-set-condition, and cmd-ping; otherwise calls do_cmd_request(). do_cmd_request(): override this to add get-handling behavior. Default sends an error reply.

Alerts

Alert handling can be enabled by overridding the function on_alert_message(). By default these are not handled.

Replies

Reply handling can be enabled by overriding the function on_reply_message(). By default these are not handled.

Lockout

These functions implement the basic lockout functionality that's part of the Dripline standard: enabling and disabling the lock, checking the lock, and validating a key.

Specific request handlers

There are a few types of requests that are built into the Dripline standard, and these are handled by endpoint:

Type: OP_CMD; Specifier: lock – set the lockout for this endpoint using the provided lockout key Type: OP_CMD; Specifier: unlock – disables the lockout for this endpoint Type: OP_GET; Specifier: is-locked – checks whether this endpoint is locked out Type: OP_CMD; Specifier: set-condition – set a particular "condition" for the endpoint. The default behavior is to do nothing, which can be overridden with the function __do_handle_set_condition_request(). Type: OP_CMD; Specifier: ping – send a simple acknowledgement of receipt of the request

Definition at line 95 of file endpoint.hh.

Constructor & Destructor Documentation

◆ endpoint() [1/3]

endpoint ( const std::string &  a_name)

Definition at line 30 of file endpoint.cc.

◆ endpoint() [2/3]

endpoint ( const endpoint a_orig)

Definition at line 38 of file endpoint.cc.

◆ endpoint() [3/3]

endpoint ( endpoint &&  a_orig)

Definition at line 45 of file endpoint.cc.

◆ ~endpoint()

~endpoint ( )
virtual

Definition at line 52 of file endpoint.cc.

Member Function Documentation

◆ __do_cmd_request()

reply_ptr_t __do_cmd_request ( const request_ptr_t  a_request)
private

Definition at line 336 of file endpoint.cc.

◆ __do_get_request()

reply_ptr_t __do_get_request ( const request_ptr_t  a_request)
private

Definition at line 301 of file endpoint.cc.

◆ __do_handle_set_condition_request()

reply_ptr_t __do_handle_set_condition_request ( const request_ptr_t  a_request)
inlineprivatevirtual

Default set-condition: no action taken; override for different behavior.

Definition at line 246 of file endpoint.hh.

◆ __do_run_request()

reply_ptr_t __do_run_request ( const request_ptr_t  a_request)
private

Definition at line 285 of file endpoint.cc.

◆ __do_set_request()

reply_ptr_t __do_set_request ( const request_ptr_t  a_request)
private

Definition at line 320 of file endpoint.cc.

◆ authenticate()

bool authenticate ( const uuid_t a_key) const
protected

Returns true if the server is unlocked or if it's locked and the key matches the lockout key; returns false otherwise.

Definition at line 400 of file endpoint.cc.

◆ check_key()

bool check_key ( const uuid_t a_key) const
inline

Definition at line 241 of file endpoint.hh.

◆ disable_lockout()

bool disable_lockout ( const uuid_t a_key,
bool  a_force = false 
)

Definition at line 391 of file endpoint.cc.

◆ do_cmd_request()

reply_ptr_t do_cmd_request ( const request_ptr_t  a_request)
inlinevirtual

Reimplemented in hub, and simple_service.

Definition at line 226 of file endpoint.hh.

◆ do_get_request()

reply_ptr_t do_get_request ( const request_ptr_t  a_request)
inlinevirtual

◆ do_run_request()

reply_ptr_t do_run_request ( const request_ptr_t  a_request)
inlinevirtual

Reimplemented in hub, and simple_service.

Definition at line 211 of file endpoint.hh.

◆ do_set_request()

reply_ptr_t do_set_request ( const request_ptr_t  a_request)
inlinevirtual

Reimplemented in hub, oscillator_ep_amplitude, oscillator_ep_frequency, and simple_service.

Definition at line 221 of file endpoint.hh.

◆ enable_lockout() [1/2]

uuid_t enable_lockout ( const scarab::param_node &  a_tag)
inline

enable lockout with randomly-generated key

Definition at line 231 of file endpoint.hh.

◆ enable_lockout() [2/2]

uuid_t enable_lockout ( const scarab::param_node &  a_tag,
uuid_t  a_key 
)

enable lockout with user-supplied key

Definition at line 382 of file endpoint.cc.

◆ handle_is_locked_request()

reply_ptr_t handle_is_locked_request ( const request_ptr_t  a_request)
private

Definition at line 442 of file endpoint.cc.

◆ handle_lock_request()

reply_ptr_t handle_lock_request ( const request_ptr_t  a_request)
private

Definition at line 407 of file endpoint.cc.

◆ handle_ping_request()

reply_ptr_t handle_ping_request ( const request_ptr_t  a_request)
private

Definition at line 452 of file endpoint.cc.

◆ handle_set_condition_request()

reply_ptr_t handle_set_condition_request ( const request_ptr_t  a_request)
private

Definition at line 437 of file endpoint.cc.

◆ handle_unlock_request()

reply_ptr_t handle_unlock_request ( const request_ptr_t  a_request)
private

Definition at line 421 of file endpoint.cc.

◆ is_locked()

bool is_locked ( ) const
inline

Definition at line 236 of file endpoint.hh.

◆ on_alert_message()

void on_alert_message ( const alert_ptr_t  a_alert)
virtual

Default alert handler; throws a dripline_error. Override this to enable handling of alerts.

Definition at line 280 of file endpoint.cc.

◆ on_reply_message()

void on_reply_message ( const reply_ptr_t  a_reply)
virtual

Default reply handler; throws a dripline_error. Override this to enable handling of replies.

Definition at line 275 of file endpoint.cc.

◆ on_request_message()

reply_ptr_t on_request_message ( const request_ptr_t  a_request)
virtual

Default request handler; passes request to initial request functions.

Reimplemented in service.

Definition at line 88 of file endpoint.cc.

◆ operator=() [1/2]

endpoint & operator= ( const endpoint a_orig)

Definition at line 55 of file endpoint.cc.

◆ operator=() [2/2]

endpoint & operator= ( endpoint &&  a_orig)

Definition at line 64 of file endpoint.cc.

◆ send_reply()

void send_reply ( reply_ptr_t  a_reply) const
protectedvirtual

Reimplemented in service.

Definition at line 232 of file endpoint.cc.

◆ snake_case_mv_accessible()

snake_case_mv_accessible ( uuid_t  ,
lockout_key   
)
protected

◆ snake_case_mv_referrable() [1/3]

snake_case_mv_referrable ( std::string  ,
name   
)

◆ snake_case_mv_referrable() [2/3]

snake_case_mv_referrable ( service_ptr_t  ,
service   
)

◆ snake_case_mv_referrable() [3/3]

snake_case_mv_referrable ( scarab::param_node  ,
lockout_tag   
)
protected

◆ sort_message()

void sort_message ( const message_ptr_t  a_request)

Calls the appropriate request handler on a message object. Message type is explicitly checked within this function. Note that you cannot get the reply_ptr_t using this method if you submit a request. This is really intended for use when handling messages received by a parent object.

Definition at line 212 of file endpoint.cc.

◆ submit_alert_message()

void submit_alert_message ( const alert_ptr_t  a_alert)

Directly submit an alert message to this endpoint.

Definition at line 78 of file endpoint.cc.

◆ submit_reply_message()

void submit_reply_message ( const reply_ptr_t  a_reply)

Directly submit a reply message to this endpoint.

Definition at line 83 of file endpoint.cc.

◆ submit_request_message()

reply_ptr_t submit_request_message ( const request_ptr_t  a_request)

Directly submit a request message to this endpoint.

Definition at line 73 of file endpoint.cc.


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