| … | … | @@ -29,32 +29,13 @@ |
| 29 | 29 | |
| 30 | 30 | using namespace opencog; |
| 31 | 31 | |
| 32 | | /// Implement Jenkins' One-at-a-Time hash for message dispatch. |
| 33 | | static 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 | | |
| 51 | 32 | CogServerNode::CogServerNode(Type t, const std::string&& s) |
| 52 | | : Node(t, std::move(s)), CogServer() |
| 33 | : ObjectCRTP<CogServerNode>(t, std::move(s)), CogServer() |
| 53 | 34 | { |
| 54 | 35 | } |
| 55 | 36 | |
| 56 | 37 | CogServerNode::CogServerNode(const std::string&& s) |
| 57 | | : Node(COG_SERVER_NODE, std::move(s)), CogServer() |
| 38 | : ObjectCRTP<CogServerNode>(COG_SERVER_NODE, std::move(s)), CogServer() |
| 58 | 39 | { |
| 59 | 40 | } |
| 60 | 41 | |
| … | … | @@ -119,45 +100,6 @@ void CogServerNode::stopServers() |
| 119 | 100 | disableNetworkServer(); |
| 120 | 101 | } |
| 121 | 102 | |
| 122 | | HandleSeq 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 | | |
| 144 | | bool 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 | | |
| 161 | 103 | ValuePtr CogServerNode::getValue(const Handle& key) const |
| 162 | 104 | { |
| 163 | 105 | // Handle the *-is-running?-* query |