| … | … | @@ -50,6 +50,32 @@ StorageNode::~StorageNode() |
| 50 | 50 | { |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | AtomSpace* StorageNode::get_target_as(const ValuePtr& value) const |
| 54 | { |
| 55 | if (value->is_type(ATOM_SPACE)) |
| 56 | return AtomSpaceCast(value).get(); |
| 57 | |
| 58 | if (nullptr == vp or 0 == vp->size()) |
| 59 | return _target_as.get(); |
| 60 | |
| 61 | ValuePtr vp(value); |
| 62 | if (vp->is_type(ATOM)) |
| 63 | { |
| 64 | Handle h(HandleCast(value)); |
| 65 | if (h->is_executable()) |
| 66 | vp = h->execute(); |
| 67 | } |
| 68 | |
| 69 | if (vp->is_type(ATOM_SPACE)) |
| 70 | return AtomSpaceCast(vp).get(); |
| 71 | |
| 72 | if (nullptr == vp or 0 == vp->size()) |
| 73 | return _target_as.get(); |
| 74 | |
| 75 | throw RuntimeException(TRACE_INFO, |
| 76 | "Expected AtomSpace; got %s", value->to_string().c_str()); |
| 77 | } |
| 78 | |
| 53 | 79 | void StorageNode::setValue(const Handle& key, const ValuePtr& value) |
| 54 | 80 | { |
| 55 | 81 | // The value must be stored only if it is not one of the values |
| … | … | @@ -127,23 +153,9 @@ void StorageNode::setValue(const Handle& key, const ValuePtr& value) |
| 127 | 153 | { |
| 128 | 154 | case p_open: { |
| 129 | 155 | COLL("*-open-*"); |
| 130 | | ValuePtr vp(value); |
| 131 | | if (vp->is_type(ATOM)) |
| 132 | | { |
| 133 | | Handle h(HandleCast(value)); |
| 134 | | if (h->is_executable()) |
| 135 | | vp = h->execute(); |
| 136 | | } |
| 137 | | |
| 138 | | if (vp->is_type(ATOM_SPACE)) |
| 139 | | _target_as = AtomSpaceCast(value); |
| 140 | | else if (nullptr == vp or 0 == vp->size()) |
| 141 | | _target_as = AtomSpaceCast(getAtomSpace()->shared_from_this()); |
| 142 | | else |
| 143 | | throw RuntimeException(TRACE_INFO, |
| 144 | | "Expected *-open-* message expects AtomSpace; got %s", |
| 145 | | value->to_string().c_str()); |
| 146 | | |
| 156 | AtomSpace* as = get_target_as(value); |
| 157 | if (nullptr == as) as = getAtomSpace(); |
| 158 | __target_as = AtomSpaceCast(as->shared_from_this()); |
| 147 | 159 | open(); |
| 148 | 160 | return; |
| 149 | 161 | } |
| … | … | @@ -154,17 +166,11 @@ void StorageNode::setValue(const Handle& key, const ValuePtr& value) |
| 154 | 166 | return; |
| 155 | 167 | case p_load_atomspace: |
| 156 | 168 | COLL("*-load-atomspace-*"); |
| 157 | | if (nullptr == value or 0 == value->size()) |
| 158 | | load_atomspace(_target_as.get()); |
| 159 | | else |
| 160 | | load_atomspace(AtomSpaceCast(value).get()); |
| 169 | load_atomspace(get_target_as(value)); |
| 161 | 170 | return; |
| 162 | 171 | case p_store_atomspace: |
| 163 | 172 | COLL("*-store-atomspace-*"); |
| 164 | | if (nullptr == value or 0 == value->size()) |
| 165 | | store_atomspace(_target_as.get()); |
| 166 | | else |
| 167 | | store_atomspace(AtomSpaceCast(value).get()); |
| 173 | store_atomspace(get_target_as(value)); |
| 168 | 174 | return; |
| 169 | 175 | case p_load_atoms_of_type: { |
| 170 | 176 | COLL("*-load-atoms-of-type-*"); |
| … | … | @@ -301,10 +307,7 @@ void StorageNode::setValue(const Handle& key, const ValuePtr& value) |
| 301 | 307 | return; |
| 302 | 308 | case p_barrier: |
| 303 | 309 | COLL("*-barrier-*"); |
| 304 | | if (nullptr == value or 0 == value->size()) |
| 305 | | barrier(_target_as.get()); |
| 306 | | else |
| 307 | | barrier(AtomSpaceCast(value).get()); |
| 310 | barrier(get_target_as(value)); |
| 308 | 311 | return; |
| 309 | 312 | case p_store_frames: |
| 310 | 313 | COLL("*-store-frames-*"); |
| … | … | @@ -370,7 +373,7 @@ void StorageNode::barrier(AtomSpace* as) |
| 370 | 373 | |
| 371 | 374 | void StorageNode::store_atom(const Handle& h) |
| 372 | 375 | { |
| 373 | | if (_atom_space->get_read_only()) |
| 376 | if (_target_as->get_read_only()) |
| 374 | 377 | throw RuntimeException(TRACE_INFO, "Read-only AtomSpace!"); |
| 375 | 378 | |
| 376 | 379 | storeAtom(h); |
| … | … | @@ -378,7 +381,7 @@ void StorageNode::store_atom(const Handle& h) |
| 378 | 381 | |
| 379 | 382 | void StorageNode::store_value(const Handle& h, const Handle& key) |
| 380 | 383 | { |
| 381 | | if (_atom_space->get_read_only()) |
| 384 | if (_target_as->get_read_only()) |
| 382 | 385 | throw RuntimeException(TRACE_INFO, "Read-only AtomSpace!"); |
| 383 | 386 | |
| 384 | 387 | storeValue(h, key); |
| … | … | @@ -387,7 +390,7 @@ void StorageNode::store_value(const Handle& h, const Handle& key) |
| 387 | 390 | void StorageNode::update_value(const Handle& h, const Handle& key, |
| 388 | 391 | const ValuePtr& delta) |
| 389 | 392 | { |
| 390 | | if (_atom_space->get_read_only()) |
| 393 | if (_target_as->get_read_only()) |
| 391 | 394 | throw RuntimeException(TRACE_INFO, "Read-only AtomSpace!"); |
| 392 | 395 | |
| 393 | 396 | updateValue(h, key, delta); |