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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CeTI
ROS
ROS Java Packages
Rosjava Core Gradle
Commits
3e403cb0
Commit
3e403cb0
authored
9 years ago
by
Ernesto Corbellini
Committed by
Ernesto Corbellini
9 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Added a new node class to wrap the loading and execution of a native code ROS node.
parent
389b657e
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/src/main/java/org/ros/node/NativeNodeMain.java
+103
-0
103 additions, 0 deletions
rosjava/src/main/java/org/ros/node/NativeNodeMain.java
with
103 additions
and
0 deletions
rosjava/src/main/java/org/ros/node/NativeNodeMain.java
0 → 100644
+
103
−
0
View file @
3e403cb0
package
org.ros.node
;
import
org.ros.node.AbstractNodeMain
;
import
org.ros.node.ConnectedNode
;
import
org.ros.node.Node
;
import
org.ros.namespace.GraphName
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
java.util.List
;
import
java.util.Map
;
/**
* A java wrapper to load and run a native-code ROS node.
*
* Note: there are no actual native methods declared in this class. We only define an interface. The native methods should be declared in the child class.
*
* @author ecorbellini@creativa77.com.ar (Ernesto Corbellini)
*/
public
abstract
class
NativeNodeMain
extends
AbstractNodeMain
{
private
Log
log
=
LogFactory
.
getLog
(
NativeNodeMain
.
class
);
private
String
libName
;
private
String
masterUri
=
null
;
private
String
hostName
=
null
;
private
String
nodeName
=
null
;
private
String
[]
remappingArguments
;
private
boolean
shuttingDown
=
false
;
/**
* @param libName
* The name of the library to load.
*
* @param remappings
* A string array with ROS argument remapping pairs in each element.
**/
public
NativeNodeMain
(
String
libName
,
String
[]
remappings
)
{
this
.
libName
=
libName
;
// if no remapping is needed, create an empty array
if
(
remappings
==
null
)
{
remappingArguments
=
new
String
[
0
];
}
log
.
info
(
"Trying to load native library '"
+
libName
+
"'..."
);
try
{
System
.
loadLibrary
(
libName
);
}
catch
(
SecurityException
e
)
{
log
.
info
(
"Error loading library! SecurityException"
);
}
catch
(
UnsatisfiedLinkError
e
)
{
log
.
info
(
"Error loading library! UnsatisfiedLinkError"
);
}
catch
(
NullPointerException
e
)
{
log
.
info
(
"Error loading library! NullPointerException"
);
}
}
/**
* @param libName
* The name of the library to load.
**/
public
NativeNodeMain
(
String
libName
)
{
this
(
libName
,
null
);
}
// These methods define the execution model interface for this node.
protected
abstract
void
execute
(
String
rosMasterUri
,
String
rosHostName
,
String
rosNodeName
,
String
[]
remappingArguments
);
protected
abstract
void
shutdown
();
@Override
public
void
onStart
(
final
ConnectedNode
connectedNode
)
{
// retain important ROS info
masterUri
=
connectedNode
.
getMasterUri
().
toString
();
hostName
=
connectedNode
.
getUri
().
getHost
();
nodeName
=
this
.
libName
;
// create a new thread to execute the native code.
new
Thread
()
{
@Override
public
void
run
()
{
execute
(
masterUri
,
hostName
,
nodeName
,
remappingArguments
);
// node execution has finished so we propagate the shutdown sequence only if we aren't already shutting down for other reasons
if
(!
shuttingDown
)
{
connectedNode
.
shutdown
();
}
}
}.
start
();
}
@Override
public
void
onShutdown
(
Node
node
)
{
shuttingDown
=
true
;
shutdown
();
}
}
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