Skip to main content

SimaaiGstErrors.h File

Structured error/warning helpers for SiMa's GStreamer plugins. More...

Included Headers

#include <gst/gst.h> #include <cstdarg> #include <cstdint> #include <cstdio> #include <sstream> #include <string> #include <vector>

Classes Index

structSimaaiGstErrorContext

Bag of diagnostic fields used to build SiMa GStreamer error/warning messages. More...

Functions Index

const char *simaai_gst_safe (const char *s)

Returns s if non-null, or the empty string if null. Convenience for printf-style sites. More...

voidsimaai_gst_append_kv (std::ostringstream &ss, const char *key, const char *value)

Append ‘key='value`(space-prefixed if not the first entry) whenvalue` is non-empty. More...

voidsimaai_gst_append_kv_required (std::ostringstream &ss, const char *key, const char *value)

Append ‘key='value`always, substituting empty string whenvalue` is null. More...

voidsimaai_gst_append_kv_int (std::ostringstream &ss, const char *key, std::int64_t value)

Append key=<value> (unquoted, integer). More...

std::stringsimaai_gst_format_context (const SimaaiGstErrorContext &ctx)

Format an entire SimaaiGstErrorContext as a single key-value line. More...

std::stringsimaai_gst_format_detail (const SimaaiGstErrorContext &ctx, const char *detail)

Format ctx and append a ‘detail=`...'field ifdetail` is non-empty. More...

std::stringsimaai_gst_vformat (const char *fmt, va_list ap)

vsnprintf-into-string helper used by the *detailf formatters; returns empty on null/empty fmt. More...

std::stringsimaai_gst_format_detailf (const SimaaiGstErrorContext &ctx, const char *fmt,...)

printf-style variant of simaai_gst_format_detail. More...

Macro Definitions Index

#defineSIMAAI_GST_FATAL(self, domain, code, summary, detail)   ...

Post a fatal error on the GStreamer bus and log it via GST_ERROR_OBJECT. More...

#defineSIMAAI_GST_WARN(self, summary, detail)   ...

Log a non-fatal warning via GST_WARNING_OBJECT, optionally with a detail suffix. More...

Description

Structured error/warning helpers for SiMa's GStreamer plugins.

Provides a SimaaiGstErrorContext struct gathering the diagnostic fields plugins carry around (plugin/node names, graph and frame ids, stream id, caps, dims, allocator, etc.) plus a small set of inline formatters that turn that context into a stable, key-value-formatted line. The SIMAAI_GST_FATAL and SIMAAI_GST_WARN macros are the standard call sites that route a formatted message into both the GStreamer logging subsystem and an element-level error message.

This header is consumed by SiMa's GStreamer plugin sources directly; framework code sees the resulting bus messages via GstBusWatch.h.

Functions

simaai_gst_append_kv()

void simaai_gst_append_kv (std::ostringstream & ss, const char * key, const char * value)
inline

Append ‘key='value`(space-prefixed if not the first entry) whenvalue` is non-empty.

Definition at line 62 of file SimaaiGstErrors.h.

62inline void simaai_gst_append_kv(std::ostringstream& ss, const char* key, const char* value) {
63 if (!value || !*value)
64 return;
65 if (ss.tellp() > 0)
66 ss << ' ';
67 ss << key << "='" << value << "'";
68}

simaai_gst_append_kv_int()

void simaai_gst_append_kv_int (std::ostringstream & ss, const char * key, std::int64_t value)
inline

Append key=<value> (unquoted, integer).

Definition at line 79 of file SimaaiGstErrors.h.

79inline void simaai_gst_append_kv_int(std::ostringstream& ss, const char* key, std::int64_t value) {
80 if (ss.tellp() > 0)
81 ss << ' ';
82 ss << key << '=' << value;
83}

simaai_gst_append_kv_required()

void simaai_gst_append_kv_required (std::ostringstream & ss, const char * key, const char * value)
inline

Append ‘key='value`always, substituting empty string whenvalue` is null.

Definition at line 71 of file SimaaiGstErrors.h.

71inline void simaai_gst_append_kv_required(std::ostringstream& ss, const char* key,
72 const char* value) {
73 if (ss.tellp() > 0)
74 ss << ' ';
75 ss << key << "='" << simaai_gst_safe(value) << "'";
76}

