synapse-app-sdk
C++ SDK for Synapse Apps
Loading...
Searching...
No Matches
synapse::App Class Referenceabstract

Base class for Synapse applications. More...

#include <app.hpp>

Collaboration diagram for synapse::App:

Public Member Functions

 App ()
 Default constructor.
 App (const std::string &configuration_path)
 Constructor with custom configuration path.
virtual ~App ()=default
 Virtual destructor.
template<typename T>
bool create_tap (const std::string &name)
 Creates a tap for publishing messages.
template<typename T>
bool publish_tap (const std::string &name, const T &message)
 Publishes a message to a tap.
template<typename T>
bool create_consumer_tap (const std::string &name, const std::function< void(const T &message)> &callback)
 Creates a consumer tap for receiving messages Tip: Don't do a lot of work in the callback, it will be called in a separate thread Instead, just queue the message for later processing.
virtual bool setup ()=0
 Setup function to be implemented by derived classes.
virtual bool start ()
 Starts the application.
virtual void stop ()
 Stops the application.

Protected Member Functions

virtual bool setup_reader (const uint32_t node_id)
 Sets up the data reader.
virtual bool setup_publisher (const PublisherType &publisher_type, const std::string &publisher_endpoint)
 Sets up the data publisher.
bool load_device_configuration (const std::string &path)
 Loads device configuration from file.
bool enable_function_profiling (const std::chrono::milliseconds &period)
 Enables function profiling.
void start_profile (const std::string &name)
 Starts profiling a function.
void stop_profile (const std::string &name)
 Stops profiling a function.
void print_profile (const std::string &name)
 Prints profile information.
bool get_app_config (std::function< bool(const synapse::ApplicationNodeConfig &)> validator, synapse::ApplicationNodeConfig &output_config)
 Gets the application parameters from the device configuration.
void disable_log_streaming ()
virtual void main ()=0
 Main loop to be implemented by derived classes.

Protected Attributes

std::atomic< bool > node_running_ {false}
 Flag indicating if the node is running.
zmq::context_t zmq_context_
 ZMQ context for communication.
std::shared_ptr< synapse::ZMQDataReaderdata_reader_ {nullptr}
 Data reader for receiving data.
std::shared_ptr< synapse::DataPublisherdata_publisher_ {nullptr}
 Data publisher for sending data.
TapManager tap_manager_
 Manager for handling taps.
std::shared_ptr< synapse::log::SynapseLogSink< std::mutex > > log_sink_ {nullptr}
 Custom log sink for capturing and streaming application logs.
std::optional< uint64_t > log_subscription_id_ {std::nullopt}
 ID for the log streaming subscription.
synapse::DeviceConfiguration device_configuration_
 Device configuration.
synapse::FunctionProfilerManager function_profiler_manager_
 Function profiler manager.
std::thread function_profiling_thread_
 Thread for function profiling.
std::atomic< bool > function_profiling_enabled_ {false}
 Flag indicating if function profiling is enabled.
std::thread main_loop_thread_
 Thread for the main loop.

Detailed Description

Base class for Synapse applications.

Provides core functionality for data reading/publishing, tap management, and performance profiling.

Constructor & Destructor Documentation

◆ App()

synapse::App::App ( const std::string & configuration_path)
explicit

Constructor with custom configuration path.

Parameters
configuration_pathPath to device configuration file

Member Function Documentation

◆ create_consumer_tap()

template<typename T>
bool synapse::App::create_consumer_tap ( const std::string & name,
const std::function< void(const T &message)> & callback )
inline

Creates a consumer tap for receiving messages Tip: Don't do a lot of work in the callback, it will be called in a separate thread Instead, just queue the message for later processing.

Template Parameters
TProtobuf message type
Parameters
nameName of the tap
callbackFunction to be called when a message is received
Returns
true if tap was created successfully, false otherwise

◆ create_tap()

template<typename T>
bool synapse::App::create_tap ( const std::string & name)
inline

Creates a tap for publishing messages.

Template Parameters
TProtobuf message type
Parameters
nameName of the tap
Returns
true if tap was created successfully, false otherwise

◆ enable_function_profiling()

bool synapse::App::enable_function_profiling ( const std::chrono::milliseconds & period)
protected

Enables function profiling.

Parameters
periodPeriod for profiling
Returns
true if profiling was enabled successfully, false otherwise

◆ get_app_config()

bool synapse::App::get_app_config ( std::function< bool(const synapse::ApplicationNodeConfig &)> validator,
synapse::ApplicationNodeConfig & output_config )
inlineprotected

Gets the application parameters from the device configuration.

Note
This function will try to load and validate the parameters from the device configuration
Parameters
validatorFunction to validate the parameters (takes const synapse::ApplicationNodeConfig& and returns bool)
output_configApplication node configuration to populate
Returns
true if parameters were retrieved successfully, false otherwise

◆ load_device_configuration()

bool synapse::App::load_device_configuration ( const std::string & path)
protected

Loads device configuration from file.

Parameters
pathPath to configuration file
Returns
true if configuration was loaded successfully, false otherwise

◆ print_profile()

void synapse::App::print_profile ( const std::string & name)
protected

Prints profile information.

Parameters
nameName of the function

◆ publish_tap()

template<typename T>
bool synapse::App::publish_tap ( const std::string & name,
const T & message )
inline

Publishes a message to a tap.

Template Parameters
TProtobuf message type
Parameters
nameName of the tap
messageMessage to publish
Returns
true if message was published successfully, false otherwise

◆ setup()

virtual bool synapse::App::setup ( )
pure virtual

Setup function to be implemented by derived classes.

Returns
true if setup was successful, false otherwise

◆ setup_publisher()

bool synapse::App::setup_publisher ( const PublisherType & publisher_type,
const std::string & publisher_endpoint )
protectedvirtual

Sets up the data publisher.

Parameters
publisher_typeType of publisher
publisher_endpointEndpoint for the publisher
Returns
true if publisher was set up successfully, false otherwise

◆ setup_reader()

bool synapse::App::setup_reader ( const uint32_t node_id)
protectedvirtual

Sets up the data reader.

Parameters
node_idID of the node to read from
Returns
true if reader was set up successfully, false otherwise

◆ start()

bool synapse::App::start ( )
virtual

Starts the application.

Returns
true if application started successfully, false otherwise

◆ start_profile()

void synapse::App::start_profile ( const std::string & name)
protected

Starts profiling a function.

Parameters
nameName of the function

◆ stop_profile()

void synapse::App::stop_profile ( const std::string & name)
protected

Stops profiling a function.

Parameters
nameName of the function

The documentation for this class was generated from the following files:
  • include/synapse-app-sdk/app/app.hpp
  • src/app/app.cpp