Skip to content

Commit

Permalink
FLesh out LibRcl.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
nstiurca committed Feb 25, 2019
1 parent c153979 commit a86f82b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 14 deletions.
34 changes: 33 additions & 1 deletion gen/LibRcl.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module LibRcl

import Libdl
# import Libdl

include("../src/find_ros2.jl")

Expand All @@ -22,6 +22,7 @@ include("ctypes.jl")
const SIZE_MAX = ~Csize_t(0)

for lib in WRAPPED_ROS2_LIBS
@info "Loading types and API for library $lib"
include(joinpath(@__DIR__, "lib$(lib)_common.jl"))
include(joinpath(@__DIR__, "lib$(lib)_api.jl"))
end
Expand All @@ -33,4 +34,35 @@ end
# end
#end

# dynamically load the ROS2 libraries
# const librmw = find_library(["librmw.$dlext"])
# const librcl = find_library(["librcl.$dlext"])
# const librcutils = find_library(["librcutils.$dlext"])

# const librmw = dlopen(librmw_path)
# const librcutils = dlopen(librcutils_path)
# const librcl = dlopen(librcl_path)

# include the auto-gen-ed wrappers for the C functions/structs/constants
# include("gen_librcl_h.jl")
# include("gen_librcl.jl")

struct RclError <: Exception
code :: Cint
msg :: AbstractString
end

function checkcall(code :: rcl_ret_t; suppress_throw=false)
code == RCL_RET_OK && return nothing

msg = rcutils_get_error_string()
@assert msg != Cstring(C_NULL)
err = RclError(code, unsafe_string(msg))

rcutils_reset_error()

suppress_throw || throw(err)
err
end

end # module
28 changes: 15 additions & 13 deletions src/Rcl.jl
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
module Rcl

module internal
include("internal.jl")
end
include(joinpath(@__DIR__, "..", "gen", "LibRcl.jl"))

using .internal: RclError
# module internal
# include("internal.jl")
# end
#
using .LibRcl: RclError
export RclError

module rcl
include("base.jl")
include("node_base.jl")
end

export rcl
using .rcl: name, namespace
export name, namespace
#
# module rcl
# include("base.jl")
# include("node_base.jl")
# end
#
# export rcl
# using .rcl: name, namespace
# export name, namespace

# abstract type Node end
# abstract type Logger end
Expand Down
9 changes: 9 additions & 0 deletions src/find_ros2.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Libdl: dlext, find_library
# TODO: handle missing values gracefully

const ROS_VERSION = VersionNumber(ENV["ROS_VERSION"])
Expand All @@ -12,3 +13,11 @@ const ROS_INCLUDE_PATH = joinpath(AMENT_PREFIX_PATH, "include")
const ROS_LIB_PATH = joinpath(AMENT_PREFIX_PATH, "lib")

const WRAPPED_ROS2_LIBS = ["rcutils", "rosidl_generator_c", "rmw", "rcl"]

# dynamically load the ROS2 libraries
for lib_name in WRAPPED_ROS2_LIBS
lib_var = Symbol("lib", lib_name)
lib_fname = "lib$lib_name.$dlext"
@info "Loading library $lib_name"
@eval const $lib_var = Symbol(find_library([$lib_fname]))
end

0 comments on commit a86f82b

Please sign in to comment.