ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
web_server_idf.h
Go to the documentation of this file.
1#pragma once
2#ifdef USE_ESP32
3
7#include <esp_http_server.h>
8
9#include <atomic>
10#include <functional>
11#include <list>
12#include <map>
13#include <span>
14#include <string>
15#include <utility>
16#include <vector>
17
18#ifdef USE_WEBSERVER
21#include "sse_chunk.h"
22#endif
23
24struct iovec; // NOLINT(readability-identifier-naming) - forward decl of lwip's gather list entry
25
26namespace esphome {
27#ifdef USE_WEBSERVER
28namespace web_server {
29class WebServer;
30}; // namespace web_server
31#endif
32namespace web_server_idf {
33
35 public:
36 AsyncWebParameter(std::string name, std::string value) : name_(std::move(name)), value_(std::move(value)) {}
37 const std::string &name() const { return this->name_; }
38 const std::string &value() const { return this->value_; }
39
40 protected:
41 std::string name_;
42 std::string value_;
43};
44
46
49
50 public:
53
54 // NOLINTNEXTLINE(readability-identifier-naming)
55 void addHeader(const char *name, const char *value);
56
57 virtual const char *get_content_data() const = 0;
58 virtual size_t get_content_size() const = 0;
59
60 protected:
62 // Bit i set: this response set default header i itself, so it is not sent at send time
64};
65
67 public:
69
70 const char *get_content_data() const override { return nullptr; };
71 size_t get_content_size() const override { return 0; };
72};
73
75 public:
77 : AsyncWebServerResponse(req), content_(std::move(content)) {}
78
79 const char *get_content_data() const override { return this->content_.c_str(); };
80 size_t get_content_size() const override { return this->content_.size(); };
81
82 protected:
83 std::string content_;
84};
85
87 public:
89
90 const char *get_content_data() const override { return this->content_.c_str(); };
91 size_t get_content_size() const override { return this->content_.size(); };
92
93 void print(const char *str) { this->content_.append(str); }
94 void print(const std::string &str) { this->content_.append(str); }
95 void print(float value);
96 void printf(const char *fmt, ...) __attribute__((format(printf, 2, 3)));
97 void write(uint8_t c) { this->content_.push_back(static_cast<char>(c)); }
98
99 protected:
100 std::string content_;
101};
102
104 public:
105 AsyncWebServerResponseProgmem(const AsyncWebServerRequest *req, const uint8_t *data, const size_t size)
106 : AsyncWebServerResponse(req), data_(data), size_(size) {}
107
108 const char *get_content_data() const override { return reinterpret_cast<const char *>(this->data_); };
109 size_t get_content_size() const override { return this->size_; };
110
111 protected:
112 const uint8_t *data_;
113 size_t size_;
114};
115
117 friend class AsyncWebServer;
118
119 public:
121
122 http_method method() const { return static_cast<http_method>(this->req_->method); }
123 static constexpr size_t URL_BUF_SIZE = CONFIG_HTTPD_MAX_URI_LEN + 1;
126 StringRef url_to(std::span<char, URL_BUF_SIZE> buffer) const;
127 // NOLINTNEXTLINE(readability-identifier-naming)
128 size_t contentLength() const { return this->req_->content_len; }
129
130#ifdef USE_WEBSERVER_AUTH
131 bool authenticate(const char *username, const char *password) const;
132 // NOLINTNEXTLINE(readability-identifier-naming)
133 void requestAuthentication() const;
134#endif
135
136 void redirect(const char *url);
137 void redirect(const std::string &url) { this->redirect(url.c_str()); }
138
139 void send(AsyncWebServerResponse *response);
140 inline void ESPHOME_ALWAYS_INLINE send(int code, const char *content_type = nullptr, const char *content = nullptr) {
141 this->init_response_(nullptr, code, content_type);
142 if (content) {
143 httpd_resp_send(*this, content, HTTPD_RESP_USE_STRLEN);
144 } else {
145 httpd_resp_send(*this, nullptr, 0);
146 }
147 }
148 // NOLINTNEXTLINE(readability-identifier-naming)
149 AsyncWebServerResponse *beginResponse(int code, const char *content_type) {
150 auto *res = new AsyncWebServerResponseEmpty(this); // NOLINT(cppcoreguidelines-owning-memory)
151 this->init_response_(res, code, content_type);
152 return res;
153 }
154 // NOLINTNEXTLINE(readability-identifier-naming)
155 AsyncWebServerResponse *beginResponse(int code, const char *content_type, const std::string &content) {
156 auto *res = new AsyncWebServerResponseContent(this, content); // NOLINT(cppcoreguidelines-owning-memory)
157 this->init_response_(res, code, content_type);
158 return res;
159 }
160 // NOLINTNEXTLINE(readability-identifier-naming)
161 AsyncWebServerResponse *beginResponse(int code, const char *content_type, const uint8_t *data,
162 const size_t data_size) {
163 auto *res = new AsyncWebServerResponseProgmem(this, data, data_size); // NOLINT(cppcoreguidelines-owning-memory)
164 this->init_response_(res, code, content_type);
165 return res;
166 }
167 // NOLINTNEXTLINE(readability-identifier-naming)
168 AsyncResponseStream *beginResponseStream(const char *content_type) {
169 auto *res = new AsyncResponseStream(this); // NOLINT(cppcoreguidelines-owning-memory)
170 this->init_response_(res, 200, content_type);
171 return res;
172 }
173
174 // NOLINTNEXTLINE(readability-identifier-naming)
175 bool hasParam(const char *name) { return this->getParam(name) != nullptr; }
176 // NOLINTNEXTLINE(readability-identifier-naming)
177 bool hasParam(const std::string &name) { return this->getParam(name.c_str()) != nullptr; }
178 // NOLINTNEXTLINE(readability-identifier-naming)
179 AsyncWebParameter *getParam(const char *name);
180 // NOLINTNEXTLINE(readability-identifier-naming)
181 AsyncWebParameter *getParam(const std::string &name) { return this->getParam(name.c_str()); }
182
183 // NOLINTNEXTLINE(readability-identifier-naming)
184 bool hasArg(const char *name);
185 std::string arg(const char *name);
186 std::string arg(const std::string &name) { return this->arg(name.c_str()); }
187
188#ifdef USE_WEBSERVER_OTA
190 // NOLINTNEXTLINE(readability-identifier-naming)
191 void onDisconnect(std::function<void()> fn) { this->on_disconnect_ = std::move(fn); }
192#endif
193
194 operator httpd_req_t *() const { return this->req_; }
195 optional<std::string> get_header(const char *name) const;
198 size_t get_header_to(const char *name, std::span<char> buf) const;
199 // NOLINTNEXTLINE(readability-identifier-naming)
200 bool hasHeader(const char *name) const;
201
202 protected:
203 httpd_req_t *req_;
205 // Use vector instead of map/unordered_map: most requests have 0-3 params, so linear search
206 // is faster than tree/hash overhead. AsyncWebParameter stores both name and value to avoid
207 // duplicate storage. Only successful lookups are cached to prevent cache pollution when
208 // handlers check for optional parameters that don't exist.
209 optional<std::string> find_query_value_(const char *name) const;
210 std::vector<AsyncWebParameter *> params_;
211 std::string post_query_;
212#ifdef USE_WEBSERVER_OTA
213 std::function<void()> on_disconnect_;
214#endif
215 AsyncWebServerRequest(httpd_req_t *req) : req_(req) {}
216 AsyncWebServerRequest(httpd_req_t *req, std::string post_query) : req_(req), post_query_(std::move(post_query)) {}
217 void init_response_(AsyncWebServerResponse *rsp, int code, const char *content_type);
218};
219
220class AsyncWebHandler;
221
223 public:
224 AsyncWebServer(uint16_t port) : port_(port) {};
225 ~AsyncWebServer() { this->end(); }
226
227 // NOLINTNEXTLINE(readability-identifier-naming)
228 void onNotFound(std::function<void(AsyncWebServerRequest *request)> &&fn) { on_not_found_ = std::move(fn); }
229
230 void begin();
231 void end();
232
233 // NOLINTNEXTLINE(readability-identifier-naming)
235 this->handlers_.push_back(handler);
236 return *handler;
237 }
238
239 httpd_handle_t get_server() { return this->server_; }
240
241 protected:
242 uint16_t port_{};
243 httpd_handle_t server_{};
244 static esp_err_t request_handler(httpd_req_t *r);
245 static esp_err_t request_post_handler(httpd_req_t *r);
246 esp_err_t request_handler_(AsyncWebServerRequest *request) const;
247 static void safe_close_with_shutdown(httpd_handle_t hd, int sockfd);
248 esp_err_t handle_raw_body_(httpd_req_t *r, const char *content_type);
249#ifdef USE_WEBSERVER_OTA
250 esp_err_t handle_multipart_upload_(httpd_req_t *r, const char *content_type);
251#endif
252 std::vector<AsyncWebHandler *> handlers_;
253 std::function<void(AsyncWebServerRequest *request)> on_not_found_{};
254};
255
257 public:
258 virtual ~AsyncWebHandler() {}
259 // NOLINTNEXTLINE(readability-identifier-naming)
260 virtual bool canHandle(AsyncWebServerRequest *request) const { return false; }
261 // NOLINTNEXTLINE(readability-identifier-naming)
262 virtual void handleRequest(AsyncWebServerRequest *request) {}
263 // NOLINTNEXTLINE(readability-identifier-naming)
264 virtual void handleUpload(AsyncWebServerRequest *request, const std::string &filename, size_t index, uint8_t *data,
265 size_t len, bool final) {}
266 // NOLINTNEXTLINE(readability-identifier-naming)
267 virtual void handleBody(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total) {}
268 // NOLINTNEXTLINE(readability-identifier-naming)
269 virtual bool isRequestHandlerTrivial() const { return true; }
270};
271
272#ifdef USE_WEBSERVER
273class AsyncEventSource;
275
277
278/*
279 This class holds a pointer to the source component that wants to publish a state event, and a pointer to a function
280 that will lazily generate that event. The two pointers allow dedup in the deferred queue if multiple publishes for
281 the same component are backed up, and take up only two pointers of memory. The entry in the deferred queue (a
282 std::vector) is the DeferredEvent instance itself (not a pointer to one elsewhere in heap) so still only two pointers
283 per entry (and no heap fragmentation). Even 100 backed up events (you'd have to have at least 100 sensors publishing
284 because of dedup) would take up only 0.8 kB.
285*/
288
289 protected:
290 void *source_;
292
293 public:
294 DeferredEvent(void *source, message_generator_t *message_generator)
295 : source_(source), message_generator_(message_generator) {}
296 bool operator==(const DeferredEvent &test) const {
297 return (source_ == test.source_ && message_generator_ == test.message_generator_);
298 }
299};
300static_assert(sizeof(DeferredEvent) == sizeof(void *) + sizeof(message_generator_t *),
301 "DeferredEvent should have no padding");
302
304 friend class AsyncEventSource;
305
306 public:
307 bool try_send_nodefer(const char *message, size_t message_len, const char *event = nullptr, uint32_t id = 0,
308 uint32_t reconnect = 0);
309 // detail_all events go out while entities are still being listed; state events wait until listing is done
310 void deferrable_send_state(void *source, bool detail_all, message_generator_t *message_generator);
311 // The old event name argument would otherwise convert to true
312 void deferrable_send_state(void *source, const char *event_type, message_generator_t *message_generator) = delete;
313 void loop();
314
315 protected:
318
319 // Main-loop only: sends initial ping/config/sorting_groups, starts entity iterator.
321
322 void deq_push_back_with_dedup_(void *source, message_generator_t *message_generator);
324 // A new chunk may go out: not re-entered from a log line, session alive, tail empty
325 bool ready_to_send_();
326 // Non-blocking gather write. Returns bytes written, 0 on would-block or a socket that is not
327 // ours, -1 after requesting the close on any other error.
328 ssize_t send_(struct iovec *iov, int iovcnt);
329 // Push what is left of the chunk in tail_ to the socket; owns the stall timer.
330 void drain_tail_();
331 // Grow tail_ to hold len bytes, kept at its high-water mark. False on OOM.
332 bool reserve_tail_(size_t len);
333 // Keep the whole chunk in tail_ and continue from sent; false when the tail cannot be allocated.
334 bool stash_chunk_(const char *prefix, size_t prefix_len, const char *message, size_t message_len, size_t total,
335 size_t sent);
336 // Send a state event; JSON too large for the stack buffer is serialized into tail_ instead
337 bool send_json_(void *source, message_generator_t *generator);
344 // Keep the arena out of the caller's frame so it is gone before the state send.
345 // size_out: BUFFER = JSON length, NO_MEMORY = requested tail capacity, TOO_LARGE = available JSON room;
346 // unused for TAIL.
347 JsonPrepareResult __attribute__((noinline)) prepare_json_(void *source, message_generator_t *generator, char *buffer,
348 size_t *size_out);
349 // Warn once, and close the session once the stall timeout passes with no memory for the tail
350 void tail_alloc_failed_(size_t cap);
351 void request_close_();
352
353 // A log line emitted inside a send re-enters try_send_nodefer on this session; refuse it
359 void process_close_();
360 static void close_session_work(void *arg);
361 void refresh_lru_();
362 static void refresh_lru_work(void *arg);
363 // httpd frees a session before closing its socket, so the fd may already belong to a new client
364 bool owns_session_(int fd) const { return fd != 0 && httpd_sess_get_ctx(this->hd_, fd) == this; }
365
366 // Deletable only after destroy() zeroed fd_ and no queued HTTPD work still references this object.
367 bool safe_to_delete_() const {
368 return this->fd_.load() == 0 && !this->close_work_queued_.load(std::memory_order_acquire) &&
369 !this->lru_work_queued_.load(std::memory_order_acquire);
370 }
371
372 static void destroy(void *p);
374 httpd_handle_t hd_{};
375 std::atomic<int> fd_{};
376 std::vector<DeferredEvent> deferred_queue_;
379 // One chunk the socket did not take whole, allocated on the first stall; the only heap use
380 // on the send path
382 uint32_t send_failure_started_ms_{0}; // Zero means no send stall in progress.
385 uint16_t tail_cap_{0};
386 uint16_t tail_len_{0}; // Zero means nothing pending
387 uint16_t tail_sent_{0};
388 // Set on the main loop before queueing close work, cleared by the HTTPD-task callback when done.
389 std::atomic<bool> close_work_queued_{false};
390 std::atomic<bool> lru_work_queued_{false};
391 // Main-loop only; the HTTPD task never reads or writes these flags.
392 bool close_requested_{false};
394 bool sending_{false};
395 // The longest multi line log message in the tree (a climate dump_config) has 22 lines; a
396 // longer one goes through the tail
397 static constexpr size_t MAX_SEND_LINES = 22;
398 static constexpr size_t MAX_SEND_IOV = 1 + 2 * MAX_SEND_LINES;
399 // Chunk header, retry/id/event lines and the first "data: "
400 static constexpr size_t PREFIX_BUF_SIZE = 128;
401
402 // Stack buffer for a state event's JSON; a larger document is serialized into the tail
403 static constexpr size_t JSON_BUF_SIZE = 1024;
404 // Same ceiling JsonBuilder::serialize() applies (max_heap_size in json_util.cpp); a larger
405 // document is dropped before anything is on the wire
406 static constexpr size_t JSON_MAX_SIZE = 5120;
407 // Most RAM a stalled session keeps: the largest state document plus any accepted framing
409 static constexpr uint32_t SEND_STALL_TIMEOUT_MS = 20000;
410 static constexpr uint32_t CLOSE_RETRY_INTERVAL_MS = 250;
411 static constexpr uint32_t CLOSE_CONFIRM_INTERVAL_MS = 1000;
412 static constexpr uint32_t LRU_REFRESH_INTERVAL_MS = 1000;
413};
414
416
419
420 public:
422 ~AsyncEventSource() override;
423
424 // NOLINTNEXTLINE(readability-identifier-naming)
425 bool canHandle(AsyncWebServerRequest *request) const override {
426 if (request->method() != HTTP_GET)
427 return false;
429 return request->url_to(url_buf) == this->url_;
430 }
431 // NOLINTNEXTLINE(readability-identifier-naming)
432 void handleRequest(AsyncWebServerRequest *request) override;
433 void try_send_nodefer(const char *message, size_t message_len, const char *event = nullptr, uint32_t id = 0,
434 uint32_t reconnect = 0);
435 void deferrable_send_state(void *source, bool detail_all, message_generator_t *message_generator);
436 // The old event name argument would otherwise convert to true
437 void deferrable_send_state(void *source, const char *event_type, message_generator_t *message_generator) = delete;
439 bool loop();
440 bool empty() { return this->count() == 0; }
441
442 size_t count() const { return this->sessions_.size(); }
443
444 protected:
445 // Cold path: move sessions from pending_sessions_ into sessions_ and greet each one.
446 void __attribute__((noinline, cold)) adopt_pending_sessions_main_loop_();
447
448 StringRef url_; // Must outlive this object (string literal)
449 // Main-loop only. Vector: SSE sessions are 1-5 connections, linear search beats set.
450 std::vector<AsyncEventSourceResponse *> sessions_;
451 // Httpd-task intake; guarded by pending_mutex_, gated by has_pending_sessions_.
452 std::vector<AsyncEventSourceResponse *> pending_sessions_;
455 std::atomic<bool> has_pending_sessions_{false};
456};
457#endif // USE_WEBSERVER
458
460 const char *name;
461 const char *value;
462};
463
467#ifdef USE_WEBSERVER
469#endif
470 static_assert(WEB_SERVER_DEFAULT_HEADERS_COUNT <= 8, "AsyncWebServerResponse::replaced_defaults_ holds 8 bits");
471
472 public:
473 // NOLINTNEXTLINE(readability-identifier-naming)
474 void addHeader(const char *name, const char *value) { this->headers_.push_back({name, value}); }
475
476 // NOLINTNEXTLINE(readability-identifier-naming)
477 static DefaultHeaders &Instance();
478
479 protected:
480 // Stack-allocated, no reallocation machinery. Count defined in web_server_base where headers are added.
482
484 void apply_(httpd_req_t *req, uint8_t skip_mask = 0) const;
485};
486
487} // namespace web_server_idf
488} // namespace esphome
489
490using namespace esphome::web_server_idf; // NOLINT(google-global-names-in-headers)
491
492#endif // !defined(USE_ESP32)
Mutex implementation, with API based on the unavailable std::mutex.
Definition helpers.h:2183
Minimal static vector - saves memory by avoiding std::vector overhead.
Definition helpers.h:304
StringRef is a reference to a string owned by something else.
Definition string_ref.h:31
Builder class for creating JSON documents without lambdas.
Definition json_util.h:256
This class allows users to create a web server with their ESP nodes.
Definition web_server.h:204
std::vector< AsyncEventSourceResponse * > pending_sessions_
bool loop()
Returns true if there are sessions remaining (including pending cleanup).
std::vector< AsyncEventSourceResponse * > sessions_
void try_send_nodefer(const char *message, size_t message_len, const char *event=nullptr, uint32_t id=0, uint32_t reconnect=0)
esphome::web_server::WebServer * web_server_
bool canHandle(AsyncWebServerRequest *request) const override
AsyncEventSource(StringRef url, esphome::web_server::WebServer *ws)
void deferrable_send_state(void *source, const char *event_type, message_generator_t *message_generator)=delete
void handleRequest(AsyncWebServerRequest *request) override
void __attribute__((noinline, cold)) adopt_pending_sessions_main_loop_()
void deferrable_send_state(void *source, bool detail_all, message_generator_t *message_generator)
void deferrable_send_state(void *source, bool detail_all, message_generator_t *message_generator)
JsonPrepareResult message_generator_t char * buffer
bool try_send_nodefer(const char *message, size_t message_len, const char *event=nullptr, uint32_t id=0, uint32_t reconnect=0)
void deq_push_back_with_dedup_(void *source, message_generator_t *message_generator)
JsonPrepareResult __attribute__((noinline)) prepare_json_(void *source
ssize_t send_(struct iovec *iov, int iovcnt)
bool stash_chunk_(const char *prefix, size_t prefix_len, const char *message, size_t message_len, size_t total, size_t sent)
AsyncEventSourceResponse(const AsyncWebServerRequest *request, esphome::web_server_idf::AsyncEventSource *server, esphome::web_server::WebServer *ws)
esphome::web_server::WebServer * web_server_
JsonPrepareResult message_generator_t * generator
JsonPrepareResult message_generator_t char size_t * size_out
bool send_json_(void *source, message_generator_t *generator)
esphome::web_server::ListEntitiesIterator entities_iterator_
void deferrable_send_state(void *source, const char *event_type, message_generator_t *message_generator)=delete
AsyncResponseStream(const AsyncWebServerRequest *req)
void printf(const char *fmt,...) __attribute__((format(printf
const char * get_content_data() const override
virtual bool canHandle(AsyncWebServerRequest *request) const
virtual void handleRequest(AsyncWebServerRequest *request)
virtual void handleUpload(AsyncWebServerRequest *request, const std::string &filename, size_t index, uint8_t *data, size_t len, bool final)
virtual void handleBody(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total)
AsyncWebParameter(std::string name, std::string value)
std::function< void(AsyncWebServerRequest *request)> on_not_found_
esp_err_t handle_raw_body_(httpd_req_t *r, const char *content_type)
static esp_err_t request_post_handler(httpd_req_t *r)
std::vector< AsyncWebHandler * > handlers_
AsyncWebHandler & addHandler(AsyncWebHandler *handler)
esp_err_t request_handler_(AsyncWebServerRequest *request) const
esp_err_t handle_multipart_upload_(httpd_req_t *r, const char *content_type)
static void safe_close_with_shutdown(httpd_handle_t hd, int sockfd)
static esp_err_t request_handler(httpd_req_t *r)
void onNotFound(std::function< void(AsyncWebServerRequest *request)> &&fn)
AsyncWebParameter * getParam(const std::string &name)
AsyncWebServerResponse * beginResponse(int code, const char *content_type, const uint8_t *data, const size_t data_size)
size_t get_header_to(const char *name, std::span< char > buf) const
Copy a header value into buf without heap allocation.
AsyncWebParameter * getParam(const char *name)
optional< std::string > get_header(const char *name) const
void ESPHOME_ALWAYS_INLINE send(int code, const char *content_type=nullptr, const char *content=nullptr)
void onDisconnect(std::function< void()> fn)
Called when the request ends, including early returns.
StringRef url_to(std::span< char, URL_BUF_SIZE > buffer) const
Write URL (without query string) to buffer, returns StringRef pointing to buffer.
void send(AsyncWebServerResponse *response)
AsyncWebServerResponse * beginResponse(int code, const char *content_type, const std::string &content)
std::string arg(const std::string &name)
AsyncWebServerResponse * beginResponse(int code, const char *content_type)
void init_response_(AsyncWebServerResponse *rsp, int code, const char *content_type)
static constexpr size_t URL_BUF_SIZE
Buffer size for url_to()
optional< std::string > find_query_value_(const char *name) const
AsyncResponseStream * beginResponseStream(const char *content_type)
bool authenticate(const char *username, const char *password) const
AsyncWebServerRequest(httpd_req_t *req, std::string post_query)
std::vector< AsyncWebParameter * > params_
AsyncWebServerResponseContent(const AsyncWebServerRequest *req, std::string content)
AsyncWebServerResponseEmpty(const AsyncWebServerRequest *req)
virtual const char * get_content_data() const =0
AsyncWebServerResponse(const AsyncWebServerRequest *req)
void addHeader(const char *name, const char *value)
AsyncWebServerResponseProgmem(const AsyncWebServerRequest *req, const uint8_t *data, const size_t size)
void addHeader(const char *name, const char *value)
StaticVector< HttpHeader, WEB_SERVER_DEFAULT_HEADERS_COUNT > headers_
void apply_(httpd_req_t *req, uint8_t skip_mask=0) const
Set every default header on the response except those whose bit is set in skip_mask.
const LogString * message
Definition component.cpp:35
uint32_t buffer
Definition gif.cpp:50
__int64 ssize_t
Definition httplib.h:178
const char * format
void(esphome::web_server::WebServer *, void *, json::JsonBuilder &) message_generator_t
constexpr size_t SSE_SUFFIX_LEN
Definition sse_chunk.h:23
std::unique_ptr< T, RAMDeleter< T > > RAMUniquePtr
unique_ptr over RAMAllocator storage
Definition helpers.h:2385
uint32_t value
Definition hal.cpp:41
const void size_t len
Definition hal.h:68
uint16_t size
Definition helpers.cpp:34
size_t size_t const char * fmt
Definition helpers.h:1334
STL namespace.
static void uint32_t
bool operator==(const DeferredEvent &test) const
DeferredEvent(void *source, message_generator_t *message_generator)
std::string print()