Skip to content

Commit

Permalink
try again
Browse files Browse the repository at this point in the history
  • Loading branch information
jdlangs committed Feb 27, 2017
1 parent 76888d3 commit bee7eab
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 31 deletions.
20 changes: 10 additions & 10 deletions src/pubsub.jl
Expand Up @@ -6,17 +6,17 @@ using Compat
type Publisher{MsgType<:AbstractMsg}
o::PyObject

function Publisher{MT}(topic::AbstractString; kwargs...) where MT <: AbstractMsg
@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(__rospy__[:Publisher](ascii(topic), rospycls; kwargs...))
return new{MT}(__rospy__[:Publisher](ascii(topic), rospycls; kwargs...))
end
end

Publisher{MsgType<:AbstractMsg}(topic::AbstractString, ::Type{MsgType}; kwargs...) =
Publisher{MsgType}(ascii(topic); kwargs...)
Publisher{MT<:AbstractMsg}(topic::AbstractString, ::Type{MT}; kwargs...) =
Publisher{MT}(ascii(topic); kwargs...)

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

Expand All @@ -27,17 +27,17 @@ type Subscriber{MsgType<:AbstractMsg}
queue::PyObject
async_loop::Task

function Subscriber{MT}(
@compat function (::Type{Subscriber{MT}}){MT <: AbstractMsg}(
topic::AbstractString, cb, cb_args::Tuple=(); kwargs...
) where MT <: AbstractMsg
)
@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 @@ -46,6 +46,6 @@ type Subscriber{MsgType<:AbstractMsg}
end
end

function Subscriber{MsgType<:AbstractMsg}(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
39 changes: 18 additions & 21 deletions src/services.jl
Expand Up @@ -6,30 +6,29 @@ using Compat
type ServiceProxy{SrvType <: AbstractService}
o::PyObject

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

function ServiceProxy{SrvType<:AbstractService}(
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 <: AbstractService}(
@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

Expand All @@ -39,7 +38,9 @@ type Service{SrvType <: AbstractService}
cb_interface::PyObject
async_loop::Task

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

Expand All @@ -56,7 +57,7 @@ type Service{SrvType <: AbstractService}
end
end

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

cbloop = Task(() -> _callback_async_loop(rosobj, cond))
schedule(cbloop)
Expand All @@ -65,13 +66,9 @@ type Service{SrvType <: AbstractService}
return rosobj
end
end
function Service{SrvType<:AbstractService}(
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

0 comments on commit bee7eab

Please sign in to comment.