Wrapping Rogue In C++
For embedding or controlling a PyRogue tree from a C++ application, Rogue
provides rogue::interfaces::api::Bsp. This wrapper sits in the built-in
interfaces section because it is an integration layer around a running PyRogue
tree rather than part of the tree model itself.
Bsp wraps a PyRogue node or Root object and provides helper methods for
node traversal, command execution, variable access, and root-level listeners.
Creating A Root Wrapper
Bsp can construct and start a PyRogue root directly from Python module/class
names:
#include "rogue/interfaces/api/Bsp.h"
// Imports pyrogue.examples and constructs ExampleRoot().
rogue::interfaces::api::Bsp bsp("pyrogue.examples", "ExampleRoot");
If constructed this way, the root is started in the constructor and stopped in the wrapper destructor.
This is the common pattern when a C++ process needs to host the PyRogue application directly instead of connecting to it through a remote client interface.
Node Traversal And Variable Access
Use operator[] for hierarchical traversal and getNode() for full-path
lookup:
// Read variable from local cached value (no forced hardware read).
std::string localTime = bsp["LocalTime"].get();
// Write variable and then force readback.
bsp["AxiVersion"]["ScratchPad"].setWrite("0x1111");
std::string scratch = bsp["AxiVersion"]["ScratchPad"].readGet();
// Full-path lookup returns a shared pointer wrapper.
auto node = bsp.getNode("ExampleRoot.AxiVersion.ScratchPad");
std::string scratch2 = node->get();
Commands
Command nodes are invoked through operator() or execute():
// Execute commands without arguments.
bsp["WriteAll"]();
bsp["ReadAll"]();
// Execute command with argument string.
std::string yaml = bsp["GetYamlConfig"]("True");
Variable Listeners (Root Only)
Variable listeners can be attached only on a root wrapper:
void varListener(std::string path, std::string value) {
// Called for each variable update pushed to this listener.
printf("Var Listener: %s = %s\n", path.c_str(), value.c_str());
}
void varDone() {
// Called when the current listener batch is complete.
printf("Var Done\n");
}
bsp.addVarListener(&varListener, &varDone);
What To Explore Next
Built-in interface overview: Interfaces
Version checks and compatibility guards: Rogue Version Helper
SQL-backed tree logging: SQL Logging