Skip to content

Commit

Permalink
improved start of the crossbar server and log output
Browse files Browse the repository at this point in the history
  • Loading branch information
atiderko committed Aug 22, 2023
1 parent 5dd24b5 commit 6d68b17
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class CustomParticipantListener : public rclcpp::Node,
// only consider known GUIDs
if (itp != discoveredParticipants_.end())
{
RCLCPP_INFO(get_logger(), "onParticipantDiscovery: remove participant %s:", to_string(info.info.m_guid).c_str());
RCLCPP_INFO(get_logger(), "onParticipantDiscovery: remove participant %s:", to_string(info.info.m_guid).c_str());
discoveredParticipants_.erase(itp);
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ def default(self, obj):

class CrossbarBaseSession(ApplicationSession):

def __init__(self, loop: asyncio.AbstractEventLoop, realm: str = 'ros', port: int = 11911, test_env=False) -> None:
CROSSBAR_SERVER_STARTED = False

def __init__(self, loop: asyncio.AbstractEventLoop, realm: str = 'ros', port: int = 11911, *, test_env=False) -> None:
self.port = port
self.crossbar_loop = loop
self._on_shutdown = False
Expand Down Expand Up @@ -95,10 +97,10 @@ async def subcribe_async(self, topic: str, handler: Callable):
try:
await self.subscribe(handler, topic)
Log.info(
f"{self.__class__.__name__}: subscribed to crossbar topic 'ros.nodes.abort'")
f"{self.__class__.__name__}: subscribed to crossbar topic '{topic}'")
except Exception as e:
Log.warn(
f"{self.__class__.__name__}: could not subscribe to 'ros.nodes.abort': {0}".format(e))
f"{self.__class__.__name__}: could not subscribe to '{topic}': {0}".format(e))

'''
Publishes message to given topic without throw an exception on connection problems.
Expand Down Expand Up @@ -150,11 +152,12 @@ def onLeave(self, details):
@coroutine
def onJoin(self, details):
res = yield from self.register(self)
Log.info(
f"{self.__class__.__name__}: {len(self._registrations)} crossbar procedures registered!")
Log.info(f"{self.__class__.__name__}: list of registered uri's:")
for _session_id, reg in self._registrations.items():
Log.info(f"{self.__class__.__name__}: {reg.procedure}")
if self._registrations:
Log.info(
f"{self.__class__.__name__}: {len(self._registrations)} crossbar procedures registered!")
Log.info(f"{self.__class__.__name__}: list of registered uri's:")
for _session_id, reg in self._registrations.items():
Log.info(f"{self.__class__.__name__}: {reg.procedure}")
self.crossbar_registered = True

async def crossbar_connect_async(self):
Expand All @@ -168,16 +171,18 @@ async def crossbar_connect_async(self):
self.crossbar_connected = True
self.crossbar_connecting = False
except Exception as err:
Log.debug(f"{err}")
Log.debug(f"{self.__class__.__name__}: {err}")

# try to start the crossbar server
try:
config_path = crossbar_start_server(self.port)
Log.info(
f"start crossbar server @ {self.uri} realm: {self.config.realm}, config: {config_path}")
except:
import traceback
Log.debug(traceback.format_exc())
if not CrossbarBaseSession.CROSSBAR_SERVER_STARTED:
CrossbarBaseSession.CROSSBAR_SERVER_STARTED = True
try:
config_path = crossbar_start_server(self.port)
Log.info(
f"{self.__class__.__name__}: start crossbar server @ {self.uri} realm: {self.config.realm}, config: {config_path}")
except:
import traceback
Log.debug(f"{self.__class__.__name__}: {traceback.format_exc()}")

self.crossbar_connecting = False
self.crossbar_connected = False
Expand Down
20 changes: 13 additions & 7 deletions fkie_node_manager_daemon/fkie_node_manager_daemon/file_servicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,17 @@ def stop(self):

@wamp.register('ros.packages.get_list')
def getPackageList(self, clear_cache: bool = False) -> List[RosPackage]:
Log.info('Request to [ros.packages.get_list]')
Log.info(
f"{self.__class__.__name__}: Request to [ros.packages.get_list]")
clear_cache = False
if clear_cache:
try:
from roslaunch import substitution_args
import rospkg
substitution_args._rospack = rospkg.RosPack()
except Exception as err:
Log.warn(f"Cannot reset package cache: {err}")
Log.warn(
f"{self.__class__.__name__}: Cannot reset package cache: {err}")
package_list: List[RosPackage] = []
# fill the input fields
ret = ros_pkg.get_packages(None)
Expand All @@ -75,7 +77,8 @@ def getPackageList(self, clear_cache: bool = False) -> List[RosPackage]:

@wamp.register('ros.path.get_log_paths')
def getLogPaths(self, nodes: List[str]) -> List[LogPathItem]:
Log.info('Request to [ros.path.get_log_paths] for %s' % nodes)
Log.info(
f"{self.__class__.__name__}: Request to [ros.path.get_log_paths] for {nodes}")
result = []
for node in nodes:
namespace = None
Expand All @@ -100,7 +103,8 @@ def getLogPaths(self, nodes: List[str]) -> List[LogPathItem]:

@wamp.register('ros.path.get_list')
def getPathList(self, inputPath: str) -> List[PathItem]:
Log.info('Request to [ros.path.get_list] for %s' % inputPath)
Log.info(
f"{self.__class__.__name__}: Request to [ros.path.get_list] for {inputPath}")
path_list: List[PathItem] = []
# list the path
dirlist = os.listdir(inputPath)
Expand Down Expand Up @@ -142,13 +146,15 @@ def _glob(self, inputPath: str, recursive: bool = True, withHidden: bool = False
dir_list.append(filename)
# glob the directories at the end
for filename in dir_list:
path_list.extend(self._glob(inputPath=filename, recursive=recursive, withHidden=withHidden, filter=filter))
path_list.extend(self._glob(
inputPath=filename, recursive=recursive, withHidden=withHidden, filter=filter))
return path_list

@wamp.register('ros.path.get_list_recursive')
def getPathListRecursive(self, inputPath: str) -> List[PathItem]:
Log.info(
'Request to [ros.path.get_list_recursive] for %s' % inputPath)
path_list: List[PathItem] = self._glob(inputPath, recursive=True, withHidden=False, filter=['node_modules'])
f"{self.__class__.__name__}: Request to [ros.path.get_list_recursive] for {inputPath}")
path_list: List[PathItem] = self._glob(
inputPath, recursive=True, withHidden=False, filter=['node_modules'])

return json.dumps(path_list, cls=SelfEncoder)
Loading

0 comments on commit 6d68b17

Please sign in to comment.