$ show dresden-elektronik/deconz-rest-plugin
This repository is the deCONZ REST plugin, a C++/Qt plugin that turns a ConBee/RaspBee Zigbee USB gateway into a full-featured IoT controller. It exposes a REST API (emulating Philips Hue) to manage lights, sensors, groups, scenes, rules, schedules, alarms, and devices over Zigbee (ZCL, ZDP, Green Power). The architecture is a monolithic Qt plugin running inside the deCONZ application, with a dedicated event loop, WebSocket server, and persistent SQLite database. Key entry points include `DeRestPlugin` (plugin interface), `DeRestPluginPrivate` (core logic), and REST handlers in files like `rest_lights.cpp`, `rest_sensors.cpp`, `rest_groups.cpp`. Device support is largely externalized via JSON Device Description Files (DDF) and embedded JavaScript (Duktape) for vendor-specific parsing. External dependencies include Qt 5/6, OpenSSL (dynamically loaded), Duktape, and system utilities (tar, gzip). The codebase is actively maintained with frequent commits, but contains technical debt from legacy device quirk handling and dual (DDF vs. legacy) initialization paths.
The LLM identified 4 files worth highlighting for reuse:
A compile-time string cache with `StringCache` and `BufString` classes that provide zero-allocation string handling using `char[]` buffers. This is used in performance-critical paths of the JSON builder and attribute handling. It is self-contained and could be extracted for any embedded or high-performance C++ project needing string interning.
A fixed-size arena allocator (`ScratchMem`) for temporary allocations without malloc/free overhead. Used in DDF parsing and JSON construction. The pattern is isolated and reusable for any application requiring allocation-free scratch memory.
A minimal, token-based JSON parser written in C with no external dependencies. It provides `cj_parse`, `cj_ref` helpers, and optional `cj_copy_ref_utf8` for UTF-8 conversion. It is used throughout the codebase for DDF and REST responses. The parser is self-contained and suitable for environments where full JSON libraries are too heavy.
The `Resource` and `ResourceItem` classes define a generic typed attribute container with flags for push, store, and change detection. Every device (light, sensor, group) exposes its state and config as ResourceItems. The pattern allows decoupling of data model from storage and REST serialization, and could be reused in any IoT or data model framework.