style: unify identifier naming per updated conventions
Automated with clang-tidy readability-identifier-naming (config added to .clang-tidy) plus scripted passes, per the updated rules now documented in CONTRIBUTING.md: - types (class/struct/enum/alias/template params): PascalCase - functions, variables, members: snake_case (incl. rational -> Rational) - private/protected members: trailing underscore; static member variables likewise (instance_, available_themes_) - constants and enum values: snake_case (kLinear -> k_linear, F32P -> f32p); ALL_CAPS reserved for macros - macros: OAK_ prefix (OLIVE_ADD_TEST/OLIVE_ASSERT/OLIVE_CONFIG -> OAK_ADD_TEST/OAK_ASSERT/OAK_CONFIG, GL_PREAMBLE -> OAK_GL_PREAMBLE, include guards -> OAK_*) - file names: all lowercase (Current/Plugin/OliveHost/OliveClip/ OlivePluginInstance -> current/plugin/olivehost/oliveclip/ oliveplugininstance) - getters share the member name sans underscore, setters set_foo() - Qt and third-party (OpenFX) virtual overrides and framework callbacks keep their original names (exempt in .clang-tidy) Manual follow-ups required where automation could not reach: - string-based QMetaObject/SIGNAL/SLOT references updated to renamed methods (AddTask, CreatedFile, DeleteSpecificFile, moveSelectionUp, ...) - macro bodies referencing renamed methods (OLIVE_CONFIG, NODE_DEFAULT_DESTRUCTOR, MANAGEDDISPLAYWIDGET_*) - self-shadowing locals renamed where signals/methods became same-named (size_changed, worker_count, selected_items, import param, filters) - third_party OFX member/namespace usages restored (OFX::Host::*, _created, _clipPrefsDirty, createInstance, clearPersistentMessage) - STL protocol aliases restored (const_iterator) with .clang-tidy ignore rules; qHash overloads restored Full build and test suite pass: ctest 4/4, ~1960 gtest cases green.
This commit is contained in:
@@ -31,54 +31,54 @@ namespace
|
||||
{
|
||||
|
||||
// Round `value` up to the next multiple of `align` (align must be a power of two).
|
||||
size_t AlignUp(size_t value, size_t align)
|
||||
size_t align_up(size_t value, size_t align)
|
||||
{
|
||||
return (value + (align - 1)) & ~(align - 1);
|
||||
}
|
||||
|
||||
constexpr size_t kAlign = 64; // Cache-line alignment for each sub-region.
|
||||
constexpr size_t k_align = 64; // Cache-line alignment for each sub-region.
|
||||
|
||||
} // namespace
|
||||
|
||||
size_t FrameSlotPool::BytesNeeded(uint32_t slot_count, size_t slot_data_bytes)
|
||||
size_t FrameSlotPool::bytes_needed(uint32_t slot_count, size_t slot_data_bytes)
|
||||
{
|
||||
const uint32_t ring_cap = RingCapacity(slot_count);
|
||||
size_t total = AlignUp(sizeof(Header), kAlign);
|
||||
const uint32_t ring_cap = ring_capacity(slot_count);
|
||||
size_t total = align_up(sizeof(Header), k_align);
|
||||
total +=
|
||||
AlignUp(SpscRingBuffer::BytesNeeded(ring_cap), kAlign); // free ring
|
||||
align_up(SpscRingBuffer::bytes_needed(ring_cap), k_align); // free ring
|
||||
total +=
|
||||
AlignUp(SpscRingBuffer::BytesNeeded(ring_cap), kAlign); // ready ring
|
||||
align_up(SpscRingBuffer::bytes_needed(ring_cap), k_align); // ready ring
|
||||
total +=
|
||||
AlignUp(sizeof(FrameSlotMeta) * slot_count, kAlign); // metadata array
|
||||
total += AlignUp(slot_data_bytes, kAlign) * slot_count; // pixel data blocks
|
||||
align_up(sizeof(FrameSlotMeta) * slot_count, k_align); // metadata array
|
||||
total += align_up(slot_data_bytes, k_align) * slot_count; // pixel data blocks
|
||||
return total;
|
||||
}
|
||||
|
||||
FrameSlotPool FrameSlotPool::Create(void *mem, uint32_t slot_count,
|
||||
FrameSlotPool FrameSlotPool::create(void *mem, uint32_t slot_count,
|
||||
size_t slot_data_bytes)
|
||||
{
|
||||
FrameSlotPool pool;
|
||||
pool.base_ = reinterpret_cast<uint8_t *>(mem);
|
||||
|
||||
const uint32_t ring_cap = RingCapacity(slot_count);
|
||||
const uint32_t ring_cap = ring_capacity(slot_count);
|
||||
|
||||
size_t offset = 0;
|
||||
const size_t header_off = offset;
|
||||
offset += AlignUp(sizeof(Header), kAlign);
|
||||
offset += align_up(sizeof(Header), k_align);
|
||||
|
||||
const size_t free_off = offset;
|
||||
offset += AlignUp(SpscRingBuffer::BytesNeeded(ring_cap), kAlign);
|
||||
offset += align_up(SpscRingBuffer::bytes_needed(ring_cap), k_align);
|
||||
|
||||
const size_t ready_off = offset;
|
||||
offset += AlignUp(SpscRingBuffer::BytesNeeded(ring_cap), kAlign);
|
||||
offset += align_up(SpscRingBuffer::bytes_needed(ring_cap), k_align);
|
||||
|
||||
const size_t meta_off = offset;
|
||||
offset += AlignUp(sizeof(FrameSlotMeta) * slot_count, kAlign);
|
||||
offset += align_up(sizeof(FrameSlotMeta) * slot_count, k_align);
|
||||
|
||||
const size_t data_off = offset;
|
||||
|
||||
pool.header_ = reinterpret_cast<Header *>(pool.base_ + header_off);
|
||||
pool.header_->magic = kMagic;
|
||||
pool.header_->magic = k_magic;
|
||||
pool.header_->slot_count = slot_count;
|
||||
pool.header_->slot_data_bytes = slot_data_bytes;
|
||||
pool.header_->free_ring_offset = free_off;
|
||||
@@ -86,8 +86,8 @@ FrameSlotPool FrameSlotPool::Create(void *mem, uint32_t slot_count,
|
||||
pool.header_->meta_offset = meta_off;
|
||||
pool.header_->data_offset = data_off;
|
||||
|
||||
pool.free_ring_ = SpscRingBuffer::Create(pool.base_ + free_off, ring_cap);
|
||||
pool.ready_ring_ = SpscRingBuffer::Create(pool.base_ + ready_off, ring_cap);
|
||||
pool.free_ring_ = SpscRingBuffer::create(pool.base_ + free_off, ring_cap);
|
||||
pool.ready_ring_ = SpscRingBuffer::create(pool.base_ + ready_off, ring_cap);
|
||||
pool.meta_ = reinterpret_cast<FrameSlotMeta *>(pool.base_ + meta_off);
|
||||
pool.data_ = pool.base_ + data_off;
|
||||
|
||||
@@ -95,19 +95,19 @@ FrameSlotPool FrameSlotPool::Create(void *mem, uint32_t slot_count,
|
||||
|
||||
// Seed the free ring with every slot index so the filler can Acquire() immediately.
|
||||
for (uint32_t i = 0; i < slot_count; i++) {
|
||||
pool.free_ring_->Push(i);
|
||||
pool.free_ring_->push(i);
|
||||
}
|
||||
|
||||
return pool;
|
||||
}
|
||||
|
||||
FrameSlotPool FrameSlotPool::Attach(void *mem)
|
||||
FrameSlotPool FrameSlotPool::attach(void *mem)
|
||||
{
|
||||
FrameSlotPool pool;
|
||||
pool.base_ = reinterpret_cast<uint8_t *>(mem);
|
||||
pool.header_ = reinterpret_cast<Header *>(pool.base_);
|
||||
|
||||
if (pool.header_->magic != kMagic) {
|
||||
if (pool.header_->magic != k_magic) {
|
||||
// Caller will see IsValid() == false via a null header reset.
|
||||
pool.header_ = nullptr;
|
||||
pool.base_ = nullptr;
|
||||
@@ -115,9 +115,9 @@ FrameSlotPool FrameSlotPool::Attach(void *mem)
|
||||
}
|
||||
|
||||
pool.free_ring_ =
|
||||
SpscRingBuffer::Attach(pool.base_ + pool.header_->free_ring_offset);
|
||||
SpscRingBuffer::attach(pool.base_ + pool.header_->free_ring_offset);
|
||||
pool.ready_ring_ =
|
||||
SpscRingBuffer::Attach(pool.base_ + pool.header_->ready_ring_offset);
|
||||
SpscRingBuffer::attach(pool.base_ + pool.header_->ready_ring_offset);
|
||||
pool.meta_ = reinterpret_cast<FrameSlotMeta *>(pool.base_ +
|
||||
pool.header_->meta_offset);
|
||||
pool.data_ = pool.base_ + pool.header_->data_offset;
|
||||
@@ -135,44 +135,44 @@ size_t FrameSlotPool::slot_data_bytes() const
|
||||
return header_ ? size_t(header_->slot_data_bytes) : 0;
|
||||
}
|
||||
|
||||
bool FrameSlotPool::Acquire(uint32_t *index)
|
||||
bool FrameSlotPool::acquire(uint32_t *index)
|
||||
{
|
||||
return free_ring_->Pop(index);
|
||||
return free_ring_->pop(index);
|
||||
}
|
||||
|
||||
void *FrameSlotPool::SlotData(uint32_t index)
|
||||
void *FrameSlotPool::slot_data(uint32_t index)
|
||||
{
|
||||
return data_ + size_t(index) * AlignUp(slot_data_bytes(), kAlign);
|
||||
return data_ + size_t(index) * align_up(slot_data_bytes(), k_align);
|
||||
}
|
||||
|
||||
const void *FrameSlotPool::SlotData(uint32_t index) const
|
||||
const void *FrameSlotPool::slot_data(uint32_t index) const
|
||||
{
|
||||
return data_ + size_t(index) * AlignUp(slot_data_bytes(), kAlign);
|
||||
return data_ + size_t(index) * align_up(slot_data_bytes(), k_align);
|
||||
}
|
||||
|
||||
FrameSlotMeta *FrameSlotPool::Meta(uint32_t index)
|
||||
FrameSlotMeta *FrameSlotPool::meta(uint32_t index)
|
||||
{
|
||||
return &meta_[index];
|
||||
}
|
||||
|
||||
const FrameSlotMeta *FrameSlotPool::Meta(uint32_t index) const
|
||||
const FrameSlotMeta *FrameSlotPool::meta(uint32_t index) const
|
||||
{
|
||||
return &meta_[index];
|
||||
}
|
||||
|
||||
bool FrameSlotPool::Publish(uint32_t index)
|
||||
bool FrameSlotPool::publish(uint32_t index)
|
||||
{
|
||||
return ready_ring_->Push(index);
|
||||
return ready_ring_->push(index);
|
||||
}
|
||||
|
||||
bool FrameSlotPool::Consume(uint32_t *index)
|
||||
bool FrameSlotPool::consume(uint32_t *index)
|
||||
{
|
||||
return ready_ring_->Pop(index);
|
||||
return ready_ring_->pop(index);
|
||||
}
|
||||
|
||||
bool FrameSlotPool::Release(uint32_t index)
|
||||
bool FrameSlotPool::release(uint32_t index)
|
||||
{
|
||||
return free_ring_->Push(index);
|
||||
return free_ring_->push(index);
|
||||
}
|
||||
|
||||
} // namespace ipc
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
***/
|
||||
|
||||
#ifndef IPC_FRAMESLOTPOOL_H
|
||||
#define IPC_FRAMESLOTPOOL_H
|
||||
#ifndef OAK_IPC_FRAMESLOTPOOL_H
|
||||
#define OAK_IPC_FRAMESLOTPOOL_H
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
@@ -36,7 +36,7 @@ namespace ipc
|
||||
*
|
||||
* Trivially-copyable POD that lives in shared memory alongside the pixel data. Carries everything
|
||||
* the consumer needs to reconstruct an olive::Frame without any out-of-band information. We store
|
||||
* the rational timestamp as an explicit numerator/denominator pair to stay POD (olive::rational is
|
||||
* the Rational timestamp as an explicit numerator/denominator pair to stay POD (olive::Rational is
|
||||
* not guaranteed shared-memory-safe).
|
||||
*/
|
||||
struct FrameSlotMeta {
|
||||
@@ -82,7 +82,7 @@ public:
|
||||
/**
|
||||
* @brief Total bytes a region must provide to back a pool of `slot_count` x `slot_data_bytes`.
|
||||
*/
|
||||
static size_t BytesNeeded(uint32_t slot_count, size_t slot_data_bytes);
|
||||
static size_t bytes_needed(uint32_t slot_count, size_t slot_data_bytes);
|
||||
|
||||
/**
|
||||
* @brief Lay out and initialize a brand-new pool over `mem` (owner side, once).
|
||||
@@ -90,7 +90,7 @@ public:
|
||||
* Initializes both rings, seeds the free ring with every slot index, and zeroes metadata.
|
||||
* `mem` must provide at least BytesNeeded(slot_count, slot_data_bytes) bytes.
|
||||
*/
|
||||
static FrameSlotPool Create(void *mem, uint32_t slot_count,
|
||||
static FrameSlotPool create(void *mem, uint32_t slot_count,
|
||||
size_t slot_data_bytes);
|
||||
|
||||
/**
|
||||
@@ -98,9 +98,9 @@ public:
|
||||
*
|
||||
* Reads slot_count/slot_data_bytes from the in-memory header written by Create().
|
||||
*/
|
||||
static FrameSlotPool Attach(void *mem);
|
||||
static FrameSlotPool attach(void *mem);
|
||||
|
||||
bool IsValid() const
|
||||
bool is_valid() const
|
||||
{
|
||||
return header_ != nullptr;
|
||||
}
|
||||
@@ -113,37 +113,37 @@ public:
|
||||
/**
|
||||
* @brief Take ownership of a free slot. Returns false (and leaves *index untouched) if none free.
|
||||
*/
|
||||
bool Acquire(uint32_t *index);
|
||||
bool acquire(uint32_t *index);
|
||||
|
||||
/**
|
||||
* @brief Pointer to a slot's pixel data block (slot_data_bytes available).
|
||||
*/
|
||||
void *SlotData(uint32_t index);
|
||||
void *slot_data(uint32_t index);
|
||||
|
||||
/**
|
||||
* @brief Mutable metadata for a slot. Filler writes this before Publish().
|
||||
*/
|
||||
FrameSlotMeta *Meta(uint32_t index);
|
||||
FrameSlotMeta *meta(uint32_t index);
|
||||
|
||||
/**
|
||||
* @brief Publish a filled slot to the drainer. Must follow a successful Acquire() of `index`.
|
||||
*/
|
||||
bool Publish(uint32_t index);
|
||||
bool publish(uint32_t index);
|
||||
|
||||
// ---- Drainer side ----
|
||||
|
||||
/**
|
||||
* @brief Take the next published slot. Returns false if nothing is ready.
|
||||
*/
|
||||
bool Consume(uint32_t *index);
|
||||
bool consume(uint32_t *index);
|
||||
|
||||
/**
|
||||
* @brief Return a consumed slot to the free pool for reuse. Must follow Consume() of `index`.
|
||||
*/
|
||||
bool Release(uint32_t index);
|
||||
bool release(uint32_t index);
|
||||
|
||||
const FrameSlotMeta *Meta(uint32_t index) const;
|
||||
const void *SlotData(uint32_t index) const;
|
||||
const FrameSlotMeta *meta(uint32_t index) const;
|
||||
const void *slot_data(uint32_t index) const;
|
||||
|
||||
public:
|
||||
FrameSlotPool() = default;
|
||||
@@ -160,11 +160,11 @@ private:
|
||||
uint64_t data_offset;
|
||||
};
|
||||
|
||||
static constexpr uint32_t kMagic = 0x4F4B5350; // 'OKSP'
|
||||
static constexpr uint32_t k_magic = 0x4F4B5350; // 'OKSP'
|
||||
|
||||
// Ring capacity must exceed slot_count by one because a ring can hold at most capacity-1 entries
|
||||
// and we need to be able to enqueue every slot at once.
|
||||
static uint32_t RingCapacity(uint32_t slot_count)
|
||||
static uint32_t ring_capacity(uint32_t slot_count)
|
||||
{
|
||||
return slot_count + 1;
|
||||
}
|
||||
@@ -180,4 +180,4 @@ private:
|
||||
} // namespace ipc
|
||||
} // namespace olive
|
||||
|
||||
#endif // IPC_FRAMESLOTPOOL_H
|
||||
#endif // OAK_IPC_FRAMESLOTPOOL_H
|
||||
@@ -29,14 +29,14 @@ namespace olive
|
||||
namespace ipc
|
||||
{
|
||||
|
||||
bool WriteMessage(QIODevice *device, const QJsonObject &obj)
|
||||
bool write_message(QIODevice *device, const QJsonObject &obj)
|
||||
{
|
||||
QByteArray line = QJsonDocument(obj).toJson(QJsonDocument::Compact);
|
||||
line.append('\n');
|
||||
return device->write(line) == line.size();
|
||||
}
|
||||
|
||||
bool ReadMessage(QByteArray *buffer, QJsonObject *out, bool *ok)
|
||||
bool read_message(QByteArray *buffer, QJsonObject *out, bool *ok)
|
||||
{
|
||||
while (true) {
|
||||
const int newline = buffer->indexOf('\n');
|
||||
@@ -72,10 +72,10 @@ bool ReadMessage(QByteArray *buffer, QJsonObject *out, bool *ok)
|
||||
|
||||
// ---- HandshakeMsg ---------------------------------------------------------------------------
|
||||
|
||||
QJsonObject HandshakeMsg::ToJson() const
|
||||
QJsonObject HandshakeMsg::to_json() const
|
||||
{
|
||||
QJsonObject o;
|
||||
o["type"] = msgtype::kHandshake;
|
||||
o["type"] = msgtype::k_handshake;
|
||||
o["protocol_version"] = protocol_version;
|
||||
o["shm_key"] = shm_key;
|
||||
o["input_shm_key"] = input_shm_key;
|
||||
@@ -86,9 +86,9 @@ QJsonObject HandshakeMsg::ToJson() const
|
||||
return o;
|
||||
}
|
||||
|
||||
bool HandshakeMsg::FromJson(const QJsonObject &o, HandshakeMsg *out)
|
||||
bool HandshakeMsg::from_json(const QJsonObject &o, HandshakeMsg *out)
|
||||
{
|
||||
if (o["type"].toString() != QLatin1String(msgtype::kHandshake)) {
|
||||
if (o["type"].toString() != QLatin1String(msgtype::k_handshake)) {
|
||||
return false;
|
||||
}
|
||||
out->protocol_version = o["protocol_version"].toInt();
|
||||
@@ -103,10 +103,10 @@ bool HandshakeMsg::FromJson(const QJsonObject &o, HandshakeMsg *out)
|
||||
|
||||
// ---- RenderFrameMsg -------------------------------------------------------------------------
|
||||
|
||||
QJsonObject RenderFrameMsg::ToJson() const
|
||||
QJsonObject RenderFrameMsg::to_json() const
|
||||
{
|
||||
QJsonObject o;
|
||||
o["type"] = msgtype::kRenderFrame;
|
||||
o["type"] = msgtype::k_render_frame;
|
||||
o["ticket"] = double(ticket_id);
|
||||
o["node"] = node_uuid;
|
||||
o["time_num"] = double(time_num);
|
||||
@@ -133,9 +133,9 @@ QJsonObject RenderFrameMsg::ToJson() const
|
||||
return o;
|
||||
}
|
||||
|
||||
bool RenderFrameMsg::FromJson(const QJsonObject &o, RenderFrameMsg *out)
|
||||
bool RenderFrameMsg::from_json(const QJsonObject &o, RenderFrameMsg *out)
|
||||
{
|
||||
if (o["type"].toString() != QLatin1String(msgtype::kRenderFrame)) {
|
||||
if (o["type"].toString() != QLatin1String(msgtype::k_render_frame)) {
|
||||
return false;
|
||||
}
|
||||
out->ticket_id = qint64(o["ticket"].toDouble());
|
||||
@@ -169,18 +169,18 @@ bool RenderFrameMsg::FromJson(const QJsonObject &o, RenderFrameMsg *out)
|
||||
|
||||
// ---- FrameReadyMsg --------------------------------------------------------------------------
|
||||
|
||||
QJsonObject FrameReadyMsg::ToJson() const
|
||||
QJsonObject FrameReadyMsg::to_json() const
|
||||
{
|
||||
QJsonObject o;
|
||||
o["type"] = msgtype::kFrameReady;
|
||||
o["type"] = msgtype::k_frame_ready;
|
||||
o["ticket"] = double(ticket_id);
|
||||
o["slot"] = output_slot;
|
||||
return o;
|
||||
}
|
||||
|
||||
bool FrameReadyMsg::FromJson(const QJsonObject &o, FrameReadyMsg *out)
|
||||
bool FrameReadyMsg::from_json(const QJsonObject &o, FrameReadyMsg *out)
|
||||
{
|
||||
if (o["type"].toString() != QLatin1String(msgtype::kFrameReady)) {
|
||||
if (o["type"].toString() != QLatin1String(msgtype::k_frame_ready)) {
|
||||
return false;
|
||||
}
|
||||
out->ticket_id = qint64(o["ticket"].toDouble());
|
||||
@@ -190,17 +190,17 @@ bool FrameReadyMsg::FromJson(const QJsonObject &o, FrameReadyMsg *out)
|
||||
|
||||
// ---- CancelMsg ------------------------------------------------------------------------------
|
||||
|
||||
QJsonObject CancelMsg::ToJson() const
|
||||
QJsonObject CancelMsg::to_json() const
|
||||
{
|
||||
QJsonObject o;
|
||||
o["type"] = msgtype::kCancel;
|
||||
o["type"] = msgtype::k_cancel;
|
||||
o["ticket"] = double(ticket_id);
|
||||
return o;
|
||||
}
|
||||
|
||||
bool CancelMsg::FromJson(const QJsonObject &o, CancelMsg *out)
|
||||
bool CancelMsg::from_json(const QJsonObject &o, CancelMsg *out)
|
||||
{
|
||||
if (o["type"].toString() != QLatin1String(msgtype::kCancel)) {
|
||||
if (o["type"].toString() != QLatin1String(msgtype::k_cancel)) {
|
||||
return false;
|
||||
}
|
||||
out->ticket_id = qint64(o["ticket"].toDouble());
|
||||
@@ -209,17 +209,17 @@ bool CancelMsg::FromJson(const QJsonObject &o, CancelMsg *out)
|
||||
|
||||
// ---- LoadGraphMsg ---------------------------------------------------------------------------
|
||||
|
||||
QJsonObject LoadGraphMsg::ToJson() const
|
||||
QJsonObject LoadGraphMsg::to_json() const
|
||||
{
|
||||
QJsonObject o;
|
||||
o["type"] = msgtype::kLoadGraph;
|
||||
o["type"] = msgtype::k_load_graph;
|
||||
o["path"] = path;
|
||||
return o;
|
||||
}
|
||||
|
||||
bool LoadGraphMsg::FromJson(const QJsonObject &o, LoadGraphMsg *out)
|
||||
bool LoadGraphMsg::from_json(const QJsonObject &o, LoadGraphMsg *out)
|
||||
{
|
||||
if (o["type"].toString() != QLatin1String(msgtype::kLoadGraph)) {
|
||||
if (o["type"].toString() != QLatin1String(msgtype::k_load_graph)) {
|
||||
return false;
|
||||
}
|
||||
out->path = o["path"].toString();
|
||||
|
||||
+23
-23
@@ -18,8 +18,8 @@
|
||||
|
||||
***/
|
||||
|
||||
#ifndef IPC_IPCMESSAGE_H
|
||||
#define IPC_IPCMESSAGE_H
|
||||
#ifndef OAK_IPC_IPCMESSAGE_H
|
||||
#define OAK_IPC_IPCMESSAGE_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <QByteArray>
|
||||
@@ -55,14 +55,14 @@ namespace ipc
|
||||
*/
|
||||
namespace msgtype
|
||||
{
|
||||
constexpr const char *kHandshake = "handshake";
|
||||
constexpr const char *kLoadGraph = "load_graph";
|
||||
constexpr const char *kRenderFrame = "render_frame";
|
||||
constexpr const char *kFrameReady = "frame_ready";
|
||||
constexpr const char *kCancel = "cancel";
|
||||
constexpr const char *kGraphUpdate = "graph_update";
|
||||
constexpr const char *kShutdown = "shutdown";
|
||||
constexpr const char *kError = "error";
|
||||
constexpr const char *k_handshake = "handshake";
|
||||
constexpr const char *k_load_graph = "load_graph";
|
||||
constexpr const char *k_render_frame = "render_frame";
|
||||
constexpr const char *k_frame_ready = "frame_ready";
|
||||
constexpr const char *k_cancel = "cancel";
|
||||
constexpr const char *k_graph_update = "graph_update";
|
||||
constexpr const char *k_shutdown = "shutdown";
|
||||
constexpr const char *k_error = "error";
|
||||
} // namespace msgtype
|
||||
|
||||
/**
|
||||
@@ -71,7 +71,7 @@ constexpr const char *kError = "error";
|
||||
* Serializes `obj` to compact JSON, appends '\n', and writes the whole line in one call. Returns
|
||||
* true only if the full line was written.
|
||||
*/
|
||||
bool WriteMessage(QIODevice *device, const QJsonObject &obj);
|
||||
bool write_message(QIODevice *device, const QJsonObject &obj);
|
||||
|
||||
/**
|
||||
* @brief Pull one complete NDJSON line out of `buffer` and parse it.
|
||||
@@ -82,7 +82,7 @@ bool WriteMessage(QIODevice *device, const QJsonObject &obj);
|
||||
* and continue rather than wedge. Supports the typical "append bytes as they arrive, then drain
|
||||
* complete lines" reader loop on a pipe.
|
||||
*/
|
||||
bool ReadMessage(QByteArray *buffer, QJsonObject *out, bool *ok = nullptr);
|
||||
bool read_message(QByteArray *buffer, QJsonObject *out, bool *ok = nullptr);
|
||||
|
||||
// ---- Typed message builders / parsers -------------------------------------------------------
|
||||
//
|
||||
@@ -100,8 +100,8 @@ struct HandshakeMsg {
|
||||
qint64 slot_data_bytes = 0; ///< Per-output-slot pixel block size.
|
||||
qint64 input_slot_data_bytes = 0; ///< Per-input-slot pixel block size.
|
||||
|
||||
QJsonObject ToJson() const;
|
||||
static bool FromJson(const QJsonObject &o, HandshakeMsg *out);
|
||||
QJsonObject to_json() const;
|
||||
static bool from_json(const QJsonObject &o, HandshakeMsg *out);
|
||||
};
|
||||
|
||||
struct RenderFrameMsg {
|
||||
@@ -129,33 +129,33 @@ struct RenderFrameMsg {
|
||||
QString color_view;
|
||||
QString color_look;
|
||||
|
||||
QJsonObject ToJson() const;
|
||||
static bool FromJson(const QJsonObject &o, RenderFrameMsg *out);
|
||||
QJsonObject to_json() const;
|
||||
static bool from_json(const QJsonObject &o, RenderFrameMsg *out);
|
||||
};
|
||||
|
||||
struct FrameReadyMsg {
|
||||
qint64 ticket_id = 0;
|
||||
int output_slot = 0; ///< Index into the worker->main output FrameSlotPool.
|
||||
|
||||
QJsonObject ToJson() const;
|
||||
static bool FromJson(const QJsonObject &o, FrameReadyMsg *out);
|
||||
QJsonObject to_json() const;
|
||||
static bool from_json(const QJsonObject &o, FrameReadyMsg *out);
|
||||
};
|
||||
|
||||
struct CancelMsg {
|
||||
qint64 ticket_id = 0;
|
||||
|
||||
QJsonObject ToJson() const;
|
||||
static bool FromJson(const QJsonObject &o, CancelMsg *out);
|
||||
QJsonObject to_json() const;
|
||||
static bool from_json(const QJsonObject &o, CancelMsg *out);
|
||||
};
|
||||
|
||||
struct LoadGraphMsg {
|
||||
QString path; ///< Temporary file holding the serialized node graph.
|
||||
|
||||
QJsonObject ToJson() const;
|
||||
static bool FromJson(const QJsonObject &o, LoadGraphMsg *out);
|
||||
QJsonObject to_json() const;
|
||||
static bool from_json(const QJsonObject &o, LoadGraphMsg *out);
|
||||
};
|
||||
|
||||
} // namespace ipc
|
||||
} // namespace olive
|
||||
|
||||
#endif // IPC_IPCMESSAGE_H
|
||||
#endif // OAK_IPC_IPCMESSAGE_H
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace ipc
|
||||
SharedMemoryRegion::SharedMemoryRegion()
|
||||
: size_(0)
|
||||
, data_(nullptr)
|
||||
, mode_(kAttach)
|
||||
, mode_(k_attach)
|
||||
#if defined(Q_OS_WIN)
|
||||
, handle_(nullptr)
|
||||
#else
|
||||
@@ -52,10 +52,10 @@ SharedMemoryRegion::SharedMemoryRegion()
|
||||
|
||||
SharedMemoryRegion::~SharedMemoryRegion()
|
||||
{
|
||||
Close();
|
||||
close();
|
||||
}
|
||||
|
||||
QString SharedMemoryRegion::MakeKey(qint64 owner_pid, int worker_index)
|
||||
QString SharedMemoryRegion::make_key(qint64 owner_pid, int worker_index)
|
||||
{
|
||||
return QStringLiteral("olive-rw-%1-%2").arg(owner_pid).arg(worker_index);
|
||||
}
|
||||
@@ -131,9 +131,9 @@ void SharedMemoryRegion::Close()
|
||||
|
||||
#else // POSIX
|
||||
|
||||
bool SharedMemoryRegion::Open(const QString &key, size_t size, Mode mode)
|
||||
bool SharedMemoryRegion::open(const QString &key, size_t size, Mode mode)
|
||||
{
|
||||
Close();
|
||||
close();
|
||||
|
||||
key_ = key;
|
||||
size_ = size;
|
||||
@@ -144,7 +144,7 @@ bool SharedMemoryRegion::Open(const QString &key, size_t size, Mode mode)
|
||||
const QByteArray name_bytes = shm_name_.toUtf8();
|
||||
|
||||
int oflag = O_RDWR;
|
||||
if (mode == kCreate) {
|
||||
if (mode == k_create) {
|
||||
oflag |= O_CREAT | O_EXCL;
|
||||
// Clear any stale segment left by a crashed previous run with the same name.
|
||||
shm_unlink(name_bytes.constData());
|
||||
@@ -157,7 +157,7 @@ bool SharedMemoryRegion::Open(const QString &key, size_t size, Mode mode)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mode == kCreate) {
|
||||
if (mode == k_create) {
|
||||
if (ftruncate(fd_, off_t(size)) != 0) {
|
||||
error_ = QStringLiteral("ftruncate failed: %1")
|
||||
.arg(QString::fromUtf8(strerror(errno)));
|
||||
@@ -195,19 +195,19 @@ bool SharedMemoryRegion::Open(const QString &key, size_t size, Mode mode)
|
||||
data_ = nullptr;
|
||||
::close(fd_);
|
||||
fd_ = -1;
|
||||
if (mode == kCreate) {
|
||||
if (mode == k_create) {
|
||||
shm_unlink(name_bytes.constData());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mode == kCreate) {
|
||||
if (mode == k_create) {
|
||||
memset(data_, 0, size);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void SharedMemoryRegion::Close()
|
||||
void SharedMemoryRegion::close()
|
||||
{
|
||||
if (data_) {
|
||||
munmap(data_, size_);
|
||||
@@ -217,7 +217,7 @@ void SharedMemoryRegion::Close()
|
||||
::close(fd_);
|
||||
fd_ = -1;
|
||||
}
|
||||
if (mode_ == kCreate && !shm_name_.isEmpty()) {
|
||||
if (mode_ == k_create && !shm_name_.isEmpty()) {
|
||||
// Only the owner unlinks, so the name is freed once both sides have unmapped.
|
||||
shm_unlink(shm_name_.toUtf8().constData());
|
||||
shm_name_.clear();
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
***/
|
||||
|
||||
#ifndef IPC_SHAREDMEMORYREGION_H
|
||||
#define IPC_SHAREDMEMORYREGION_H
|
||||
#ifndef OAK_IPC_SHAREDMEMORYREGION_H
|
||||
#define OAK_IPC_SHAREDMEMORYREGION_H
|
||||
|
||||
#include <cstddef>
|
||||
#include <QString>
|
||||
@@ -46,9 +46,9 @@ class SharedMemoryRegion {
|
||||
public:
|
||||
enum Mode {
|
||||
/// Create (and own) the segment. Fails if it already exists; unlinks on destruction.
|
||||
kCreate,
|
||||
k_create,
|
||||
/// Attach to a segment created by the peer. Does not unlink on destruction.
|
||||
kAttach
|
||||
k_attach
|
||||
};
|
||||
|
||||
SharedMemoryRegion();
|
||||
@@ -63,14 +63,14 @@ public:
|
||||
* `key` is a short identifier (no leading slash needed; the platform prefix is added internally).
|
||||
* Returns true on success. On failure, error() carries a human-readable reason.
|
||||
*/
|
||||
bool Open(const QString &key, size_t size, Mode mode);
|
||||
bool open(const QString &key, size_t size, Mode mode);
|
||||
|
||||
/**
|
||||
* @brief Unmap and (if owner) unlink the segment. Called automatically by the destructor.
|
||||
*/
|
||||
void Close();
|
||||
void close();
|
||||
|
||||
bool IsValid() const
|
||||
bool is_valid() const
|
||||
{
|
||||
return data_ != nullptr;
|
||||
}
|
||||
@@ -100,7 +100,7 @@ public:
|
||||
*
|
||||
* Centralized so the owner and the spawned worker agree on the same name.
|
||||
*/
|
||||
static QString MakeKey(qint64 owner_pid, int worker_index);
|
||||
static QString make_key(qint64 owner_pid, int worker_index);
|
||||
|
||||
private:
|
||||
QString key_;
|
||||
@@ -120,4 +120,4 @@ private:
|
||||
} // namespace ipc
|
||||
} // namespace olive
|
||||
|
||||
#endif // IPC_SHAREDMEMORYREGION_H
|
||||
#endif // OAK_IPC_SHAREDMEMORYREGION_H
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
***/
|
||||
|
||||
#ifndef IPC_SPSCRINGBUFFER_H
|
||||
#define IPC_SPSCRINGBUFFER_H
|
||||
#ifndef OAK_IPC_SPSCRINGBUFFER_H
|
||||
#define OAK_IPC_SPSCRINGBUFFER_H
|
||||
|
||||
#include <atomic>
|
||||
#include <cstddef>
|
||||
@@ -60,7 +60,7 @@ public:
|
||||
* intended to be placement-style initialization performed exactly once by whichever process owns
|
||||
* the segment's creation; the peer process uses Attach() instead.
|
||||
*/
|
||||
static SpscRingBuffer *Create(void *mem, uint32_t capacity)
|
||||
static SpscRingBuffer *create(void *mem, uint32_t capacity)
|
||||
{
|
||||
auto *self = reinterpret_cast<SpscRingBuffer *>(mem);
|
||||
self->capacity_ = capacity;
|
||||
@@ -77,7 +77,7 @@ public:
|
||||
*
|
||||
* No writes are performed; the cursors and capacity are assumed already set by Create().
|
||||
*/
|
||||
static SpscRingBuffer *Attach(void *mem)
|
||||
static SpscRingBuffer *attach(void *mem)
|
||||
{
|
||||
return reinterpret_cast<SpscRingBuffer *>(mem);
|
||||
}
|
||||
@@ -85,7 +85,7 @@ public:
|
||||
/**
|
||||
* @brief Total bytes required to hold the header plus `capacity` index slots.
|
||||
*/
|
||||
static size_t BytesNeeded(uint32_t capacity)
|
||||
static size_t bytes_needed(uint32_t capacity)
|
||||
{
|
||||
return sizeof(SpscRingBuffer) + size_t(capacity) * sizeof(uint32_t);
|
||||
}
|
||||
@@ -93,10 +93,10 @@ public:
|
||||
/**
|
||||
* @brief Producer side: enqueue an index. Returns false if the buffer is full.
|
||||
*/
|
||||
bool Push(uint32_t value)
|
||||
bool push(uint32_t value)
|
||||
{
|
||||
const uint32_t head = head_.load(std::memory_order_relaxed);
|
||||
const uint32_t next = Increment(head);
|
||||
const uint32_t next = increment(head);
|
||||
|
||||
// Buffer is full if advancing head would collide with the consumer's tail.
|
||||
if (next == tail_.load(std::memory_order_acquire)) {
|
||||
@@ -111,7 +111,7 @@ public:
|
||||
/**
|
||||
* @brief Consumer side: dequeue an index into `out`. Returns false if the buffer is empty.
|
||||
*/
|
||||
bool Pop(uint32_t *out)
|
||||
bool pop(uint32_t *out)
|
||||
{
|
||||
const uint32_t tail = tail_.load(std::memory_order_relaxed);
|
||||
|
||||
@@ -121,7 +121,7 @@ public:
|
||||
}
|
||||
|
||||
*out = slot_array()[tail];
|
||||
tail_.store(Increment(tail), std::memory_order_release);
|
||||
tail_.store(increment(tail), std::memory_order_release);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -131,14 +131,14 @@ public:
|
||||
* Safe to call from either side, but the value may be stale the instant it returns. Intended for
|
||||
* metrics/backpressure heuristics, not for correctness decisions.
|
||||
*/
|
||||
uint32_t SizeApprox() const
|
||||
uint32_t size_approx() const
|
||||
{
|
||||
const uint32_t head = head_.load(std::memory_order_acquire);
|
||||
const uint32_t tail = tail_.load(std::memory_order_acquire);
|
||||
return (head + capacity_ - tail) % capacity_;
|
||||
}
|
||||
|
||||
bool IsEmptyApprox() const
|
||||
bool is_empty_approx() const
|
||||
{
|
||||
return head_.load(std::memory_order_acquire) ==
|
||||
tail_.load(std::memory_order_acquire);
|
||||
@@ -150,7 +150,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t Increment(uint32_t index) const
|
||||
uint32_t increment(uint32_t index) const
|
||||
{
|
||||
// capacity_ is small and this avoids requiring a power-of-two capacity.
|
||||
return (index + 1) % capacity_;
|
||||
@@ -182,4 +182,4 @@ private:
|
||||
} // namespace ipc
|
||||
} // namespace olive
|
||||
|
||||
#endif // IPC_SPSCRINGBUFFER_H
|
||||
#endif // OAK_IPC_SPSCRINGBUFFER_H
|
||||
|
||||
Reference in New Issue
Block a user