Skip to content

Commit 079dacd

Browse files
committed
Switch String to AbstractString
1 parent 1bacbe5 commit 079dacd

File tree

4 files changed

+58
-54
lines changed

4 files changed

+58
-54
lines changed

src/gentypes.jl

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type ROSPackage
1111
name::ASCIIString
1212
msg::ROSModule
1313
srv::ROSModule
14-
function ROSPackage(pkgname::String)
14+
function ROSPackage(pkgname::ASCIIString)
1515
pkg = new(pkgname)
1616
pkg.msg = ROSMsgModule(pkg)
1717
pkg.srv = ROSSrvModule(pkg)
@@ -110,7 +110,7 @@ function _pkgtype_import(input::Expr)
110110
return ps,msb,ts
111111
end
112112
#Import a set of types from a single package
113-
function _usepkg(package::String, ismsg::Bool, names::String...)
113+
function _usepkg(package::ASCIIString, ismsg::Bool, names::ASCIIString...)
114114
global _rospy_imports
115115
if ! haskey(_rospy_imports, package)
116116
@debug("Creating new package: ",package,".", ismsg ? "msg" : "srv")
@@ -148,7 +148,7 @@ cleartypes() = error("cleartypes() renamed to rostypereset()")
148148

149149
#Populate the module with a new message type. Import and add dependencies first
150150
#so they will appear first in the generated code.
151-
function addtype!(mod::ROSMsgModule, typ::String)
151+
function addtype!(mod::ROSMsgModule, typ::ASCIIString)
152152
global _rospy_objects
153153
if !(typ in mod.members)
154154
@debug("Message type import: ", _fullname(mod), ".", typ)
@@ -164,7 +164,7 @@ end
164164

165165
#Populate the module with a new service type. Import and add dependencies
166166
#first.
167-
function addtype!(mod::ROSSrvModule, typ::String)
167+
function addtype!(mod::ROSSrvModule, typ::ASCIIString)
168168
global _rospy_objects
169169
if !(typ in mod.members)
170170
@debug("Service type import: ", _fullname(mod), ".", typ)
@@ -190,7 +190,7 @@ function addtype!(mod::ROSSrvModule, typ::String)
190190
end
191191

192192
#Return the python module and python object for a particular type
193-
function _pyvars(modname::String, typ::String)
193+
function _pyvars(modname::ASCIIString, typ::ASCIIString)
194194
pymod = _import_rospy_pkg(modname)
195195
pyobj =
196196
try pymod[typ]
@@ -234,7 +234,7 @@ function _importdeps!(mod::ROSModule, deps::Vector)
234234
end
235235

236236
#Bring in the python modules as needed
237-
function _import_rospy_pkg(package::String)
237+
function _import_rospy_pkg(package::ASCIIString)
238238
global _rospy_modules
239239
if ! haskey(_rospy_modules, package)
240240
@debug("Importing python package: ", package)
@@ -352,7 +352,7 @@ function _exportexpr(mod::ROSSrvModule)
352352
end
353353

354354
#All the generated code for a generated message type
355-
function buildtype(mod::ROSMsgModule, typename::String)
355+
function buildtype(mod::ROSMsgModule, typename::ASCIIString)
356356
global _rospy_objects
357357
fulltypestr = _rostypestr(mod, typename)
358358
pyobj = _rospy_objects[fulltypestr]
@@ -370,7 +370,7 @@ end
370370

371371
#All the generated code for a generated service type
372372
#Will create 3 different composite types.
373-
function buildtype(mod::ROSSrvModule, typename::String)
373+
function buildtype(mod::ROSSrvModule, typename::ASCIIString)
374374
global _rospy_objects
375375

376376
req_typestr = _rostypestr(mod, string(typename,"Request"))
@@ -407,7 +407,7 @@ end
407407
# (2) Default outer constructer with no arguments
408408
# (3) convert(PyObject, ...)
409409
# (4) convert(..., o::PyObject)
410-
function typecode(rosname::String, super::Symbol, members::Vector)
410+
function typecode(rosname::ASCIIString, super::Symbol, members::Vector)
411411
tname = _splittypestr(rosname)[2]
412412
@debug("Type: ", tname)
413413
tsym = symbol(tname)
@@ -522,11 +522,11 @@ end
522522

523523
#Build a String => Iterable{String} object from the individual package
524524
#dependencies.
525-
function _collectdeps{S<:String}(pkgs::Dict{S, ROSPackage})
526-
deps = Dict{ASCIIString, Set{ASCIIString}}()
525+
function _collectdeps{S<:AbstractString}(pkgs::Dict{S, ROSPackage})
526+
deps = Dict{S, Set{S}}()
527527
for pname in keys(pkgs)
528528
if ! haskey(deps, pname)
529-
deps[pname] = Set{ASCIIString}()
529+
deps[pname] = Set{S}()
530530
end
531531
union!(deps[pname], pkgs[pname].msg.deps)
532532
union!(deps[pname], pkgs[pname].srv.deps)
@@ -557,36 +557,36 @@ function _order(d::Dict)
557557
tlist
558558
end
559559

