OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-atomspace-storage commits / 0bec1c1

Inherit from ObjectNode
0bec1c1723dce555a491443167b6ab4fb1a0c805
by Linas Vepštas <linasvepstas@gmail.com> · 2026-01-17T23:42:54.000Z

Changed files (2) +41 -102

opencog/persist/api/StorageNode.cc +1 -98
……@@ -37,7 +37,7 @@ using namespace opencog;
3737// ====================================================================
3838
3939StorageNode::StorageNode(Type t, std::string uri) :
40 Node(t, uri)
40 ObjectCRTP<StorageNode>(t, std::move(uri))
4141{
4242 if (not nameserver().isA(t, STORAGE_NODE))
4343 throw RuntimeException(TRACE_INFO, "Bad inheritance!");
……@@ -47,103 +47,6 @@ StorageNode::~StorageNode()
4747{
4848}
4949
50HandleSeq StorageNode::getMessages() const
51{
52 static const HandleSeq msgs = []() {
53 HandleSeq m({
54 createNode(PREDICATE_NODE, "*-open-*"),
55 createNode(PREDICATE_NODE, "*-close-*"),
56 createNode(PREDICATE_NODE, "*-load-atomspace-*"),
57 createNode(PREDICATE_NODE, "*-store-atomspace-*"),
58 createNode(PREDICATE_NODE, "*-load-atoms-of-type-*"),
59 createNode(PREDICATE_NODE, "*-store-atom-*"),
60 createNode(PREDICATE_NODE, "*-store-value-*"),
61 createNode(PREDICATE_NODE, "*-update-value-*"),
62
63 createNode(PREDICATE_NODE, "*-fetch-atom-*"),
64 createNode(PREDICATE_NODE, "*-fetch-value-*"),
65 createNode(PREDICATE_NODE, "*-fetch-incoming-set-*"),
66 createNode(PREDICATE_NODE, "*-fetch-incoming-by-type-*"),
67 createNode(PREDICATE_NODE, "*-fetch-query-*"),
68
69 createNode(PREDICATE_NODE, "*-delete-*"),
70 createNode(PREDICATE_NODE, "*-delete-recursive-*"),
71 createNode(PREDICATE_NODE, "*-barrier-*"),
72
73 createNode(PREDICATE_NODE, "*-store-frames-*"),
74 createNode(PREDICATE_NODE, "*-delete-frame-*"),
75 createNode(PREDICATE_NODE, "*-erase-*"),
76
77 createNode(PREDICATE_NODE, "*-proxy-open-*"),
78 createNode(PREDICATE_NODE, "*-proxy-close-*"),
79 createNode(PREDICATE_NODE, "*-set-proxy-*"),
80
81 // Used only in getValue
82 createNode(PREDICATE_NODE, "*-load-frames-*"),
83 createNode(PREDICATE_NODE, "*-connected?-*"),
84 createNode(PREDICATE_NODE, "*-load-frames-*"),
85 createNode(PREDICATE_NODE, "*-monitor-*")
86 });
87 // Mark each message predicate as a message, once at load time.
88 for (const Handle& h : m)
89 h->markIsMessage();
90 return m;
91 }();
92
93 // Copy list above into the local AtomSpace. If this is not done,
94 // then (cog-execute! (IsMessage (Predicate "*-open-*"))) will fail.
95 HandleSeq lms;
96 for (const Handle& m : msgs)
97 lms.emplace_back(_atom_space->add(m));
98 return lms;
99}
100
101bool StorageNode::usesMessage(const Handle& key) const
102{
103 static const std::unordered_set<uint32_t> msgset({
104 dispatch_hash("*-open-*"),
105 dispatch_hash("*-close-*"),
106 dispatch_hash("*-load-atomspace-*"),
107 dispatch_hash("*-store-atomspace-*"),
108 dispatch_hash("*-load-atoms-of-type-*"),
109 dispatch_hash("*-store-atom-*"),
110 dispatch_hash("*-store-value-*"),
111 dispatch_hash("*-update-value-*"),
112
113 dispatch_hash("*-fetch-atom-*"),
114 dispatch_hash("*-fetch-value-*"),
115 dispatch_hash("*-fetch-incoming-set-*"),
116 dispatch_hash("*-fetch-incoming-by-type-*"),
117 dispatch_hash("*-fetch-query-*"),
118
119 dispatch_hash("*-delete-*"),
120 dispatch_hash("*-delete-recursive-*"),
121 dispatch_hash("*-barrier-*"),
122
123 dispatch_hash("*-store-frames-*"),
124 dispatch_hash("*-delete-frame-*"),
125 dispatch_hash("*-erase-*"),
126
127 dispatch_hash("*-proxy-open-*"),
128 dispatch_hash("*-proxy-close-*"),
129 dispatch_hash("*-set-proxy-*")
130 });
131
132 // Messages used in getValue only don't need to be published here,
133 // because only the setValue ones need the COW, R/O work-around.
134 // ("*-load-frames-*")
135 // ("*-connected?-*")
136 // ("*-load-frames-*")
137 // ("*-monitor-*")
138
139 if (PREDICATE_NODE != key->get_type()) return false;
140
141 const std::string& pred = key->get_name();
142 uint32_t dhsh = dispatch_hash(pred.c_str());
143 if (msgset.find(dhsh) != msgset.end()) return true;
144 return false;
145}
146
14750void StorageNode::setValue(const Handle& key, const ValuePtr& value)
14851{
14952 // The value must be stored only if it is not one of the values
opencog/persist/api/StorageNode.h +40 -4
……@@ -25,7 +25,7 @@
2525#ifndef _OPENCOG_STORAGE_NODE_H
2626#define _OPENCOG_STORAGE_NODE_H
2727
28#include <opencog/atoms/base/Node.h>
28#include <opencog/atoms/core/ObjectNode.h>
2929#include <opencog/atomspace/AtomSpace.h>
3030#include <opencog/persist/api/BackingStore.h>
3131#include <opencog/atoms/atom_types/atom_types.h>
……@@ -35,7 +35,7 @@ namespace opencog
3535/** \addtogroup grp_atomspace
3636 * @{
3737 */
38class StorageNode : public Node, protected BackingStore
38class StorageNode : public ObjectCRTP<StorageNode>, protected BackingStore
3939{
4040 // The write-thru proxies need to call into the BackingStore
4141 // directly. We declare them as friends.
……@@ -65,8 +65,6 @@ public:
6565
6666 virtual void setValue(const Handle&, const ValuePtr&);
6767 virtual ValuePtr getValue(const Handle&) const;
68 virtual HandleSeq getMessages() const;
69 virtual bool usesMessage(const Handle&) const;
7068
7169 // ----------------------------------------------------------------
7270 // Operations regarding the connection to the remote URI.
……@@ -331,6 +329,44 @@ public:
331329 void remove_atom(AtomSpace*, Handle, bool recursive=false);
332330 void remove_atom(const AtomSpacePtr& as, Handle h, bool recursive=false)
333331 { remove_atom(as.get(), h, recursive); }
332
333private:
334 static constexpr const char* _messages[] = {
335 "*-open-*",
336 "*-close-*",
337 "*-load-atomspace-*",
338 "*-store-atomspace-*",
339 "*-load-atoms-of-type-*",
340 "*-store-atom-*",
341 "*-store-value-*",
342 "*-update-value-*",
343
344 "*-fetch-atom-*",
345 "*-fetch-value-*",
346 "*-fetch-incoming-set-*",
347 "*-fetch-incoming-by-type-*",
348 "*-fetch-query-*",
349
350 "*-delete-*",
351 "*-delete-recursive-*",
352 "*-barrier-*",
353
354 "*-store-frames-*",
355 "*-delete-frame-*",
356 "*-erase-*",
357
358 "*-proxy-open-*",
359 "*-proxy-close-*",
360 "*-set-proxy-*",
361
362 // Messages used in getValue only don't need to be published here,
363 // because only the setValue ones need the COW, R/O work-around.
364 // ???
365 "*-load-frames-*",
366 "*-connected?-*",
367 "*-load-frames-*",
368 "*-monitor-*"
369 };
334370};
335371
336372NODE_PTR_DECL(StorageNode)