Exemplo n.º 1
0
        private void PostSetup(Topic t, Participant participant, McUdpSendDataHandler sdh)
        {
            // If topic specifies a valid node address, add that as a static destination address for topic
            if (Ops.InetAddress.IsValidNodeAddress(t.GetDomainAddress()))
            {
                sdh.AddSink(t.GetName(), t.GetDomainAddress(), t.GetPort(), true);
            }
            else
            {
                if (partInfoListener == null)
                {
                    // Setup a listener on the participant info data published by participants on our domain.
                    // We use the information for topics with UDP as transport, to know the destination for UDP sends
                    // ie. we extract ip and port from the information and add it to our McUdpSendDataHandler
                    partInfoListener = new ParticipantInfoDataListener(participant, sdh);

                    partInfoSub = new Subscriber(participant.CreateParticipantInfoTopic());
                    partInfoSub.newDataDefault += new NewDataDefaultEventHandler(partInfoListener.SubscriberNewData);
                    partInfoSub.Start();
                }
            }
        }
        public void SubscriberNewData(Subscriber sender, OPSObject data)
        {
            if (!(data is ParticipantInfoData))
            {
                return;
            }

            ParticipantInfoData partInfo = (ParticipantInfoData)data;

            // Is it on our domain?
            if (partInfo.domain.Equals(participant.domainID))
            {
                foreach (TopicInfoData tid in partInfo.subscribeTopics)
                {
                    // We are only interrested in topics with UDP as transport
                    if ((tid.transport.Equals(Topic.TRANSPORT_UDP)) && (participant.HasPublisherOn(tid.name)))
                    {
                        udpSendDataHandler.AddSink(tid.name, partInfo.ip, partInfo.mc_udp_port);
                    }
                }
            }
        }