CppGraph Application Framework©
Copyright © 2004-202x Geoff Goldberg
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | List of all members
cppgraph::graph_thread Struct Reference

A graph thread is a concrete derived class of thread that owns a node graph and that can receive messages, in addition to sending them. More...

#include <graph_thread.h>

Inherits thread.

Public Member Functions

node_handle get_root (error_action_enum error_action_type) const
 Returns the worker thread's root node. More...
 
void post_end_message ()
 Appends an end_thread_message to the worker thread's message queue. More...
 
void set_root (node_handle const &h_root)
 Sets the worker thread's root node. More...
 

Static Public Member Functions

static graph_threadget_this_thread (error_action_enum error_action_type)
 Returns a pointer to the current worker thread's graph_thread owner. More...
 

Protected Member Functions

 graph_thread ()
 Constructor. More...
 
 graph_thread (node_handle const &h_root)
 Constructor. More...
 
void on_pre_message_loop ()
 Function called from the worker thread before its message loop starts.
 
virtual void virtual_on_post_message_loop ()
 Function called from the worker thread after its message loop ends.
 
virtual void virtual_on_pre_message_loop ()
 Function called from the worker thread before its message loop starts.
 

Private Member Functions

void on_end_thread_message (cppgraph::node_handle_t< cppgraph ::end_thread_message > const &h_message)
 [auto-generated] Handler for messages of type cppgraph :: end_thread_message . More...
 
void on_nodes_request_message (cppgraph::node_handle_t< cppgraph ::nodes_request_message > const &h_message)
 [auto-generated] Handler for messages of type cppgraph :: nodes_request_message . More...
 
void on_post_message_loop ()
 Function called from the worker thread after its message loop ends. This base class implementation is a NOP.
 
void on_set_root_message (cppgraph::node_handle_t< cppgraph ::set_root_message > const &h_message)
 [auto-generated] Handler for messages of type cppgraph :: set_root_message . More...
 

Detailed Description

A graph thread is a concrete derived class of thread that owns a node graph and that can receive messages, in addition to sending them.

The node graph of a graph_thread exists in its worker thread. It can be provided in one of 2 ways:

#### Object Diagram #

dot_inline_dotgraph_242.png

Class Diagram

graph_thread.png

Constructor & Destructor Documentation

◆ graph_thread() [1/2]

cppgraph::graph_thread::graph_thread ( )
protected

Constructor.

An O/S thread is constructed and started. It enters a loop receiving and sending messages. While waiting for messages, the thread sleeps. The thread's graph must be supplied by posting a set_root_message to the thread.

◆ graph_thread() [2/2]

cppgraph::graph_thread::graph_thread ( node_handle const &  h_root)
protected

Constructor.

An O/S thread is constructed and started. It enters a loop receiving and sending messages. While waiting for messages, the thread sleeps.

Parameters
h_rootThe node graph rooted at this node is assigned as the worker thread's node graph.

Member Function Documentation

◆ get_root()

node_handle cppgraph::graph_thread::get_root ( error_action_enum  error_action_type) const

Returns the worker thread's root node.

Callable only from this graph_node's worker thread.

Parameters
error_action_typeThe action to take if the graph is nullptr.
Exceptions
exceptionThe graph is nullptr AND error_action_type != error_action_enum::e_no_assert.
Returns
A handle to the worker thread's root node.

◆ get_this_thread()

graph_thread * cppgraph::graph_thread::get_this_thread ( error_action_enum  error_action_type)
static

Returns a pointer to the current worker thread's graph_thread owner.

Callable only from the worker thread owned by a graph_thread.

Parameters
error_action_typeThe action to take if this function is not called from a worker thread owned by a graph_thread.
Returns
A pointer to the graph_thread instance that owns the current worker thread, or nullptr if this function was not called from a worker thread owned by a graph_thread.
Exceptions
exceptionThis function was not called from a worker thread owned by a graph_thread AND error_action_type != error_action_enum::e_no_assert.

◆ on_end_thread_message()

void cppgraph::graph_thread::on_end_thread_message ( cppgraph::node_handle_t< cppgraph ::end_thread_message > const &  h_message)
private

[auto-generated] Handler for messages of type cppgraph :: end_thread_message .

Parameters
h_messageMessage to handle.

◆ on_nodes_request_message()

void cppgraph::graph_thread::on_nodes_request_message ( cppgraph::node_handle_t< cppgraph ::nodes_request_message > const &  h_message)
private

[auto-generated] Handler for messages of type cppgraph :: nodes_request_message .

Parameters
h_messageMessage to handle.

◆ on_set_root_message()

void cppgraph::graph_thread::on_set_root_message ( cppgraph::node_handle_t< cppgraph ::set_root_message > const &  h_message)
private

[auto-generated] Handler for messages of type cppgraph :: set_root_message .

Parameters
h_messageMessage to handle.

◆ post_end_message()

void cppgraph::graph_thread::post_end_message ( )

Appends an end_thread_message to the worker thread's message queue.

When the worker thread pulls the message from its queue, it exits its message loop and terminates. This function may be called from any thread.

Callable only from the owner thread.

See also
thread::request_end().

◆ set_root()

void cppgraph::graph_thread::set_root ( node_handle const &  h_root)

Sets the worker thread's root node.

Callable from any thread.

Parameters
h_rootSpecifies the node to set as the current graph thread's root.
Exceptions
exceptionh_root is nullptr.
See also
get_root().

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