OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-cogserver commits / ea8f47e

CogServer to inherit from bjectNode
ea8f47e53c3097d20b262093c14bcbc5bb907cf1
by Linas Vepštas <linasvepstas@gmail.com> · 2026-01-17T23:30:21.000Z

Changed files (2) +11 -64

opencog/cogserver/atoms/CogServerNode.cc +2 -60
……@@ -29,32 +29,13 @@
2929
3030using namespace opencog;
3131
32/// Implement Jenkins' One-at-a-Time hash for message dispatch.
33static constexpr uint32_t dispatch_hash(const char* s)
34{
35 uint32_t hash = 0;
36
37 for(; *s; ++s)
38 {
39 hash += *s;
40 hash += (hash << 10);
41 hash ^= (hash >> 6);
42 }
43
44 hash += (hash << 3);
45 hash ^= (hash >> 11);
46 hash += (hash << 15);
47
48 return hash;
49}
50
5132CogServerNode::CogServerNode(Type t, const std::string&& s)
52 : Node(t, std::move(s)), CogServer()
33 : ObjectCRTP<CogServerNode>(t, std::move(s)), CogServer()
5334{
5435}
5536
5637CogServerNode::CogServerNode(const std::string&& s)
57 : Node(COG_SERVER_NODE, std::move(s)), CogServer()
38 : ObjectCRTP<CogServerNode>(COG_SERVER_NODE, std::move(s)), CogServer()
5839{
5940}
6041
……@@ -119,45 +100,6 @@ void CogServerNode::stopServers()
119100 disableNetworkServer();
120101}
121102
122HandleSeq CogServerNode::getMessages() const
123{
124 static const HandleSeq msgs = []() {
125 HandleSeq m({
126 Predicate("*-start-*"),
127 Predicate("*-stop-*"),
128 Predicate("*-run-*"),
129 Predicate("*-is-running?-*")
130 });
131 // Mark each message predicate as a message, once at load time.
132 for (const Handle& h : m)
133 h->markIsMessage();
134 return m;
135 }();
136
137 // Copy list above into the local AtomSpace.
138 HandleSeq lms;
139 for (const Handle& m : msgs)
140 lms.emplace_back(_atom_space->add_atom(m));
141 return lms;
142}
143
144bool CogServerNode::usesMessage(const Handle& key) const
145{
146 static const std::unordered_set<uint32_t> msgset({
147 dispatch_hash("*-start-*"),
148 dispatch_hash("*-stop-*"),
149 dispatch_hash("*-run-*"),
150 dispatch_hash("*-is-running?-*")
151 });
152
153 if (PREDICATE_NODE != key->get_type()) return false;
154
155 const std::string& pred = key->get_name();
156 uint32_t dhsh = dispatch_hash(pred.c_str());
157 if (msgset.find(dhsh) != msgset.end()) return true;
158 return false;
159}
160
161103ValuePtr CogServerNode::getValue(const Handle& key) const
162104{
163105 // Handle the *-is-running?-* query
opencog/cogserver/atoms/CogServerNode.h +9 -4
……@@ -20,7 +20,7 @@
2020#ifndef _OPENCOG_COG_SERVER_NODE_H
2121#define _OPENCOG_COG_SERVER_NODE_H
2222
23#include <opencog/atoms/base/Node.h>
23#include <opencog/atoms/core/ObjectNode.h>
2424#include <opencog/atomspace/AtomSpace.h>
2525#include <opencog/cogserver/server/CogServer.h>
2626#include <opencog/cogserver/types/atom_types.h>
……@@ -37,7 +37,7 @@ namespace opencog
3737 * to this node to hold server configuration and state.
3838 */
3939
40class CogServerNode : public Node, public CogServer
40class CogServerNode : public ObjectCRTP<CogServerNode>, public CogServer
4141{
4242public:
4343 // Please do NOT use this constructor!
……@@ -52,8 +52,6 @@ public:
5252 virtual void setValue(const Handle&, const ValuePtr&);
5353 virtual ValuePtr getValue(const Handle&) const;
5454 virtual void setAtomSpace(AtomSpace*) override;
55 virtual HandleSeq getMessages() const;
56 virtual bool usesMessage(const Handle&) const;
5755
5856 Handle getHandle() override { return get_handle(); }
5957
……@@ -63,6 +61,13 @@ private:
6361 bool startServers();
6462 void stopServers();
6563 std::thread* _main_loop = nullptr;
64
65 static constexpr const char* _messages[] = {
66 "*-start-*",
67 "*-stop-*",
68 "*-run-*",
69 "*-is-running?-*"
70 };
6671};
6772
6873NODE_PTR_DECL(CogServerNode)