Stages¶
More detailed info about stages, how they should be structured, and what should go where.
Minimal Definition¶
A minimalist stage is defined in ExampleProducer.cpp and reproduced below. This should be considered a minimal stage.
1#include "ExampleProducer.hpp"
2
3#include <stdint.h> // for uint32_t, uint8_t
4#include <functional> // for bind, function
5
6#include "StageFactory.hpp" // for REGISTER_KOTEKAN_STAGE
7#include "kotekanLogging.hpp" // for INFO
8#include "visUtil.hpp" // for frameID, modulo
9#include "fmt.hpp" // for compile_string_to_view
10
11// Include the classes we will be using
12using kotekan::bufferContainer;
13using kotekan::Config;
14using kotekan::Stage;
15
16// Register the stage with the stage factory.
17REGISTER_KOTEKAN_STAGE(ExampleProducer);
18
19ExampleProducer::ExampleProducer(Config& config, const std::string& unique_name,
20 bufferContainer& buffer_container) :
21 Stage(config, unique_name, buffer_container, std::bind(&ExampleProducer::main_thread, this)) {
22
23 // Register as producer of out_buf
24 out_buf = get_buffer("out_buf");
25 out_buf->register_producer(unique_name);
26
27 // Load options that can be set in config
28 // The arguments to config.get_default are the:
29 // unique_name_for_stage, name_of_config, default_value_if_not_set
30 _init_value = config.get_default<float>(unique_name, "init_value", 0.f);
31}
32
33
34ExampleProducer::~ExampleProducer() {}
35
36// Framework managed pthread
37void ExampleProducer::main_thread() {
38
39 // Ring buffer pointer
40 frameID frame_id(out_buf);
41
42 // Get the no. of elements in each frame
43 uint32_t frame_length = out_buf->frame_size / sizeof(float);
44
45 // Until the thread is stopped
46 while (!stop_thread) {
47
48 // Acquire frame
49 uint8_t* frame = out_buf->wait_for_empty_frame(unique_name, frame_id);
50 // A null frame is returned on shutdown
51 if (frame == nullptr)
52 break;
53
54 float* data = (float*)frame;
55
56 for (uint32_t i = 0; i < frame_length; i++) {
57 data[i] = _init_value;
58 }
59
60 INFO("{:s}[{:d}] initialised to: {:f}, ..., {:f}, ..., {:f}", out_buf->buffer_name,
61 frame_id, data[0], data[frame_length / 2], data[frame_length - 1]);
62
63 // Release frame
64 out_buf->mark_frame_full(unique_name, frame_id);
65
66 // Increase the ring pointer
67 frame_id++;
68 }
69}
Using breathe to parse the autodoc,
-
class ExampleProducer : public kotekan::Stage¶
An example producer stage that sets each element of a buffer to a constant value.
- Buffers
out_bufThe buffer to process the contents of.Format: any
Metadata:
any
- Param init_value:
Default 0. The value to set each element to.
Public Functions
-
ExampleProducer(kotekan::Config &config, const std::string &unique_name, kotekan::bufferContainer &buffer_container)¶
Constructor for the stage Note: you can use the macro STAGE_CONSTRUCTOR(ExampleProducer) if your constructor does not need additional customisation and you wish to hide the complexity.
-
virtual ~ExampleProducer()¶
Deconstructor - Called on shutdown, after
main_threadhas exited.
-
virtual void main_thread() override¶
Framework managed pthread.