Ejemplo n.º 1
0
    def _node_change(self, node):
        """
        Node status changed (event callback).
        """
#        self.log.debug("Sending new node data for %d" % node.id())
        from simx.act.context import R
        R.reply(self._info_for_node(node))
Ejemplo n.º 2
0
 def QUERY_LINKS(self, node_ids=None):
     nodes = self.topo[node_ids] if node_ids else self.topo.activeNodes()
     self.log.debug("Sending link information for %d nodes" % len(nodes))
     for n in nodes:
         for o in n.neighbors:
             from simx.act.context import R
             R.reply(self._link_msg(n, o, n.gain(o)))
Ejemplo n.º 3
0
    def _link_change(self, node, other, gain):
        """
        Link status changed (event callback).
        """
#        self.log.debug("Sending new link information %d(%s)->%d"
#                       % (node.id(), gain, other.id()))
        from simx.act.context import R
        R.reply(self._link_msg(node, other, gain))
Ejemplo n.º 4
0
 def _send_time_event(self, event_type):
     """
     Send a time event now.
     """
     event = TimeEvent.Msg()
     event.set_event_type(event_type)
     event.set_time(self.time_control.time())
     R.reply(event)
Ejemplo n.º 5
0
 def _send_time_event(self, event_type):
     """
     Send a time event now.
     """
     event = TimeEvent.Msg()
     event.set_event_type(event_type)
     event.set_time(self.time_control.time())
     R.reply(event)
Ejemplo n.º 6
0
    def MOVE(self, node_id, x_pos, y_pos, quiet=False):
        """
        Move a node with the given ID to the new location.
        """
        node = self.topo.getNode(node_id)
        node.set_pos((x_pos, y_pos))

        if not quiet:
            from simx.act.context import R
            R.reply(self._info_for_node(node))
Ejemplo n.º 7
0
 def replyWatch(self, var):
     """
     Send the variable binding information in a reply.
     """
     resp = ReactBindWatch.Msg()
     resp.set_node(var.node_id)
     resp.set_var_id(var.id)
     resp.set_var_type(0)
     resp.set_varname(var.name)
     resp.set_watchexpr(var.expr_str)
     from simx.act.context import R
     R.reply(resp)
Ejemplo n.º 8
0
 def replyWatch(self,var):
        """
        Send the variable binding information in a reply.
        """
        resp = ReactBindWatch.Msg()
        resp.set_node(var.node_id)
        resp.set_var_id(var.id)
        resp.set_var_type(0)
        resp.set_varname(var.name)
        resp.set_watchexpr(var.expr_str)
        from simx.act.context import R
        R.reply(resp)
Ejemplo n.º 9
0
    def VIEW_REBIND(self, varname, rebinding_str):
        """
        Rebind a view.
        """
        try:
            rebindings = self._rebindings(rebinding_str)
            rebound = self.probe_loader.lookup(varname, *rebindings)
            msg = simplejson.dumps(rebound.to_basic())
        except StandardError, exc:
#            reply(failure_reply(str(exc)))
            from simx.act.context import R
            R.reply(failure_reply(exc.message))
Ejemplo n.º 10
0
    def GET_LISTING(self):
        """
        Return a listing of all known variable and type information.
        """
        def conv(src):
            "Convert to proper transmission structure"
            return dict((k, v.to_basic()) for k, v in src.iteritems())
        
        data = {
            'variables': conv(self.probe_loader.variables),
            'structures': conv(self.probe_loader.structs),
            'typedefs': conv(self.probe_loader.typedefs)
            }
        msg = simplejson.dumps(data)
#        reply(success_reply(msg))
        from simx.act.context import R
        R.reply(success_reply(msg))
Ejemplo n.º 11
0
    def _rebindings(self, rebinding_str):
        """
        Returns split replacements strings or None.
        """
        pairs = [pok for pok
                 in (p.strip() for p in rebinding_str.split(","))
                 if pok]
        rebindings = [p.split("=") for p in pairs]
        #print "pairs****", pairs
        #print "rebindings****", rebindings
        try:
            # don't actually do anything, but will throw an exception
            # if an invalid assignment occurs
            for (a, b) in rebindings:
                pass
        except:
#            raise ValueError("Invalid replacement: %s" % rebinding_str)
            reply = failure_reply("Invalid replacement: %s" % rebinding_str)
            from simx.act.context import R
            R.reply(reply)
        else:
            return rebindings
Ejemplo n.º 12
0
 def sendWatchMsg(var):
     watch = ReactWatch.Msg()
     watch.set_var_id(var.id)
     watch.set_value(str(current))
     from simx.act.context import R
     R.reply(watch)
Ejemplo n.º 13
0
 def DEL(self, var_id):
     from simx.act.context import R
     R.strReply("<NI DEL>")
     pass
Ejemplo n.º 14
0
 def QUERY_NODES(self, node_ids=None):
     nodes = self.topo[node_ids] if node_ids else self.topo.activeNodes()
     self.log.debug("Sending node information for %d nodes" % len(nodes))
     for node in nodes:
         from simx.act.context import R
         R.reply(self._info_for_node(node))
Ejemplo n.º 15
0
 def sendWatchMsg(var):
     watch = ReactWatch.Msg()
     watch.set_var_id(var.id)
     watch.set_value(str(current))
     from simx.act.context import R
     R.reply(watch)
Ejemplo n.º 16
0
 def DEL(self,var_id):
            from simx.act.context import R
            R.strReply("<NI DEL>")
            pass
Ejemplo n.º 17
0
    def VIEW_REBIND(self, varname, rebinding_str):
        """
        Rebind a view.
        """
        try:
            rebindings = self._rebindings(rebinding_str)
            rebound = self.probe_loader.lookup(varname, *rebindings)
            msg = simplejson.dumps(rebound.to_basic())
        except StandardError, exc:
#            reply(failure_reply(str(exc)))
            from simx.act.context import R
            R.reply(failure_reply(exc.message))
        else:
#            reply(success_reply(msg))
            from simx.act.context import R
            R.reply(success_reply(msg))


    def BIND(self, nodeId, varname, watch=None,expr_str=None):
        """
        Creating a binding for a variable.

        If the variable is already bound it is updated. The variable
        binding is returned on success.

        If the variable can not be bound or rebound, a BindingFailed
        exception is raised.
        """
        rebinding_str=""
        #print "rebindings****", rebinding_str
        rebindings = self._rebindings(rebinding_str)
Ejemplo n.º 18
0
 def sendWatchMsg(id,value):
     watch = ReactWatch.Msg()
     watch.set_var_id(id)
     watch.set_value(value)
     from simx.act.context import R
     R.reply(watch)