Skip to content

Commit

Permalink
Commiting old code
Browse files Browse the repository at this point in the history
  • Loading branch information
nstiurca committed Feb 24, 2019
1 parent d701e49 commit 41c039d
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 24 deletions.
31 changes: 31 additions & 0 deletions Manifest.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
# This file is machine-generated - editing it directly is not advised

[[Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

[[Distributed]]
deps = ["Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"

[[InteractiveUtils]]
deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[[Libdl]]
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"

[[Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"

[[Markdown]]
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[Random]]
deps = ["Serialization"]
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[[Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

[[Sockets]]
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"

[[Test]]
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
authors = ["Nicu Stiurca <[email protected]>"]
name = "Rcl"
uuid = "78a8c452-60eb-11e8-3cb2-e7ea7ae9c7f8"
authors = ["Nicu Stiurca <[email protected]>"]
version = "0.1.0"

[deps]
Expand Down
1 change: 0 additions & 1 deletion gen/wrap_rcl2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ clang_includes=[
ROS_INCLUDE_PATH,
"/usr/include",
"/usr/lib/llvm-6.0/lib/clang/6.0.0/include", # stdbool.h
"/usr/lib/llvm-3.9/lib/clang/3.9.1/include", # stdbool.h
]

function header_wrapped(header_file, cursor_name)
Expand Down
2 changes: 2 additions & 0 deletions src/Rcl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ include("node_base.jl")
end

export rcl
using .rcl: name, namespace
export name, namespace

# abstract type Node end
# abstract type Logger end
Expand Down
40 changes: 19 additions & 21 deletions src/node_base.jl
Original file line number Diff line number Diff line change
@@ -1,44 +1,42 @@
import ..internal
mutable struct NodeBase
rcl_node::internal.rcl_node_t
rcl_node::Ref{internal.rcl_node_t}

NodeBase(node_name, namespace) = begin
rcl_node = internal.rcl_get_zero_initialized_node()

default_options = internal.rcl_node_get_default_options()
# allocator = internal.rcl_get_default_allocator()
# @assert internal.rcutils_allocator_is_valid(pointer_from_objref(allocator))
# @async @show allocator
# options = internal.rcl_node_options_t(internal.RCL_NODE_OPTIONS_DEFAULT_DOMAIN_ID, allocator)
# @assert internal.rcutils_allocator_is_valid(pointer_from_objref(options.allocator))

# @show allocator
# @show options
# @show default_options
rcl_node_handle = pointer_from_objref(rcl_node)
default_options_handle = pointer_from_objref(default_options)
internal.checkcall(internal.rcl_node_init(rcl_node_handle, node_name, namespace, default_options_handle))
rcl_node = Ref(internal.rcl_get_zero_initialized_node())
default_options = Ref(internal.rcl_node_get_default_options())
internal.checkcall(internal.rcl_node_init(rcl_node, node_name, namespace, default_options))

new(rcl_node)
end
end

NodeBase(node_name) = NodeBase(node_name, "")
Base.finalize(rcl_node::internal.rcl_node_t) = internal.checkcall(internal.rcl_node_fini(pointer_from_objref(rcl_node)); suppress_throw=true)
NodeBase(node_name) = NodeBase(node_name, "/")
Base.finalize(rcl_node::Ref{internal.rcl_node_t}) = internal.checkcall(internal.rcl_node_fini(rcl_node); suppress_throw=true)
Base.finalize(nb::NodeBase) = finalize(nb.rcl_node)

mutable struct CallbackGroup
end

function name(nb::NodeBase) end
function namespace(nb::NodeBase) end
function name(nb::NodeBase)
n = internal.rcl_node_get_name(nb.rcl_node)
n == C_NULL && error("node name returned NULL. Is the node NULL or un-initialized?")
unsafe_string(n)
end

function namespace(nb::NodeBase)
n = internal.rcl_node_get_namespace(nb.rcl_node)
n == C_NULL && error("node name returned NULL. Is the node NULL or un-initialized?")
unsafe_string(n)
end

function context(nb::NodeBase) end
# function rcl_node_handle(nb::NodeBase) end
function CallbackGroup(nb::NodeBase) end
function default_callback_group(nb::NodeBase) end
import Base: in, isvalid
function in(cg::CallbackGroup, nb::NodeBase) end
isvalid(nb::NodeBase) = internal.rcl_node_is_valid(pointer_from_objref(nb.rcl_node), C_NULL)
isvalid(nb::NodeBase) = internal.rcl_node_is_valid(nb.rcl_node, C_NULL)
function callback_groups(nb::NodeBase) end
function callback_groups!(cbs, nb::NodeBase) end
function associated_with_executor_atomic(nb::NodeBase) :: Threads.Atomic{Bool} end
Expand Down
19 changes: 18 additions & 1 deletion test/unit/node_base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ using Rcl
import Rcl.internal: rcutils_error_is_set, rcutils_reset_error
using Test

@testset "Node" begin
@testset "node base" begin
# initialize
@test !rcl.ok()
rcl.init()
@test rcl.ok()

@test !rcutils_error_is_set()
nb = rcl.NodeBase("test_node")
@test rcl.isvalid(nb)

@test name(nb) == "test_node"
@test namespace(nb) == "/"

# finalizing it shouldn't cause errors
finalize(nb)
@test !rcutils_error_is_set()
Expand All @@ -25,6 +29,19 @@ using Test
rcutils_reset_error()
@test !rcutils_error_is_set()

@testset "name and namspace" begin
foo_node = rcl.NodeBase("foo", "foo_ns")
@test name(foo_node) == "foo"
@test namespace(foo_node) == "/foo_ns"

bar_node = rcl.NodeBase("bar", "/biz/baz")
@test name(bar_node) == "bar"
@test namespace(bar_node) == "/biz/baz"

finalize(foo_node)
finalize(bar_node)
end

# shutdown
@test rcl.ok()
rcl.shutdown()
Expand Down

0 comments on commit 41c039d

Please sign in to comment.