コード例 #1
0
ファイル: node.py プロジェクト: BackupTheBerlios/solipsis-svn
  def __init__(self, params):
    """ All informations about this node:
    host --> ip if the node, network_port, GUI_port, posX, posY, ar, ca, 
    ori --> a point, 
    exp --> expected number of neighbour, pseudo"""


    # event queue, used for inter-thread communication
    self.events = NotificationQueue()

    # network communication with peers is handled by this object
    netParams = params.getNetParams()
    self.peerConnector = UDPConnector("peer", self.events, netParams)

    controlParams = params.getControlParams()
    self.controlConnector = XMLRPCConnector("control", self.events, controlParams)

    # set the solipsis protocol used
    engineParams = params.getEngineParams()
    self.engine = V0_2_5_Engine(self, engineParams)

    self.controlEngine = ControlEngine(self, engineParams)
    self.internalEngine = InternalEngine(self, engineParams)
    
    position = [params.posX, params.posY]
    
    # call parent class constructor
    Entity.__init__(self, position, params.ori, params.ar, params.caliber,
                  params.pseudo)
    
    self.id = "unknown"
    
    # maximum expected number of neighbours.
    self.exp = params.exp
    
    # our IP address or 'localhost' if not specified in config file
    self.host = params.host
    
    self.alive = True
    self.logger = params.rootLogger
    
    # manage all peers
    peersParams = params.getPeersParams()
    self.peersManager = PeersManager(self, peersParams)

    # set world size in Geometry class
    Geometry.SIZE = params.world_size
    self.params=params
コード例 #2
0
ファイル: peer.py プロジェクト: BackupTheBerlios/solipsis-svn
  def __init__(self, id="", host="", port=0, pos=Position(0,0), ori=0,
               awareness_radius=0, caliber=0, pseudo=""):
    """ Create a new Entity and keep information about it"""

    # call parent class constructor
    Entity.__init__(self,pos, ori, awareness_radius, caliber, pseudo)

    self.id   = id
    self.address = Address(host, port)
    
    # last time when we saw this peer active 
    self.activeTime = 0

    # local position is the position of this peer using a coordinate system
    # centered on the position of the node
    # this value is set-up by the peer manager
    self.localPositon = pos
    
    # set the ID of this peer
    #id = self.createId()
    #self.setId(id)
    
    # position and relative position
    #relative_position = Function.relativePosition(self.position,
    # globalvars.me.position)
    #self.local_position = [ relative_position[0] - globalvars.me.position[0],
    #relative_position[1] - globalvars.me.position[1] ]

    # two boolean variables indicating that
    # we received a message from this entity
    self.message_received = 1
    # we sent a message to this entity
    self.message_sent = 0

    # services provided by entity
    # {id_service: [desc_service, host, port], ...}
    self.services = {}
    
    # boolean confirmation of the accuracy of informations
    self.ok = 0
コード例 #3
0
    def __init__(self, params):
        self._node = Entity()
        self._isConnected = False
        self._peers = {}
        self._options = {}
        self._params = params

        # get navigator specific parameters
        [dist_max, scale, coeff_zoom, pseudo, arePseudosDisplayed,
         areAvatarsDisplayed] = params.getNavigatorParams()
        self._options['dist_max'] = dist_max
        self._options['scale'] = scale
        self._options['coeff_zoom'] = coeff_zoom
        self._options['pseudo'] = pseudo
        self._options['display_pseudos'] = arePseudosDisplayed
        self._options['display_avatars'] = areAvatarsDisplayed
コード例 #4
0
 def __init__(self):
     Entity.__init__(self)
     self._isConnected = False
     self._peers = {}
コード例 #5
0
    def createEntity(self):
        """ Parse the event and return an Entity object initilized with information
        included in the event
        Return : a new Entity object
        """
        ent = Entity()
        if self.args.has_key("Id"):
            ent.setId(self.args["Id"])

        if self.args.has_key("Address"):
            ent.setAddress(self.args["Address"])

        if self.args.has_key("Position"):
            ent.setPosition(self.args["Position"])

        if self.args.has_key("Orientation"):
            ent.setOrientation(self.args["Orientation"])

        if self.args.has_key("AwarnessRadius"):
            ent.setAwarnessRadius(self.args["AwarnessRadius"])

        if self.args.has_key("Calibre"):
            ent.setCalibre(self.args["Calibre"])

        if self.args.has_key("Pseudo"):
            ent.setPseudo(self.args["Pseudo"])

        return ent
コード例 #6
0
class NavigatorInfo:
    """ NavigatorInfo contains all the informations related to the node
    * its characteristics : position, awarness radius, etc..
    * its peers
    * the services available for this node
    and the navigator state
    * what are the options : display avatar and/or display pseudo
    """
    def __init__(self, params):
        self._node = Entity()
        self._isConnected = False
        self._peers = {}
        self._options = {}
        self._params = params

        # get navigator specific parameters
        [dist_max, scale, coeff_zoom, pseudo, arePseudosDisplayed,
         areAvatarsDisplayed] = params.getNavigatorParams()
        self._options['dist_max'] = dist_max
        self._options['scale'] = scale
        self._options['coeff_zoom'] = coeff_zoom
        self._options['pseudo'] = pseudo
        self._options['display_pseudos'] = arePseudosDisplayed
        self._options['display_avatars'] = areAvatarsDisplayed
        
        
    def isConnected(self):
        return self._isConnected

    def addPeerInfo(self, peerInfo):
        """ Add information on a new peer
        peerInfo : a EntityInfo object
        """
        id = peerInfo.getId()
        relPos = Geometry.relativePosition(peerInfo.getPosition(),
                                           self._node.getPosition())
        peerInfo.setRelativePosition(relPos)
        assert( id <> '' )
        if not self._peers.has_key(id):
            self._peers[id] = peerInfo
        else:
            msg = 'Error - duplicate ID. Cannot add peer with id:' + id
            raise SolipsisInternalError(msg)

    def updateNodeInfo(self, nodeinfo):
        self._node = nodeinfo
        self._node.setRelativePosition(Position(0,0))

        
    def getOption(self, optionName):
        return self._options[optionName]

    def arePseudosDisplayed(self):
        return self.getOption('display_pseudos')    
    
    def areAvatarsDisplayed(self):
        return self.getOption('display_avatars')

    def setOption(self, section, option, value):
        
        self._options[option] = value
        self.params.setOption(section, option, value)

    def getMaxPosX(self):
        """ Return the X coordinate of the peer that is the farthest
        on the X axis.
        Return: a number >=0 """
        max = 0
        for p in self.enumeratePeers():
            absPosX = math.fabs(p.getRelativePosition().getPosX())
            if absPosX > max:
                max = absPosX

        return max

    def getMaxPosY(self):
        """ Return the Y coordinate of the peer that is the farthest
        on the Y axis.
        Return: a number >=0 """
        max = 0
        for p in self.enumeratePeers():
            absPosY = math.fabs(p.getRelativePosition().getPosY())
            if absPosY > max:
                max = absPosY

        return max
            
    def enumeratePeers(self):
        return self._peers.values()
    
    def getNode(self):
        return self._node