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

Introduction

The Synapse App SDK provides a framework for building applications that can process and publish data using various middleware solutions. This SDK handles the complexities of inter-process communication, performance profiling, and configuration management, allowing you to focus on your application logic.

Getting Started

To create a new Synapse application, you need to inherit from the synapse::App base class and implement a few key methods.

Basic Application Structure

#include "synapse-app-sdk/app/app.hpp"
// Include any other headers you need
class MyApplication : public synapse::App {
public:
// Default constructor
MyApplication() : synapse::App() {}
// Constructor with custom config path
explicit MyApplication(const std::string& config_path)
: synapse::App(config_path) {}
// Setup function - initialize your application here
bool setup() override {
// Create taps for publishing data
// Setup data reader
const int broadband_node_id = 1;
setup_reader(broadband_node_id);
// Any other initialization code
return true; // Return true if setup successful
}
// Main loop - where your application logic goes
void main() override {
while (node_running_) {
// Your processing logic here
// Example: read data
auto message = data_reader_->receive_message();
// Process data
// ...
// Publish results
MyProtobufMessage output_message;
// ... fill in message fields
publish_tap("my_tap_name", output_message);
// Optional profiling
start_profile("my_function");
my_function();
stop_profile("my_function");
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
}
};
// Application entry point
int main(int argc, char* argv[]) {
return synapse::Entrypoint<MyApplication>();
}
Base class for Synapse applications.
Definition app.hpp:29
void stop_profile(const std::string &name)
Stops profiling a function.
Definition app.cpp:145
virtual void main()=0
Main loop to be implemented by derived classes.
void start_profile(const std::string &name)
Starts profiling a function.
Definition app.cpp:138
virtual bool setup()=0
Setup function to be implemented by derived classes.
bool publish_tap(const std::string &name, const T &message)
Publishes a message to a tap.
Definition app.hpp:77
bool create_tap(const std::string &name)
Creates a tap for publishing messages.
Definition app.hpp:50
virtual bool setup_reader(const uint32_t node_id)
Sets up the data reader.
Definition app.cpp:21

Key Components to Implement

  1. setup() - Override this method to initialize your application:
    • Create taps for data publishing using create_tap<MessageType>(name)
    • Setup data readers with setup_reader(node_id)
    • Initialize any other resources your application needs
  2. main() - Override this method to implement your application's main processing loop:
    • Check node_running_ flag to determine when to stop
    • Read data using data_reader_->receive_message() or data_reader_->receive_multipart()
    • Process the data according to your application's logic
    • Publish results using publish_tap(name, message)

Key Features

Data Publishing

Use the tap system to publish data:

// Create the tap during setup
create_tap<MyMessage>("my_tap_name");
// Publish messages
MyMessage message;
// ... fill in message fields
publish_tap("my_tap_name", message);

Data Reading

Read data from other applications:

// Setup reader with appropriate node ID
setup_reader(node_id);
// Receive messages
auto message = data_reader_->receive_message();
if (message.has_value()) {
// Process the message
}
// Or receive multipart messages
auto messages = data_reader_->receive_multipart();

Performance Profiling

Profile your application's functions:

// Enable profiling
enable_function_profiling(std::chrono::milliseconds(1000));
// Profile specific functions
start_profile("my_function");
my_function();
stop_profile("my_function");
// Print the profile
print_profile("my_function");

Configuration

Access the device configuration:

// Get configuration
auto config = device_configuration();
// Use configuration values
auto value = config.some_value();

Application Lifecycle

Your application will automatically handle signals like SIGINT (Ctrl+C) to gracefully shut down. The AppRunner class manages your application's lifecycle, calling your setup() method during initialization and ensuring proper cleanup when the application exits.

Best Practices

  1. Keep the main loop efficient and avoid blocking operations
  2. Use the profiling tools to identify performance bottlenecks
  3. Check return values from API calls to handle errors gracefully
  4. Use the tap system for structured data publishing