simaai_gst_format_context()

std::string simaai_gst_format_context (const SimaaiGstErrorContext & ctx)
inline

Format an entire SimaaiGstErrorContext as a single key-value line.

Returns

Space-separated ‘key='value`(orkey=N`) pairs; null/empty values are skipped.

Definition at line 89 of file SimaaiGstErrors.h.

89inline std::string simaai_gst_format_context(const SimaaiGstErrorContext& ctx) {
90 std::ostringstream ss;
91 simaai_gst_append_kv(ss, "plugin", ctx.plugin);
92 simaai_gst_append_kv(ss, "node", ctx.node);
93 simaai_gst_append_kv(ss, "config_path", ctx.config_path);
94 simaai_gst_append_kv(ss, "model_path", ctx.model_path);
95 if (ctx.graph_id >= 0)
96 simaai_gst_append_kv_int(ss, "graph_id", ctx.graph_id);
97 if (ctx.frame_id >= 0)
98 simaai_gst_append_kv_int(ss, "frame_id", ctx.frame_id);
99 simaai_gst_append_kv(ss, "stream_id", ctx.stream_id);
100 simaai_gst_append_kv(ss, "input_caps", ctx.input_caps);
101 simaai_gst_append_kv(ss, "output_caps", ctx.output_caps);
102 simaai_gst_append_kv(ss, "input_dims", ctx.input_dims);
103 simaai_gst_append_kv(ss, "output_dims", ctx.output_dims);
104 simaai_gst_append_kv(ss, "allocator", ctx.allocator);
105 simaai_gst_append_kv(ss, "dispatcher_err", ctx.dispatcher_err);
106 simaai_gst_append_kv(ss, "hint", ctx.hint);
107 simaai_gst_append_kv(ss, "stage_key", ctx.stage_key);
109 ss, "source_used", (ctx.source_used && *ctx.source_used) ? ctx.source_used : "framework");
111 ss, "missing_field", (ctx.missing_field && *ctx.missing_field) ? ctx.missing_field : "none");
112 simaai_gst_append_kv_required(ss, "fallback_chain",
114 : "none");
115 return ss.str();
116}

simaai_gst_format_detail()

std::string simaai_gst_format_detail (const SimaaiGstErrorContext & ctx, const char * detail)
inline

Format ctx and append a ‘detail=`...'field ifdetail` is non-empty.

Parameters
ctx

Diagnostic context to format.

detail

Free-form detail string (may be null/empty).

Definition at line 123 of file SimaaiGstErrors.h.

123inline std::string simaai_gst_format_detail(const SimaaiGstErrorContext& ctx, const char* detail) {
124 std::ostringstream ss;
125 std::string base = simaai_gst_format_context(ctx);
126 if (!base.empty())
127 ss << base;
128 if (detail && *detail) {
129 simaai_gst_append_kv(ss, "detail", detail);
130 }
131 return ss.str();
132}

simaai_gst_format_detailf()

std::string simaai_gst_format_detailf (const SimaaiGstErrorContext & ctx, const char * fmt, ...)
inline

printf-style variant of simaai_gst_format_detail.

Formats fmt and the variadic args into a detail string, then appends it to the formatted context line.

Definition at line 155 of file SimaaiGstErrors.h.

155inline std::string simaai_gst_format_detailf(const SimaaiGstErrorContext& ctx, const char* fmt,
156 ...) {
157 va_list ap;
158 va_start(ap, fmt);
159 std::string detail = simaai_gst_vformat(fmt, ap);
160 va_end(ap);
161 return simaai_gst_format_detail(ctx, detail.c_str());
162}

simaai_gst_safe()

const char * simaai_gst_safe (const char * s)
inline

Returns s if non-null, or the empty string if null. Convenience for printf-style sites.

Definition at line 57 of file SimaaiGstErrors.h.

57inline const char* simaai_gst_safe(const char* s) {
58 return s ? s : "";
59}

simaai_gst_vformat()

std::string simaai_gst_vformat (const char * fmt, va_list ap)
inline

vsnprintf-into-string helper used by the *detailf formatters; returns empty on null/empty fmt.

Definition at line 135 of file SimaaiGstErrors.h.

