Skip to content

Commit

Permalink
Check if appropriate bson module is installed or not just after init_…
Browse files Browse the repository at this point in the history
…node. (RobotWebTools#198)

Check whether mongodb oriented bson is installed or not just after init_node,
and if appropriate bson is not installed, shutdown node with error message.

See: RobotWebTools#198
  • Loading branch information
ledmonster committed Mar 10, 2017
1 parent 632363d commit 729be6c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
16 changes: 16 additions & 0 deletions rosbridge_library/src/rosbridge_library/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,19 @@
import simplejson as json
except ImportError:
import json


def appropriate_bson_installed():
""" Check whether appropriate bson module installed
pymongo oriented bson module should be installed. See following issue for
detail.
* https://github.com/RobotWebTools/rosbridge_suite/issues/198
"""
import bson
try:
bson.BSON
except AttributeError:
return False
return True
8 changes: 8 additions & 0 deletions rosbridge_server/scripts/rosbridge_tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from rosbridge_library.capabilities.advertise_service import AdvertiseService
from rosbridge_library.capabilities.unadvertise_service import UnadvertiseService
from rosbridge_library.capabilities.call_service import CallService
from rosbridge_library.util import appropriate_bson_installed

from functools import partial
from signal import signal, SIGINT, SIG_DFL
Expand Down Expand Up @@ -36,6 +37,13 @@ def shutdown_hook(server):
init_node("rosbridge_tcp")
signal(SIGINT, SIG_DFL)

# Check whether appropriate bson module is installed or not
# See: https://github.com/RobotWebTools/rosbridge_suite/issues/198
if not appropriate_bson_installed():
rospy.logerr("BSON installation does not support all necessary features. "
"Please use the MongoDB BSON implementation.")
rospy.signal_shutdown("shutdown")

"""
Parameter handling:
- try to get parameter from parameter server (..define those via launch-file)
Expand Down
8 changes: 8 additions & 0 deletions rosbridge_server/scripts/rosbridge_udp.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from rosbridge_library.capabilities.advertise_service import AdvertiseService
from rosbridge_library.capabilities.unadvertise_service import UnadvertiseService
from rosbridge_library.capabilities.call_service import CallService
from rosbridge_library.util import appropriate_bson_installed

def shutdown_hook():
reactor.stop()
Expand All @@ -52,6 +53,13 @@ def shutdown_hook():
rospy.init_node("rosbridge_websocket")
rospy.on_shutdown(shutdown_hook) # register shutdown hook to stop the server

# Check whether appropriate bson module is installed or not
# See: https://github.com/RobotWebTools/rosbridge_suite/issues/198
if not appropriate_bson_installed():
rospy.logerr("BSON installation does not support all necessary features. "
"Please use the MongoDB BSON implementation.")
rospy.signal_shutdown("shutdown")

##################################################
# Parameter handling #
##################################################
Expand Down
8 changes: 8 additions & 0 deletions rosbridge_server/scripts/rosbridge_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
from rosbridge_library.capabilities.advertise_service import AdvertiseService
from rosbridge_library.capabilities.unadvertise_service import UnadvertiseService
from rosbridge_library.capabilities.call_service import CallService
from rosbridge_library.util import appropriate_bson_installed

def shutdown_hook():
IOLoop.instance().stop()
Expand All @@ -56,6 +57,13 @@ def shutdown_hook():
rospy.init_node("rosbridge_websocket")
rospy.on_shutdown(shutdown_hook) # register shutdown hook to stop the server

# Check whether appropriate bson module is installed or not
# See: https://github.com/RobotWebTools/rosbridge_suite/issues/198
if not appropriate_bson_installed():
rospy.logerr("BSON installation does not support all necessary features. "
"Please use the MongoDB BSON implementation.")
rospy.signal_shutdown("shutdown")

##################################################
# Parameter handling #
##################################################
Expand Down

0 comments on commit 729be6c

Please sign in to comment.