6 Copyright (C) 2009-2014     8     RT-Synthesis Research Group     9     Intelligent Systems Research Institute,    10     National Institute of Advanced Industrial Science and Technology (AIST),    13 Licensed under the Eclipse Public License -v 1.0 (EPL)    14 http://www.opensource.org/licenses/eclipse-1.0.txt    16 Objects and functions used to build and store a tree representing a hierarchy    17 of name servers, directories, managers and components.    21 from copy 
import deepcopy
    22 from omniORB 
import CORBA
    26 from rtctree 
import NAMESERVERS_ENV_VAR, ORB_ARGS_ENV_VAR
    41     '''Represents a tree of name servers, directories, managers and components.    43     This stores the root node. All other nodes branch off from that.    45     When creating a tree, you may pass no arguments, or a list of name servers    46     to load, or a path or list of paths (as returned by    47     rtctree.path.parse_path). If no arguments are given, the tree will load    48     name servers from the environment variable specified in    49     NAMESERVERS_ENV_VAR. If a list of servers are given, only those servers    52     If paths are given, and the path is just '/', behaviour is as if no path    53     argument were given. If a path starts with '/' and contains an element    54     after it, that element will be treated as a name server. Otherwise the path    55     is considered to be bad.    58     def __init__(self, servers=None, paths=None, orb=None, filter=[],
    59             dynamic=
False, *args, **kwargs):
    62         @param servers A list of servers to parse into the tree.    63         @param paths A list of paths from which to get servers to parse    65         @param orb If not None, the specified ORB will be used. If None,    66                    the tree object will create its own ORB.    67         @param filter A list of paths (each a list of strings).    68                       If not empty, then only objects in the paths will    69                       be parsed, to increase speed. If the tail of a    70                       path is a directory, that entire directory will be    71                       parsed. Directories that are not the tail will    72                       only have the next entry in the path parsed.    73         @param dynamic Use observers to keep the tree up-to-date. For example,    74                        when a component changes state, an observer can notify    75                        RTCTree so that the corresponding object in the tree can    76                        be updated. Currently this only affects components.    77         @raises NonRootPathError    87             if type(paths[0]) == str:
    88                 if paths[0][0] != 
'/':
   101         if not servers 
and not paths:
   107             self._orb.shutdown(wait_for_completion=CORBA.FALSE)
   112         return str(self.
_root)
   115         '''Parse a name server, adding its contents to the tree.   117         @param server The address of the name server, in standard   118                       address format. e.g. 'localhost',   119                       'localhost:2809', '59.7.0.1'.   120         @param filter Restrict the parsed objects to only those in this   121                       path. For example, setting filter to [['/',   122                       'localhost', 'host.cxt', 'comp1.rtc']] will   123                       prevent 'comp2.rtc' in the same naming context   125         @param dynamic Override the tree-wide dynamic setting. If not provided,   126                        the value given when the tree was created will be used.   134         '''Get a node by path.   136         @param path A list of path elements pointing to a node in the tree.   137                     For example, ['/', 'localhost', 'dir.host']. The first   138                     element in this path should be the root node's name.   141         return self._root.get_node(path)
   144         '''Check if the tree has a path.   146         @param path A list of path elements pointing to a node in the tree.   147                     For example, ['/', 'localhost', 'dir.host']. The first   148                     element in this path should be the root node's name.   151         return self._root.has_path(path)
   154         '''Is the node pointed to by @ref path a component?'''   156         return node.is_component
   159         '''Is the node pointed to by @ref path a directory (name servers and   164         return node.is_directory
   167         '''Is the node pointed to by @ref path a manager?'''   169         return node.is_manager
   172         '''Is the node pointed to by @ref path a name server (specialisation   177         return node.is_nameserver
   180         '''Is the node pointed to by @ref path an unknown object?'''   182         return node.is_unknown
   185         '''Is the node pointed to by @ref path a zombie object?'''   187         return node.is_zombie
   189     def iterate(self, func, args=None, filter=[]):
   190         '''Call a function on the root node, and recursively all its children.   192         This is a depth-first iteration.   194         @param func The function to call. Its declaration must be   195                     'def blag(node, args)', where 'node' is the current node   196                     in the iteration and args is the value of @ref args.   197         @param args Extra arguments to pass to the function at each iteration.   198                     Pass multiple arguments in as a tuple.   199         @param filter A list of filters to apply before calling func for each   200                       node in the iteration. If the filter is not True,   201                       @ref func will not be called for that node. Each filter   202                       entry should be a string, representing on of the is_*   203                       properties (is_component, etc), or a function object.   204         @return The results of the calls to @ref func in a list.   207         return self._root.iterate(func, args, filter)
   210         '''Load the name servers environment variable and parse each server in   213         @param filter Restrict the parsed objects to only those in this   214                       path. For example, setting filter to [['/',   215                       'localhost', 'host.cxt', 'comp1.rtc']] will   216                       prevent 'comp2.rtc' in the same naming context   218         @param dynamic Override the tree-wide dynamic setting. If not provided,   219                        the value given when the tree was created will be used.   224         if NAMESERVERS_ENV_VAR 
in os.environ:
   225             servers = [s 
for s 
in os.environ[NAMESERVERS_ENV_VAR].split(
';') \
   230         '''Releases ownership of an ORB created by the tree.   232         This will prevent the ORB being destroyed when the tree is.   238         '''Claims ownership of an ORB created elsewhere.   240         This will cause the ORB to be destroyed when the tree is.   247         '''The reference to the ORB held by this tree.'''   257             if ORB_ARGS_ENV_VAR 
in os.environ:
   258                 orb_args = os.environ[ORB_ARGS_ENV_VAR].split(
';')
   261             self.
_orb = CORBA.ORB_init(orb_args)
   264         self.
_poa = self._orb.resolve_initial_references(
'RootPOA')
   265         self._poa._get_the_POAManager().activate()
   269         if type(servers) 
is str:
   271             if servers 
in self._root.children_names:
   275             for server 
in servers:
   277                 if server 
in self._root.children_names:
   283         if not filtered([
'/', address], filter):
   286             self._root._add_child(new_ns_node)
 def _parse_name_servers(self, servers, filter=[], dynamic=False)
def is_directory(self, path)
def is_unknown(self, path)
def load_servers_from_env(self, filter=[], dynamic=None)
def __init__(self, servers=None, paths=None, orb=None, filter=[], dynamic=False, args, kwargs)
def trim_filter(filter, levels=1)
def is_nameserver(self, path)
def filtered(path, filter)
def is_component(self, path)
def iterate(self, func, args=None, filter=[])
def is_zombie(self, path)
def _create_orb(self, orb=None)
def is_manager(self, path)
def add_name_server(self, server, filter=[], dynamic=None)
def _parse_name_server(self, address, filter=[], dynamic=False)