135inline std::string simaai_gst_vformat(const char* fmt, va_list ap) {
136 if (!fmt || !*fmt)
137 return {};
138 va_list ap_copy;
139 va_copy(ap_copy, ap);
140 const int needed = std::vsnprintf(nullptr, 0, fmt, ap_copy);
141 va_end(ap_copy);
142 if (needed <= 0)
143 return {};
144 std::vector<char> buf(static_cast<size_t>(needed) + 1, '\0');
145 std::vsnprintf(buf.data(), buf.size(), fmt, ap);
146 return std::string(buf.data());
147}

Macro Definitions

SIMAAI_GST_FATAL

#define SIMAAI_GST_FATAL(self, domain, code, summary, detail)   ...

Post a fatal error on the GStreamer bus and log it via GST_ERROR_OBJECT.

Value
do { \ GST_ERROR_OBJECT((self), "%s", (summary)); \ gst_element_message_full(GST_ELEMENT(self), GST_MESSAGE_ERROR, (domain), (code), \ g_strdup(summary), g_strdup((detail) ? (detail) : ""), __FILE__, \ G_STRFUNC, __LINE__); \ } while (0)
Parameters
self

GstElement-like pointer the message is attributed to.

domain

GError domain for the message.

code

GError code within domain.

summary

Short, user-facing summary string.

detail

Detail string (may be empty); attached as the message's debug field.

Definition at line 172 of file SimaaiGstErrors.h.

172#define SIMAAI_GST_FATAL(self, domain, code, summary, detail) \
173 do { \
174 GST_ERROR_OBJECT((self), "%s", (summary)); \
175 gst_element_message_full(GST_ELEMENT(self), GST_MESSAGE_ERROR, (domain), (code), \
176 g_strdup(summary), g_strdup((detail) ? (detail) : ""), __FILE__, \
177 G_STRFUNC, __LINE__); \
178 } while (0)

SIMAAI_GST_WARN

#define SIMAAI_GST_WARN(self, summary, detail)   ...

Log a non-fatal warning via GST_WARNING_OBJECT, optionally with a detail suffix.

Value
do { \ if ((detail) && *(detail)) { \ GST_WARNING_OBJECT((self), "%s | %s", (summary), (detail)); \ } else { \ GST_WARNING_OBJECT((self), "%s", (summary)); \ } \ } while (0)
Parameters
self

GstElement-like pointer the warning is attributed to.

summary

Short summary string.

detail

Detail string; if non-empty it's appended after a | separator.

Definition at line 186 of file SimaaiGstErrors.h.

186#define SIMAAI_GST_WARN(self, summary, detail) \
187 do { \
188 if ((detail) && *(detail)) { \
189 GST_WARNING_OBJECT((self), "%s | %s", (summary), (detail)); \
190 } else { \
191 GST_WARNING_OBJECT((self), "%s", (summary)); \
192 } \
193 } while (0)

File Listing

The file content with the documentation metadata removed is:

