aboutsummaryrefslogtreecommitdiff
path: root/zencore
diff options
context:
space:
mode:
authorPer Larsson <[email protected]>2022-02-21 15:14:11 +0100
committerPer Larsson <[email protected]>2022-02-21 15:14:11 +0100
commitdb1c9605e3afbaf86f4231ba4eb7976d896f286b (patch)
tree54b451da4247c69575ff1a05ed006ecef3905c85 /zencore
parentIf open(O_CREAT) is used then a file mode must be given (diff)
parentRemoved optional offset for GetView. (diff)
downloadzen-db1c9605e3afbaf86f4231ba4eb7976d896f286b.tar.xz
zen-db1c9605e3afbaf86f4231ba4eb7976d896f286b.zip
Initial support for websockets.
Diffstat (limited to 'zencore')
-rw-r--r--zencore/include/zencore/logging.h61
-rw-r--r--zencore/include/zencore/stream.h6
-rw-r--r--zencore/stream.cpp9
3 files changed, 76 insertions, 0 deletions
diff --git a/zencore/include/zencore/logging.h b/zencore/include/zencore/logging.h
index 468e5d6e2..74ab0f81f 100644
--- a/zencore/include/zencore/logging.h
+++ b/zencore/include/zencore/logging.h
@@ -38,6 +38,67 @@ using logging::ConsoleLog;
using zen::ConsoleLog;
using zen::Log;
+struct LogCategory
+{
+ LogCategory(std::string_view InCategory) : Category(InCategory) {}
+
+ spdlog::logger& Logger()
+ {
+ static spdlog::logger& Inst = zen::logging::Get(Category);
+ return Inst;
+ }
+
+ std::string Category;
+};
+
+#define ZEN_DEFINE_LOG_CATEGORY_STATIC(Category, Name) \
+ static struct LogCategory##Category : public LogCategory \
+ { \
+ LogCategory##Category() : LogCategory(Name) {} \
+ } Category;
+
+#define ZEN_LOG_TRACE(Category, fmtstr, ...) \
+ do \
+ { \
+ using namespace std::literals; \
+ Category.Logger().trace(fmtstr##sv, ##__VA_ARGS__); \
+ } while (false)
+
+#define ZEN_LOG_DEBUG(Category, fmtstr, ...) \
+ do \
+ { \
+ using namespace std::literals; \
+ Category.Logger().debug(fmtstr##sv, ##__VA_ARGS__); \
+ } while (false)
+
+#define ZEN_LOG_INFO(Category, fmtstr, ...) \
+ do \
+ { \
+ using namespace std::literals; \
+ Category.Logger().info(fmtstr##sv, ##__VA_ARGS__); \
+ } while (false)
+
+#define ZEN_LOG_WARN(Category, fmtstr, ...) \
+ do \
+ { \
+ using namespace std::literals; \
+ Category.Logger().warn(fmtstr##sv, ##__VA_ARGS__); \
+ } while (false)
+
+#define ZEN_LOG_ERROR(Category, fmtstr, ...) \
+ do \
+ { \
+ using namespace std::literals; \
+ Category.Logger().error(fmtstr##sv, ##__VA_ARGS__); \
+ } while (false)
+
+#define ZEN_LOG_CRITICAL(Category, fmtstr, ...) \
+ do \
+ { \
+ using namespace std::literals; \
+ Category.Logger().critical(fmtstr##sv, ##__VA_ARGS__); \
+ } while (false)
+
// Helper macros for logging
#define ZEN_TRACE(fmtstr, ...) \
diff --git a/zencore/include/zencore/stream.h b/zencore/include/zencore/stream.h
index 9d1a7628c..efff2c541 100644
--- a/zencore/include/zencore/stream.h
+++ b/zencore/include/zencore/stream.h
@@ -27,12 +27,18 @@ public:
m_Offset += ByteCount;
}
+ inline void Write(MemoryView Memory) { Write(Memory.GetData(), Memory.GetSize()); }
+
inline uint64_t CurrentOffset() const { return m_Offset; }
inline const uint8_t* Data() const { return m_Buffer.data(); }
inline const uint8_t* GetData() const { return m_Buffer.data(); }
inline uint64_t Size() const { return m_Buffer.size(); }
inline uint64_t GetSize() const { return m_Buffer.size(); }
+ void Reset();
+
+ inline MemoryView GetView() const { return MemoryView(m_Buffer.data(), m_Offset); }
+ inline MutableMemoryView GetMutableView() { return MutableMemoryView(m_Buffer.data(), m_Offset); }
private:
RwLock m_Lock;
diff --git a/zencore/stream.cpp b/zencore/stream.cpp
index aa9705764..8faf90af2 100644
--- a/zencore/stream.cpp
+++ b/zencore/stream.cpp
@@ -25,6 +25,15 @@ BinaryWriter::Write(const void* data, size_t ByteCount, uint64_t Offset)
memcpy(m_Buffer.data() + Offset, data, ByteCount);
}
+void
+BinaryWriter::Reset()
+{
+ RwLock::ExclusiveLockScope _(m_Lock);
+
+ m_Buffer.clear();
+ m_Offset = 0;
+}
+
//////////////////////////////////////////////////////////////////////////
//
// Testing related code follows...