MCPcopy Create free account
hub / github.com/attermann/microReticulum / op_commit

Method op_commit

src/microReticulum/Provisioning/Provisioning.cpp:759–826  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

757 }
758
759 Bytes Provisioner::op_commit(seq_t seq, void* unpacker_v) {
760 MsgPack::Unpacker* up = (MsgPack::Unpacker*)unpacker_v;
761 std::vector<nid_t> filter;
762 bool has_filter = false;
763 if (up && up->isArray()) {
764 const size_t n = up->unpackArraySize();
765 has_filter = true;
766 for (size_t i = 0; i < n; ++i) {
767 if (up->isUInt() || up->isInt()) {
768 fint_t v; up->deserialize(v);
769 filter.push_back((nid_t)v);
770 }
771 else skip_value(*up);
772 }
773 }
774 else if (up) skip_value(*up);
775
776 size_t applied_total = 0;
777 bool any_reboot = false;
778
779 auto do_one = [&](Namespace& ns) {
780 // Pre-commit hook: fires once per namespace iff at least one
781 // draft entry exists, before any field setter runs. Mirrors
782 // the in-process Provisioner::commit path so wire-driven commits
783 // see identical semantics.
784 bool has_any_draft = false;
785 for (const Field& f : ns.fields()) {
786 if (ns.has_draft(f.id)) { has_any_draft = true; break; }
787 }
788 if (has_any_draft && ns.has_on_commit()) {
789 try { ns.on_commit_callback()(ns); }
790 catch (const std::exception& e) {
791 ERRORF("Provisioning::op_commit: on_commit callback for namespace %u threw: %s",
792 ns.id(), e.what());
793 }
794 }
795 std::vector<fid_t> ids;
796 for (const Field& f : ns.fields()) if (ns.has_draft(f.id)) ids.push_back(f.id);
797 for (fid_t id : ids) {
798 auto outcome = ns.commit_one(id);
799 switch (outcome) {
800 case Namespace::CommitOutcome::AppliedLive:
801 ++applied_total; break;
802 case Namespace::CommitOutcome::AppliedReboot:
803 ++applied_total; any_reboot = true; break;
804 default: break;
805 }
806 }
807 if (_storage) _storage->save_namespace(ns);
808 };
809
810 if (has_filter) {
811 for (nid_t id : filter) {
812 Namespace* ns = _registry.find(id);
813 if (ns) do_one(*ns);
814 }
815 }
816 else {

Callers

nothing calls this directly

Calls 8

pack_responseFunction · 0.85
has_draftMethod · 0.80
has_on_commitMethod · 0.80
idMethod · 0.80
commit_oneMethod · 0.80
save_namespaceMethod · 0.80
skip_valueFunction · 0.70
findMethod · 0.45

Tested by

no test coverage detected