1
16#pragma once
17
18#include <gst/gst.h>
19
20#include <cstdarg>
21#include <cstdint>
22#include <cstdio>
23#include <sstream>
24#include <string>
25#include <vector>
26
35 const char* plugin = nullptr;
36 const char* node = nullptr;
37 const char* config_path = nullptr;
38 const char* model_path = nullptr;
39 int graph_id = -1;
40 std::int64_t frame_id = -1;
41 const char* stream_id = nullptr;
42 const char* input_caps = nullptr;
43 const char* output_caps = nullptr;
44 const char* input_dims = nullptr;
45 const char* output_dims = nullptr;
46 const char* allocator = nullptr;
47 const char* dispatcher_err = nullptr;
48 const char* hint = nullptr;
49 const char* stage_key = nullptr;
50 const char* source_used = nullptr;
51 const char* missing_field =
52 nullptr;
53 const char* fallback_chain = nullptr;
54};
55
57inline const char* simaai_gst_safe(const char* s) {
58 return s ? s : "";
59}
60
62inline void simaai_gst_append_kv(std::ostringstream& ss, const char* key, const char* value) {
63 if (!value || !*value)
64 return;
65 if (ss.tellp() > 0)
66 ss << ' ';
67 ss << key << "='" << value << "'";
68}
69
71inline void simaai_gst_append_kv_required(std::ostringstream& ss, const char* key,
72 const char* value) {
73 if (ss.tellp() > 0)
74 ss << ' ';
75 ss << key << "='" << simaai_gst_safe(value) << "'";
76}
77
79inline void simaai_gst_append_kv_int(std::ostringstream& ss, const char* key, std::int64_t value) {
80 if (ss.tellp() > 0)
81 ss << ' ';
82 ss << key << '=' << value;
83}
84
89inline std::string simaai_gst_format_context(const SimaaiGstErrorContext& ctx) {
90 std::ostringstream ss;
91 simaai_gst_append_kv(ss, "plugin", ctx.plugin);
92 simaai_gst_append_kv(ss, "node", ctx.node);
93 simaai_gst_append_kv(ss, "config_path", ctx.config_path);
94 simaai_gst_append_kv(ss, "model_path", ctx.model_path);
95 if (ctx.graph_id >= 0)
96 simaai_gst_append_kv_int(ss, "graph_id", ctx.graph_id);
97 if (ctx.frame_id >= 0)
98 simaai_gst_append_kv_int(ss, "frame_id", ctx.frame_id);
99 simaai_gst_append_kv(ss, "stream_id", ctx.stream_id);
100 simaai_gst_append_kv(ss, "input_caps", ctx.input_caps);
101 simaai_gst_append_kv(ss, "output_caps", ctx.output_caps);
102 simaai_gst_append_kv(ss, "input_dims", ctx.input_dims);
103 simaai_gst_append_kv(ss, "output_dims", ctx.output_dims);
104 simaai_gst_append_kv(ss, "allocator", ctx.allocator);
105 simaai_gst_append_kv(ss, "dispatcher_err", ctx.dispatcher_err);
106 simaai_gst_append_kv(ss, "hint", ctx.hint);
107 simaai_gst_append_kv(ss, "stage_key", ctx.stage_key);
109 ss, "source_used", (ctx.source_used && *ctx.source_used) ? ctx.source_used : "framework");
111 ss, "missing_field", (ctx.missing_field && *ctx.missing_field) ? ctx.missing_field : "none");
112 simaai_gst_append_kv_required(ss, "fallback_chain",
114 : "none");
115 return ss.str();
116}
117
123inline std::string simaai_gst_format_detail(const SimaaiGstErrorContext& ctx, const char* detail) {
124 std::ostringstream ss;
125 std::string base = simaai_gst_format_context(ctx);
126 if (!base.empty())
127 ss << base;
128 if (detail && *detail) {
129 simaai_gst_append_kv(ss, "detail", detail);
130 }
131 return ss.str();
132}
133
135inline std::string simaai_gst_vformat(const char* fmt, va_list ap) {
136 if (!fmt || !*fmt)
137 return {};
138 va_list ap_copy;
139 va_copy(ap_copy, ap);
140 const int needed = std::vsnprintf(nullptr, 0, fmt, ap_copy);
141 va_end(ap_copy);
142 if (needed <= 0)
143 return {};
144 std::vector<char> buf(static_cast<size_t>(needed) + 1, '\0');
145 std::vsnprintf(buf.data(), buf.size(), fmt, ap);
146 return std::string(buf.data());
147}
148
155inline std::string simaai_gst_format_detailf(const SimaaiGstErrorContext& ctx, const char* fmt,
156 ...) {
157 va_list ap;
158 va_start(ap, fmt);
159 std::string detail = simaai_gst_vformat(fmt, ap);
160 va_end(ap);
161 return simaai_gst_format_detail(ctx, detail.c_str());
162}
163
172#define SIMAAI_GST_FATAL(self, domain, code, summary, detail) \
173 do { \
174 GST_ERROR_OBJECT((self), "%s", (summary)); \
175 gst_element_message_full(GST_ELEMENT(self), GST_MESSAGE_ERROR, (domain), (code), \
176 g_strdup(summary), g_strdup((detail) ? (detail) : ""), __FILE__, \
177 G_STRFUNC, __LINE__); \
178 } while (0)
179
186#define SIMAAI_GST_WARN(self, summary, detail) \
187 do { \
188 if ((detail) && *(detail)) { \
189 GST_WARNING_OBJECT((self), "%s | %s", (summary), (detail)); \
190 } else { \
191 GST_WARNING_OBJECT((self), "%s", (summary)); \
192 } \
193 } while (0)

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.