Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Rosjava Core Gradle
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CeTI
ROS
ROS Java Packages
Rosjava Core Gradle
Commits
d6760a90
Commit
d6760a90
authored
6 years ago
by
Juan Ignacio Ubeira
Browse files
Options
Downloads
Patches
Plain Diff
Improved error checking for ParameterLoaderNode.
parent
f2134b28
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
rosjava_helpers/src/main/java/org/ros/helpers/ParameterLoaderNode.java
+31
-28
31 additions, 28 deletions
...rs/src/main/java/org/ros/helpers/ParameterLoaderNode.java
with
31 additions
and
28 deletions
rosjava_helpers/src/main/java/org/ros/helpers/ParameterLoaderNode.java
+
31
−
28
View file @
d6760a90
...
...
@@ -16,6 +16,8 @@
package
org.ros.helpers
;
import
com.google.common.base.Preconditions
;
import
org.apache.commons.logging.Log
;
import
org.ros.namespace.GraphName
;
import
org.ros.node.AbstractNodeMain
;
...
...
@@ -47,36 +49,39 @@ public class ParameterLoaderNode extends AbstractNodeMain {
* Default constructor
* @param resources Array of resources with their respective namespace to load.
*/
public
ParameterLoaderNode
(
ArrayList
<
Resource
>
resources
)
{
public
ParameterLoaderNode
(
List
<
Resource
>
resources
)
{
Preconditions
.
checkNotNull
(
resources
);
for
(
Resource
r
:
resources
)
{
Preconditions
.
checkNotNull
(
r
.
inputStream
);
addSingleYmlInput
(
r
.
inputStream
,
r
.
namespace
==
null
?
""
:
r
.
namespace
);
}
}
private
void
addSingleYmlInput
(
InputStream
ymlInputStream
,
String
namespace
)
{
this
.
params
.
add
(
new
LoadedResource
((
new
Yaml
()).
load
(
ymlInputStream
),
namespace
));
Object
loadedYaml
=
new
Yaml
().
load
(
ymlInputStream
);
if
(
loadedYaml
!=
null
&&
loadedYaml
instanceof
Map
<?,
?>)
{
this
.
params
.
add
(
new
LoadedResource
(
Map
.
class
.
cast
(
loadedYaml
),
namespace
));
}
}
@SuppressWarnings
(
"unchecked"
)
private
void
addParams
(
ParameterTree
parameterTree
,
String
namespace
,
Map
<
String
,
Object
>
params
)
{
for
(
Map
.
Entry
<
String
,
Object
>
e
:
params
.
entrySet
())
{
String
fullKeyName
=
namespace
+
"/"
+
e
.
getKey
();
private
void
addParams
(
ParameterTree
parameterTree
,
String
namespace
,
Map
<?,
?>
params
)
{
for
(
Map
.
Entry
<?,
?>
e
:
params
.
entrySet
())
{
String
fullKeyName
=
namespace
+
"/"
+
e
.
getKey
().
toString
();
if
(
log
!=
null
)
{
log
.
info
(
"Loading parameter "
+
fullKeyName
+
" \nValue = "
+
e
.
getValue
());
log
.
debug
(
"Loading parameter "
+
fullKeyName
+
" \nValue = "
+
e
.
getValue
());
}
if
(
e
.
getValue
()
instanceof
String
)
{
parameterTree
.
set
(
fullKeyName
,
(
String
)
e
.
getValue
());
parameterTree
.
set
(
fullKeyName
,
String
.
class
.
cast
(
e
.
getValue
())
)
;
}
else
if
(
e
.
getValue
()
instanceof
Integer
)
{
parameterTree
.
set
(
fullKeyName
,
(
Integer
)
e
.
getValue
());
parameterTree
.
set
(
fullKeyName
,
Integer
.
class
.
cast
(
e
.
getValue
())
)
;
}
else
if
(
e
.
getValue
()
instanceof
Double
)
{
parameterTree
.
set
(
fullKeyName
,
(
Double
)
e
.
getValue
());
parameterTree
.
set
(
fullKeyName
,
Double
.
class
.
cast
(
e
.
getValue
())
)
;
}
else
if
(
e
.
getValue
()
instanceof
Map
)
{
parameterTree
.
set
(
fullKeyName
,
(
Map
)
e
.
getValue
());
parameterTree
.
set
(
fullKeyName
,
Map
.
class
.
cast
(
e
.
getValue
())
)
;
}
else
if
(
e
.
getValue
()
instanceof
Boolean
)
{
parameterTree
.
set
(
fullKeyName
,
(
Boolean
)
e
.
getValue
());
parameterTree
.
set
(
fullKeyName
,
Boolean
.
class
.
cast
(
e
.
getValue
())
)
;
}
else
if
(
e
.
getValue
()
instanceof
List
)
{
parameterTree
.
set
(
fullKeyName
,
(
List
)
e
.
getValue
());
parameterTree
.
set
(
fullKeyName
,
List
.
class
.
cast
(
e
.
getValue
())
)
;
}
else
if
(
log
!=
null
)
{
log
.
debug
(
"I don't know what type parameter "
+
fullKeyName
+
" is. Value = "
+
e
.
getValue
());
log
.
debug
(
"Class name is: "
+
e
.
getValue
().
getClass
().
getName
());
...
...
@@ -95,7 +100,6 @@ public class ParameterLoaderNode extends AbstractNodeMain {
@Override
public
void
onStart
(
ConnectedNode
connectedNode
)
{
if
(
params
!=
null
)
{
ParameterTree
parameterTree
=
connectedNode
.
getParameterTree
();
log
=
connectedNode
.
getLog
();
...
...
@@ -107,7 +111,6 @@ public class ParameterLoaderNode extends AbstractNodeMain {
connectedNode
.
shutdown
();
}
}
/**
* Resource to load to Parameter Server, consisting of an InputStream and its corresponding namespace.
...
...
@@ -128,11 +131,11 @@ public class ParameterLoaderNode extends AbstractNodeMain {
* keep the code simple.
*/
private
class
LoadedResource
{
p
ublic
Map
<
String
,
Object
>
resource
;
p
ublic
String
namespace
;
p
rivate
Map
<?,
?
>
resource
;
p
rivate
String
namespace
;
LoadedResource
(
Object
resource
,
String
namespace
)
{
this
.
resource
=
(
Map
<
String
,
Object
>)
resource
;
LoadedResource
(
Map
resource
,
String
namespace
)
{
this
.
resource
=
resource
;
this
.
namespace
=
namespace
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment