aboutsummaryrefslogtreecommitdiffstats
path: root/serd
diff options
context:
space:
mode:
Diffstat (limited to 'serd')
-rw-r--r--serd/serd.h26
-rw-r--r--serd/serd.hpp48
2 files changed, 40 insertions, 34 deletions
diff --git a/serd/serd.h b/serd/serd.h
index 3e2f8f45..42946b90 100644
--- a/serd/serd.h
+++ b/serd/serd.h
@@ -783,13 +783,20 @@ serd_node_free(SerdNode* node);
Sink function for log messages
@param handle Handle for user data.
- @param msg Message description.
-*/
-typedef SerdStatus (*SerdMessageFunc)(void* handle, const SerdMessage* msg);
-
-/**
- Sink function for base URI changes
+ @param status Status code
+ @param level Log level
+ @param cursor Origin of message, or NULL
+ @param fmt Message format string (printf style)
+ @param args Arguments corresponding to fmt (printf style)
+*/
+typedef SerdStatus (*SerdMessageFunc)(void* handle,
+ SerdStatus status,
+ SerdLogLevel level,
+ const SerdCursor* cursor,
+ const char* fmt,
+ va_list args);
+/*
Called whenever the base URI of the serialisation changes.
*/
typedef SerdStatus (*SerdBaseFunc)(void* handle, const SerdNode* uri);
@@ -878,7 +885,12 @@ serd_world_set_message_sink(SerdWorld* world,
/// Write a message to the log
SERD_API
SerdStatus
-serd_world_log(const SerdWorld* world, const SerdMessage* msg);
+serd_world_vlogf(const SerdWorld* world,
+ SerdStatus st,
+ SerdLogLevel level,
+ const SerdCursor* cursor,
+ const char* fmt,
+ va_list args);
/// Write a message to the log
SERD_API
diff --git a/serd/serd.hpp b/serd/serd.hpp
index 5084e1ad..112daa23 100644
--- a/serd/serd.hpp
+++ b/serd/serd.hpp
@@ -574,12 +574,6 @@ struct Message
/**
@}
- @name Event Handlers
- @{
-*/
-
-/**
- @}
@name World
@{
*/
@@ -601,11 +595,6 @@ public:
serd_world_set_message_sink(cobj(), s_message_sink, this);
}
- Status log(const SerdMessage* msg)
- {
- return static_cast<Status>(serd_world_log(cobj(), msg));
- }
-
SERD_LOG_FUNC(5, 6)
Status log(const Status status,
const LogLevel level,
@@ -615,44 +604,49 @@ public:
{
va_list args;
va_start(args, fmt);
- const SerdMessage msg = {static_cast<SerdStatus>(status),
- static_cast<SerdLogLevel>(level),
- cursor,
- fmt,
- &args};
- const SerdStatus st = serd_world_log(cobj(), &msg);
+
+ const SerdStatus st = serd_world_vlogf(cobj(),
+ static_cast<SerdStatus>(status),
+ static_cast<SerdLogLevel>(level),
+ cursor,
+ fmt,
+ args);
va_end(args);
return static_cast<Status>(st);
}
private:
- static std::string format(const char* fmt, va_list* args) noexcept
+ static std::string format(const char* fmt, va_list args) noexcept
{
va_list args_copy;
- va_copy(args_copy, *args);
+ va_copy(args_copy, args);
const int n_bytes = vsnprintf(nullptr, 0, fmt, args_copy);
va_end(args_copy);
#if __cplusplus >= 201703L
std::string result(n_bytes, '\0');
- vsnprintf(result.data(), n_bytes + 1, fmt, *args);
+ vsnprintf(result.data(), n_bytes + 1, fmt, args);
#else
std::vector<char> str(n_bytes + 1U, '\0');
- vsnprintf(str.data(), n_bytes + 1U, fmt, *args);
+ vsnprintf(str.data(), n_bytes + 1U, fmt, args);
std::string result(str.data(), size_t(n_bytes));
#endif
return result;
}
- static SerdStatus
- s_message_sink(void* handle, const SerdMessage* msg) noexcept
+ static SerdStatus s_message_sink(void* handle,
+ SerdStatus status,
+ SerdLogLevel level,
+ const SerdCursor* cursor,
+ const char* fmt,
+ va_list args) noexcept
{
const auto* const self = static_cast<const World*>(handle);
try {
- Message message{static_cast<Status>(msg->status),
- static_cast<LogLevel>(msg->level),
- CursorView{msg->cursor},
- format(msg->fmt, msg->args)};
+ Message message{static_cast<Status>(status),
+ static_cast<LogLevel>(level),
+ CursorView{cursor},
+ format(fmt, args)};
return static_cast<SerdStatus>(self->_msg_sink(message));
} catch (...) {
return SERD_ERR_INTERNAL;