Skip to content

Commit

Permalink
core.shm: Add alias() and children()
Browse files Browse the repository at this point in the history
alias(toname, fromname) creates a new name for an existing
object. This is implemented as a symlink.

children() lists the names of objects under a path. This is a
directory listing.

The initial use for these features is providing links to apps. The app
has to learn what links it has using children() and each link it finds
is an alias of one created by the engine.

For example, the link 'a.tx->b.rx' would be one shm object created by
the engine with a symlink to make it available to each app:

    /engine/link/a.tx->b.rx  (real struct link created by engine)
    /app/a/link/output/tx -> /engine/link/a.tx->b.rx
    /app/b/link/input/rx  -> /engine/link/a.tx->b.rx
  • Loading branch information
lukego committed Jun 6, 2015
1 parent 49dfcb4 commit c99b36a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/core/shm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,20 @@ function unlink (name)
return S.util.rm(root..'/'..path) -- recursive rm of file or directory
end

-- Return an array of objects under the prefix name.
-- The names are returned unqualified e.g. 'x' and not 'foo/bar/x'.
function children (name)
-- XXX dirtable returns an array but with a special tostring metamethod.
-- Potentially confusing? (Copy into plain array instead?)
return S.util.dirtable(root.."/"..resolve(name), true) or {}
end

-- Create an additional name for an existing object.
function alias (toname, fromname)
assert(S.symlink(root.."/"..resolve(toname), root.."/"..resolve(fromname)),
"alias symlink failed")
end

function selftest ()
print("selftest: shm")
print("checking paths..")
Expand All @@ -145,10 +159,13 @@ function selftest ()
print("create "..name)
local p1 = map(name, "struct { int x, y, z; }")
local p2 = map(name, "struct { int x, y, z; }")
alias(name, name..".alias")
local p3 = map(name..".alias", "struct { int x, y, z; }")
assert(p1 ~= p2)
assert(p1.x == p2.x)
p1.x = 42
assert(p1.x == p2.x)
assert(p1.x == p3.x)
assert(unlink(name))
unmap(p1)
unmap(p2)
Expand All @@ -164,6 +181,7 @@ function selftest ()
print(n.." objects created")
for i = 1, n do unmap(objs[i]) end
print(n.." objects unmapped")
assert((#children("/shm/selftest/manyobj/obj")) == n, "child count mismatch")
assert(unlink("/"))
print("selftest ok")
end
Expand Down

0 comments on commit c99b36a

Please sign in to comment.