Skip to content

Commit b6e2775

Browse files
committed
[doc] commented source files of simple-embedding
1 parent b55eea5 commit b6e2775

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

examples/simple-embedding/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
* Simple Embedding Example
22

3+
This example illustrates how to integrate monilog in your C++ application.
4+
35
In this directory:
46
- Create and activate a Python venv.
57
- Install pybind11: `pip install pybind11`

examples/simple-embedding/src/SimpleEmbedding.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,38 @@ namespace fs = std::filesystem;
77

88
int main()
99
{
10+
// Retrieve the path where the Python scripts to use are located (can provide multiple locations).
1011
std::string path = fs::current_path();
1112
std::vector<std::string> python_path = { path + "/src/" };
13+
// Provide the Python scripts to include.
1214
std::vector<std::string> python_scripts = {"example_moniloggers"};
15+
// Name of the interface module (here, an embedded module declared above) exposing the execution context of the application.
1316
std::string interface_module = "example_interface";
17+
// Initialization function for the interface module.
1418
std::function<void (pybind11::module_, pybind11::object)> interface_module_initializer =
1519
[](pybind11::module_ iterativeheatequation_module, pybind11::object context_class) { };
1620

21+
// Define base execution events emitted by the application, to which moniloggers can register.
1722
MoniLog::register_base_events({
1823
{"SomeEvent", 0},
1924
{"SomeOtherEvent", 1}
2025
});
2126

27+
// Define a composite event, emitted when either of its triggering events are emitted.
2228
MoniLog::register_composite_event("SomeCompositeEvent", {"SomeEvent", "SomeOtherEvent"});
2329

30+
// Instantiating the execution context accessible from Python.
2431
std::shared_ptr<MoniLog::MoniLogExecutionContext> ctx(new MoniLog::MoniLogExecutionContext());
2532

33+
// Bootstrapping monilog, consisting mainly of starting the Python interpreter, initializing
34+
// the monilog module, and evaluating the provided scripts.
2635
MoniLog::bootstrap_monilog(python_path, python_scripts, interface_module, interface_module_initializer);
2736

37+
// Emitting some base events, triggering the registered moniloggers.
2838
MoniLog::trigger(0, ctx);
2939
MoniLog::trigger(1, ctx);
3040

41+
// Emitting a composite event (can also emit base event by name).
3142
MoniLog::trigger("SomeCompositeEvent", ctx);
3243

3344
}

0 commit comments

Comments
 (0)