Skip to content

Commit

Permalink
Deprecation fixes for julia 0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
jdlangs committed Mar 13, 2017
1 parent 3855cc7 commit c7ecdc9
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 68 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -2,6 +2,7 @@ language: julia
julia:
- 0.4
- 0.5
- 0.6
- nightly
sudo: required
dist: trusty
Expand Down
4 changes: 2 additions & 2 deletions REQUIRE
@@ -1,3 +1,3 @@
julia 0.4
PyCall
Compat 0.8.0
PyCall 1.11.0
Compat 0.17.0
28 changes: 14 additions & 14 deletions src/gentypes.jl
Expand Up @@ -8,7 +8,7 @@ export @rosimport, rostypegen, rostypereset, gentypes, cleartypes
#Type definitions
#Composite types for internal use. Keeps track of the imported types and helps
#keep code generation orderly.
abstract ROSModule
@compat abstract type ROSModule end
type ROSPackage
name::String
msg::ROSModule
Expand All @@ -33,7 +33,7 @@ type ROSSrvModule <: ROSModule
ROSSrvModule(pkg) = new(pkg, String[], Set{String}())
end

#These two global objects maintain the hierarchy from multiple calls to
#These global objects maintain the hierarchy from multiple calls to
#`@rosimport` and keep the link to the Python objects whenever communication
#goes between RobotOS and rospy.
const _rospy_imports = Dict{String,ROSPackage}()
Expand Down Expand Up @@ -61,9 +61,9 @@ const _ros_builtin_types = Dict{String, Symbol}(
)

#Abstract supertypes of all generated types
abstract MsgT
abstract SrvT
abstract ServiceDefinition
@compat abstract type AbstractMsg end
@compat abstract type AbstractSrv end
@compat abstract type AbstractService end

#Rearranges the expression into a RobotOS._rosimport call. Input comes in as a
#single package qualified expression, or as a tuple expression where the first
Expand Down Expand Up @@ -317,15 +317,15 @@ end

#The imports specific to each module, including dependant packages
function _importexprs(mod::ROSMsgModule)
imports = Expr[Expr(:import, :RobotOS, :MsgT)]
imports = Expr[Expr(:import, :RobotOS, :AbstractMsg)]
othermods = filter(d -> d != _name(mod), mod.deps)
append!(imports, [Expr(:using,Symbol(m),:msg) for m in othermods])
imports
end
function _importexprs(mod::ROSSrvModule)
imports = Expr[
Expr(:import, :RobotOS, :SrvT),
Expr(:import, :RobotOS, :ServiceDefinition),
Expr(:import, :RobotOS, :AbstractSrv),
Expr(:import, :RobotOS, :AbstractService),
Expr(:import, :RobotOS, :_srv_reqtype),
Expr(:import, :RobotOS, :_srv_resptype),
]
Expand Down Expand Up @@ -362,7 +362,7 @@ function buildtype(mod::ROSMsgModule, typename::String)
memtypes = pyobj[:_slot_types]
members = collect(zip(memnames, memtypes))

typecode(fulltypestr, :MsgT, members)
typecode(fulltypestr, :AbstractMsg, members)
end

#All the generated code for a generated service type
Expand All @@ -376,21 +376,21 @@ function buildtype(mod::ROSSrvModule, typename::String)
memtypes = reqobj[:_slot_types]
reqmems = collect(zip(memnames, memtypes))
pyreq = :(RobotOS._rospy_objects[$req_typestr])
reqexprs = typecode(req_typestr, :SrvT, reqmems)
reqexprs = typecode(req_typestr, :AbstractSrv, reqmems)

resp_typestr = _rostypestr(mod, string(typename,"Response"))
respobj = _rospy_objects[resp_typestr]
memnames = respobj[:__slots__]
memtypes = respobj[:_slot_types]
respmems = collect(zip(memnames, memtypes))
pyresp = :(RobotOS._rospy_objects[$resp_typestr])
respexprs = typecode(resp_typestr, :SrvT, respmems)
respexprs = typecode(resp_typestr, :AbstractSrv, respmems)