560-
_rostypestr(mod::ROSModule, name::String) = string(_name(mod),"/",name)
561-
function _splittypestr(typestr::String)
560+
_rostypestr(mod::ROSModule, name::ASCIIString) = string(_name(mod),"/",name)
561+
function _splittypestr(typestr::ASCIIString)
562562
if ! _isrostype(typestr)
563563
error(string("Invalid message type '$typestr', ",
564564
"use 'package_name/type_name'"))
565565
end
566-
rospkg, typ = split(typestr, '/')
566+
rospkg, typ = map(ascii, split(typestr, '/'))
567567
rospkg, typ
568568
end
569569
#Valid ROS type string is all word chars split by a single forward slash, with
570570
#optional square brackets for array types
571-
_isrostype(s::String) = ismatch(r"^\w+/\w+(?:\[\d*\])?$", s)
571+
_isrostype(s::ASCIIString) = ismatch(r"^\w+/\w+(?:\[\d*\])?$", s)
572572

573573
#Sanitize a string by checking for and removing brackets if they are present
574574
#Return the sanitized type and the number inside the brackets if it is a fixed
575575
#size type. Returns 0 if variable size (no number), -1 if no brackets
576-
function _check_array_type(typ::String)
576+
function _check_array_type(typ::ASCIIString)
577577
arraylen = -1
578578
m = match(r"^([\w/]+)\[(\d*)\]$", typ)
579579
if m != nothing
580580
btype = m.captures[1]
581581
if isempty(m.captures[2])
582582
arraylen = 0
583583
else
584-
arraylen = int(m.captures[2])
584+
arraylen = parse(Int, m.captures[2])
585585
end
586586
else
587587
btype = typ
588588
end
589-
btype, arraylen
589+
ascii(btype), arraylen
590590
end
591591

592592
#Get the rospy PyObject corresponding to a generated type
@@ -607,7 +607,7 @@ end
607607

608608
#Check if the type name conflicts with a Julia builtin. Currently this is only
609609
#some of the messages from the std_msgs.msg package
610-
_nameconflicts(typename::String) = isdefined(Base, symbol(typename))
610+
_nameconflicts(typename::ASCIIString) = isdefined(Base, symbol(typename))
611611

612612
#Get a default value for any builtin ROS type
613613
_typedefault{T<:Real}(::Type{T}) = zero(T)

src/pubsub.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ export Publisher, Subscriber, publish
44
type Publisher{MsgType<:MsgT}
55
o::PyObject
66

7-
function Publisher(topic::String; kwargs...)
7+
function Publisher(topic::AbstractString; kwargs...)
88
@debug("Creating <$(string(MsgType))> publisher on topic: '$topic'")
99
rospycls = _get_rospy_class(MsgType)
10-
return new(__rospy__[:Publisher](topic, rospycls; kwargs...))
10+
return new(__rospy__[:Publisher](ascii(topic), rospycls; kwargs...))
1111
end
1212
end
13-
Publisher{MsgType<:MsgT}(topic::String, ::Type{MsgType}; kwargs...) =
14-
Publisher{MsgType}(topic; kwargs...)
13+
Publisher{MsgType<:MsgT}(topic::AbstractString, ::Type{MsgType}; kwargs...) =
14+
Publisher{MsgType}(ascii(topic); kwargs...)
1515

1616
function publish{MsgType<:MsgT}(p::Publisher{MsgType}, msg::MsgType)
1717
pycall(p.o["publish"], PyAny, convert(PyObject, msg))
@@ -22,21 +22,21 @@ type Subscriber{MsgType<:MsgT}
2222
callback
2323

2424
function Subscriber(
25-
topic::String, cb, cb_args::Tuple=(); kwargs...
25+
topic::AbstractString, cb, cb_args::Tuple=(); kwargs...
2626
)
2727
@debug("Creating <$(string(MsgType))> subscriber on topic: '$topic'")
2828
rospycls = _get_rospy_class(MsgType)
29-
jl_callback(msg::PyObject) = cb(convert(MsgType, msg), cb_args...)
29+
jl_cb(msg::PyObject) = cb(convert(MsgType, msg), cb_args...)
3030
return new(
31-
__rospy__[:Subscriber](topic, rospycls, jl_callback; kwargs...),
32-
jl_callback
31+
__rospy__[:Subscriber](ascii(topic), rospycls, jl_cb; kwargs...),
32+
jl_cb
3333
)
3434
end
3535
end
3636
Subscriber{MsgType<:MsgT}(
37-
topic::String,
37+
topic::AbstractString,
3838
::Type{MsgType},
3939
cb,
4040
cb_args::Tuple=();
4141
kwargs...
42-
) = Subscriber{MsgType}(topic, cb, cb_args; kwargs...)
42+
) = Subscriber{MsgType}(ascii(topic), cb, cb_args; kwargs...)

src/rospy.jl

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,39 @@ export init_node, is_shutdown, spin,
44
logdebug, loginfo, logwarn, logerr, logfatal
55

