Ejemplo n.º 1
0
    /*
     *  IncomingNewDataLink is used to accept new connections from the listener.
     */
    public void IncomingNewDataLink(IDataLink dataLink, IPresentationProtocol usedProtocol)
    {
        Debug.Log("[RobotRegister] incoming new connection!");

        // Change the receiver of the incoming messages for given client (connection) to this class.
        // The information is used to check the identity of the connection.
        usedProtocol.SetReceiver(this);

        // Communicator is a management class for protocol and datalink
        Communicator communicator = new Communicator(dataLink, usedProtocol);

        // Ask for identification of the connection; might be a robot!
        Message id_request = MessageBuilder.CreateMessage(MessageTarget_.Robot, MessageType_.IdentificationRequest);

        Thread.Sleep(1);

        if (!communicator.SendCommand(id_request))
        {
            Debug.LogError("[RobotRegister] Sending identity request command fails, how could this happen!?");
            // Actually, it could happen if the connection is immediately closed after making it.
        }
        else
        {
            // Keep a list of the active connections
            communicators.Add(communicator);
        }
    }
Ejemplo n.º 2
0
        public static bool AssignRobot(Communicator communicator, GeneralTypeRobot robot)
        {
            if (robot == null)
            {
                throw new ArgumentNullException("robot");
            }

            if (communicator == null)
            {
                throw new ArgumentNullException("communicator");
            }

            IPresentationProtocol pp = communicator.GetPresentationProtocol();

            if (pp == null)
            {
                throw new ArgumentNullException("communicator.GetPresentationProtocol()");
            }

            IDataLink dl = communicator.GetDataLink();

            if (dl == null || communicator.GetDataLink().Connected() != true)
            {
                throw new InvalidOperationException("Can't assign robot without being connected");
            }

            MessageActionMapper map = new MessageActionMapper(robot);

            communicator.GetPresentationProtocol().SetReceiver(map);

            return(true);
        }
 public void IncomingNewDataLink(IDataLink dataLink, IPresentationProtocol usedProtocol)
 {
     this.DataLink = dataLink;
     usedProtocol.SetReceiver(this);
     Connected = true;
     Debug.Log("Incoming impl");
 }
Ejemplo n.º 4
0
        public Communicator(IDataLink dataLink, IPresentationProtocol pP)
        {
            if (pP == null)
            {
                throw new System.ArgumentException("Parameter cannot be null", "pP");
            }

            if (dataLink == null)
            {
                throw new System.ArgumentException("Parameter cannot be null", "dataLink");
            }

            _pp       = pP;
            _datalink = dataLink;
        }
 public void IncomingNewDataLink(IDataLink dataLink, IPresentationProtocol usedProtocol)
 {
     this.DataLink = dataLink;
     Connected     = true;
 }