defsym = Symbol(typename)
reqsym = Symbol(string(typename,"Request"))
respsym = Symbol(string(typename,"Response"))
srvexprs = Expr[
:(immutable $defsym <: ServiceDefinition end),
:(immutable $defsym <: AbstractService end),
:(_typerepr(::Type{$defsym}) = $(_rostypestr(mod,typename))),
:(_srv_reqtype(::Type{$defsym}) = $reqsym),
:(_srv_resptype(::Type{$defsym}) = $respsym),
Expand All @@ -411,8 +411,8 @@ function typecode(rosname::String, super::Symbol, members::Vector)

#generated code should not conflict with julia built-ins
#some messages need renaming
suffix = if super == :MsgT; "Msg"
elseif super == :SrvT; "Srv"
suffix = if super == :AbstractMsg; "Msg"
elseif super == :AbstractSrv; "Srv"
else; "ROS" end
jlsym = Symbol(_jl_safe_name(tname,suffix))

Expand Down
34 changes: 18 additions & 16 deletions src/pubsub.jl
Expand Up @@ -3,38 +3,41 @@ export Publisher, Subscriber, publish

using Compat

type Publisher{MsgType<:MsgT}
type Publisher{MsgType<:AbstractMsg}
o::PyObject

function Publisher(topic::AbstractString; kwargs...)
@debug("Creating <$(string(MsgType))> publisher on topic: '$topic'")
rospycls = _get_rospy_class(MsgType)
return new(__rospy__[:Publisher](ascii(topic), rospycls; kwargs...))
@compat function (::Type{Publisher{MT}}){MT <: AbstractMsg}(topic::AbstractString; kwargs...)
@debug("Creating <$(string(MT))> publisher on topic: '$topic'")
rospycls = _get_rospy_class(MT)
return new{MT}(__rospy__[:Publisher](ascii(topic), rospycls; kwargs...))
end
end
Publisher{MsgType<:MsgT}(topic::AbstractString, ::Type{MsgType}; kwargs...) =
Publisher{MsgType}(ascii(topic); kwargs...)

function publish{MsgType<:MsgT}(p::Publisher{MsgType}, msg::MsgType)
Publisher{MT<:AbstractMsg}(topic::AbstractString, ::Type{MT}; kwargs...) =
Publisher{MT}(ascii(topic); kwargs...)

function publish{MT<:AbstractMsg}(p::Publisher{MT}, msg::MT)
pycall(p.o["publish"], PyAny, convert(PyObject, msg))
end

type Subscriber{MsgType<:MsgT}
type Subscriber{MsgType<:AbstractMsg}
callback
callback_args::Tuple
sub_obj::PyObject
queue::PyObject
async_loop::Task

function Subscriber(topic::AbstractString, cb, cb_args::Tuple=(); kwargs...)
@debug("Creating <$(string(MsgType))> subscriber on topic: '$topic'")
rospycls = _get_rospy_class(MsgType)
@compat function (::Type{Subscriber{MT}}){MT <: AbstractMsg}(
topic::AbstractString, cb, cb_args::Tuple=(); kwargs...
)
@debug("Creating <$(string(MT))> subscriber on topic: '$topic'")
rospycls = _get_rospy_class(MT)

cond = Compat.AsyncCondition()
mqueue = _py_ros_callbacks["MessageQueue"](CB_NOTIFY_PTR, cond.handle)
subobj = __rospy__[:Subscriber](ascii(topic), rospycls, mqueue["storemsg"]; kwargs...)

rosobj = new(cb, cb_args, subobj, mqueue)
rosobj = new{MT}(cb, cb_args, subobj, mqueue)
cbloop = Task(() -> _callback_async_loop(rosobj, cond))
schedule(cbloop)

Expand All @@ -43,7 +46,6 @@ type Subscriber{MsgType<:MsgT}
end
end

function Subscriber{MsgType<:MsgT}(topic, ::Type{MsgType}, cb, cb_args::Tuple=(); kwargs...)
Subscriber{MsgType}(topic, cb, cb_args; kwargs...)
function Subscriber{MT<:AbstractMsg}(topic, ::Type{MT}, cb, cb_args::Tuple=(); kwargs...)
Subscriber{MT}(topic, cb, cb_args; kwargs...)
end

54 changes: 26 additions & 28 deletions src/services.jl
Expand Up @@ -3,44 +3,46 @@ export Service, ServiceProxy, wait_for_service

using Compat

type ServiceProxy{SrvType <: ServiceDefinition}
type ServiceProxy{SrvType <: AbstractService}
o::PyObject

function ServiceProxy(name::AbstractString; kwargs...)
@debug("Creating <$SrvType> service proxy for '$name'")
rospycls = _get_rospy_class(SrvType)
new(__rospy__[:ServiceProxy](ascii(name), rospycls; kwargs...))
@compat function (::Type{ServiceProxy{ST}}){ST <: AbstractService}(
name::AbstractString; kwargs...
)
@debug("Creating <$ST> service proxy for '$name'")
rospycls = _get_rospy_class(ST)
new{ST}(__rospy__[:ServiceProxy](ascii(name), rospycls; kwargs...))
end
end
function ServiceProxy{SrvType<:ServiceDefinition}(
name::AbstractString,
srv::Type{SrvType};
kwargs...
)
ServiceProxy{SrvType}(ascii(name); kwargs...)

function ServiceProxy{ST<:AbstractService}(name::AbstractString, srv::Type{ST}; kwargs...)
ServiceProxy{ST}(ascii(name); kwargs...)
end

@compat function (srv::ServiceProxy{SrvType}){SrvType <: ServiceDefinition}(
req::SrvT
@compat function (srv::ServiceProxy{ST}){ST <: AbstractService}(
req::AbstractSrv
)
if ! isa(req, _srv_reqtype(SrvType))
if ! isa(req, _srv_reqtype(ST))
throw(ArgumentError(
string("Incorrect service request type: ",typeof(req))))
string("Incorrect service request type: ", typeof(req),
", expected: ", _srv_reqtype(ST))))
end
pyresp = pycall(srv.o, PyObject, convert(PyObject, req))
resp = convert(_srv_resptype(SrvType), pyresp)
resp = convert(_srv_resptype(ST), pyresp)
resp
end