66
#General rospy functions
7-
init_node(name::String; args...) = __rospy__[:init_node](name; args...)
7+
init_node(name::AbstractString; args...) =
8+
__rospy__[:init_node](ascii(name); args...)
89
spin() = __rospy__[:spin]()
910
is_shutdown() = __rospy__[:is_shutdown]()
1011
get_published_topics() = __rospy__[:get_published_topics]()
1112
get_ros_root() = __rospy__[:get_ros_root]()
1213

1314
#Parameter server API
14-
get_param(param_name::String, def=nothing) = begin
15+
function get_param(param_name::AbstractString, def=nothing)
1516
try
1617
if def == nothing
17-
__rospy__[:get_param](param_name)
18+
__rospy__[:get_param](ascii(param_name))
1819
else
19-
__rospy__[:get_param](param_name, def)
20+
__rospy__[:get_param](ascii(param_name), def)
2021
end
2122
catch ex
2223
throw(KeyError(pycall(pybuiltin("str"), PyAny, ex.val)[2:end-1]))
2324
end
2425
end
25-
set_param(param_name::String, val) = __rospy__[:set_param](param_name, val)
26-
has_param(param_name::String) = __rospy__[:has_param](param_name)
27-
delete_param(param_name::String) = begin
26+
set_param(param_name::AbstractString, val) =
27+
__rospy__[:set_param](ascii(param_name), val)
28+
has_param(param_name::AbstractString) =
29+
__rospy__[:has_param](ascii(param_name))
30+
function delete_param(param_name::AbstractString)
2831
try
29-
__rospy__[:delete_param](param_name)
32+
__rospy__[:delete_param](ascii(param_name))
3033
catch ex
3134
throw(KeyError(pycall(pybuiltin("str"), PyAny, ex.val)[2:end-1]))
3235
end
3336
end
3437
#Doesn't work for some reason
35-
#rospy_search_param(param_name::String) = __rospy__[:rospy_search_param](param_name)
38+
#rospy_search_param(param_name::AbstractString) =
39+
# __rospy__[:rospy_search_param](ascii(param_name))
3640
get_param_names() = __rospy__[:get_param_names]()
3741

3842
#Logging API

src/services.jl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ end
99

1010
type ServiceProxy{SrvType <: ServiceDefinition}
1111
o::PyObject
12-
13-
function ServiceProxy(name::String; kwargs...)
12+
13+
function ServiceProxy(name::AbstractString; kwargs...)
1414
@debug("Creating <$SrvType> service proxy for '$name'")
1515
rospycls = _get_rospy_class(SrvType)
16-
new(__rospy__[:ServiceProxy](name, rospycls; kwargs...))
16+
new(__rospy__[:ServiceProxy](ascii(name), rospycls; kwargs...))
1717
end
1818
end
1919
function ServiceProxy{SrvType<:ServiceDefinition}(
20-
name::String,
21-
srv::Type{SrvType};
20+
name::AbstractString,
21+
srv::Type{SrvType};
2222
kwargs...
2323
)
24-
ServiceProxy{SrvType}(name; kwargs...)
24+
ServiceProxy{SrvType}(ascii(name); kwargs...)
2525
end
2626

2727
function call{SrvType <: ServiceDefinition}(
28-
srv::ServiceProxy{SrvType},
28+
srv::ServiceProxy{SrvType},
2929
req::SrvT
3030
)
3131
if ! isa(req, _srv_reqtype(SrvType))
@@ -41,15 +41,15 @@ type Service{SrvType <: ServiceDefinition}
4141
o::PyObject
4242
jl_handler
4343

44-
function Service(name::String, handler; kwargs...)
44+
function Service(name::AbstractString, handler; kwargs...)
4545
@debug("Providing <$SrvType> service at '$name'")
4646
rospycls = _get_rospy_class(SrvType)
4747
ReqType = _srv_reqtype(SrvType)
48-
jl_handler(req::PyObject) =
48+
jl_hndl(req::PyObject) =
4949
convert(PyObject, handler(convert(ReqType,req)))
5050
try
51-
new(__rospy__[:Service](name, rospycls, jl_handler; kwargs...),
52-
jl_handler
51+
new(__rospy__[:Service](ascii(name), rospycls, jl_hndl; kwargs...),
52+
jl_hndl
5353
)
5454
catch err
5555
if isa(err, PyCall.PyError)
@@ -61,17 +61,17 @@ type Service{SrvType <: ServiceDefinition}
6161
end
6262
end
6363
function Service{SrvType<:ServiceDefinition}(
64-
name::String,
64+
name::AbstractString,
6565
srv::Type{SrvType},
6666
handler;
6767
kwargs...
6868
)
69-
Service{SrvType}(name, handler; kwargs...)
69+
Service{SrvType}(ascii(name), handler; kwargs...)
7070
end
7171

72-
function wait_for_service(service::String; kwargs...)
72+
function wait_for_service(service::AbstractString; kwargs...)
7373
try
74-
__rospy__[:wait_for_service](service; kwargs...)
74+
__rospy__[:wait_for_service](ascii(service); kwargs...)
7575
catch ex
7676
error("Timeout exceeded waiting for service '$service'")
7777
end

0 commit comments

Comments
 (0)