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"
public:
MyApplication() : synapse::App() {}
explicit MyApplication(const std::string& config_path)
: synapse::App(config_path) {}
const int broadband_node_id = 1;
return true;
}
while (node_running_) {
auto message = data_reader_->receive_message();
MyProtobufMessage output_message;
my_function();
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
}
};
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
- 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
- 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_tap<MyMessage>("my_tap_name");
MyMessage message;
publish_tap("my_tap_name", message);
Data Reading
Read data from other applications:
setup_reader(node_id);
auto message = data_reader_->receive_message();
if (message.has_value()) {
}
auto messages = data_reader_->receive_multipart();
Performance Profiling
Profile your application's functions:
enable_function_profiling(std::chrono::milliseconds(1000));
start_profile("my_function");
my_function();
stop_profile("my_function");
print_profile("my_function");
Configuration
Access the device configuration:
auto config = device_configuration();
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
- Keep the main loop efficient and avoid blocking operations
- Use the profiling tools to identify performance bottlenecks
- Check return values from API calls to handle errors gracefully
- Use the tap system for structured data publishing