type Service{SrvType <: ServiceDefinition}
type Service{SrvType <: AbstractService}
handler
srv_obj::PyObject
cb_interface::PyObject
async_loop::Task

function Service(name::AbstractString, handler; kwargs...)
@debug("Providing <$SrvType> service at '$name'")
rospycls = _get_rospy_class(SrvType)
@compat function (::Type{Service{ST}}){ST <: AbstractService}(
name::AbstractString, handler; kwargs...
)
@debug("Providing <$ST> service at '$name'")
rospycls = _get_rospy_class(ST)

cond = Compat.AsyncCondition()
pysrv = _py_ros_callbacks["ServiceCallback"](CB_NOTIFY_PTR, cond.handle)
Expand All @@ -55,7 +57,7 @@ type Service{SrvType <: ServiceDefinition}
end
end

rosobj = new(handler, srvobj, pysrv)
rosobj = new{ST}(handler, srvobj, pysrv)

cbloop = Task(() -> _callback_async_loop(rosobj, cond))
schedule(cbloop)
Expand All @@ -64,13 +66,9 @@ type Service{SrvType <: ServiceDefinition}
return rosobj
end
end
function Service{SrvType<:ServiceDefinition}(
name::AbstractString,
srv::Type{SrvType},
handler;
kwargs...
)
Service{SrvType}(ascii(name), handler; kwargs...)

function Service{ST<:AbstractService}(name::AbstractString, srv::Type{ST}, handler; kwargs...)
Service{ST}(ascii(name), handler; kwargs...)
end

function wait_for_service(service::AbstractString; kwargs...)
Expand Down
4 changes: 3 additions & 1 deletion src/time.jl
@@ -1,10 +1,12 @@
#All time related types and functions

using Compat

import Base: convert, isless, sleep, +, -, *, ==
export Time, Duration, Rate, to_sec, to_nsec, get_rostime, rossleep

#Time type definitions
abstract TVal
@compat abstract type TVal end

immutable Time <: TVal
secs::Int32
Expand Down
8 changes: 4 additions & 4 deletions test/pubsub.jl
Expand Up @@ -7,7 +7,7 @@ using geometry_msgs.msg
const Nmsgs = 10
const rate = 20. #Hz
const msgs = PoseStamped[]
const refs = Array(Vector3, Nmsgs)
const refs = Array{Vector3}(Nmsgs)
const t0 = to_nsec(get_rostime())

for i=1:Nmsgs
Expand Down Expand Up @@ -50,8 +50,8 @@ println("Received ",length(msgs)," / ",Nmsgs)

@test length(msgs) == Nmsgs
for i=1:Nmsgs
@test_approx_eq msgs[i].pose.position.x refs[i].x
@test_approx_eq msgs[i].pose.position.y refs[i].y
@test_approx_eq msgs[i].pose.position.z refs[i].z
@test msgs[i].pose.position.x refs[i].x
@test msgs[i].pose.position.y refs[i].y
@test msgs[i].pose.position.z refs[i].z
end
empty!(msgs)
6 changes: 3 additions & 3 deletions test/services.jl
Expand Up @@ -13,8 +13,8 @@ const Nposes = 5

function srv_cb(req::GetPlanRequest)
println("GetPlan call received")
@test_approx_eq(req.start.pose.position.x, 1.0)
@test_approx_eq(req.goal.pose.position.y, 1.0)
@test req.start.pose.position.x 1.0
@test req.goal.pose.position.y 1.0

resp = GetPlanResponse()
for i=1:Nposes
Expand Down Expand Up @@ -45,7 +45,7 @@ if flag[1]
rossleep(Duration(2.0))
@test length(msgs) == Nposes
for i=1:Nposes
@test_approx_eq(msgs[i].pose.position.z, i)
@test msgs[i].pose.position.z i
end
end
empty!(msgs)
Expand Down

0 comments on commit c7ecdc9

Please sign in to comment.