///LA TODO Protection ?? What if several subscribers at the same time
        /// Not needed since all calls go through the participant which is synched
        public ISendDataHandler GetSendDataHandler(Topic t, Participant participant)
        {
            // In the case that we use the same port for several topics, we need to find the sender for the transport::address::port used
            string key = t.GetTransport() + "::" + t.GetDomainAddress() + "::" + t.GetPort();

            if (SendDataHandlers.ContainsKey(key))
            {
                return(SendDataHandlers[key]);
            }

            try
            {
                // Get the local interface, doing a translation from subnet if necessary
                string localIF = Domain.DoSubnetTranslation(participant.getDomain().GetLocalInterface());

                ISendDataHandler sender = null;
                if (t.GetTransport().Equals(Topic.TRANSPORT_MC))
                {
                    sender = new McSendDataHandler(t, localIF);
                }
                else if (t.GetTransport().Equals(Topic.TRANSPORT_TCP))
                {
                    sender = new TcpSendDataHandler(t, localIF);
                }
                if (sender != null)
                {
                    SendDataHandlers.Add(key, sender);
                    return(sender);
                }

                // We don't want to add the udp handler to the handler list, so handle this last
                if (t.GetTransport().Equals(Topic.TRANSPORT_UDP))
                {
                    if (udpSendDataHandler == null)
                    {
                        // We have only one sender for all topics, so use the domain value for buffer size
                        udpSendDataHandler = new McUdpSendDataHandler(
                            participant.getDomain().GetOutSocketBufferSize(),
                            localIF);

                        // 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, udpSendDataHandler);

                        partInfoSub = new Subscriber(participant.CreateParticipantInfoTopic());
                        partInfoSub.newDataDefault += new NewDataDefaultEventHandler(partInfoListener.SubscriberNewData);
                        partInfoSub.Start();
                    }
                    return(udpSendDataHandler);
                }

                throw new CommException("No such Transport " + t.GetTransport());
            }
            catch (System.IO.IOException ex)
            {
                throw new CommException("Error creating SendDataHandler. IOException -->" + ex.Message);
            }
        }
Exemple #2
0
 private void Init()
 {
     try
     {
         this.sendDataHandler = this.participant.GetSendDataHandler(topic);
         Start();
     }
     catch (Exception ex)
     {
         Logger.ExceptionLogger.LogMessage(this.GetType().Name + " Init: " + ex.ToString());
     }
 }
Exemple #3
0
        public ISendDataHandler GetSendDataHandler(Topic topic)
        {
            ISendDataHandler sdh = this.sendDataHandlerFactory.GetSendDataHandler(topic, this);

            if (sdh != null)
            {
                lock (partInfoData)
                {
                    partInfoData.publishTopics.Add(new TopicInfoData(topic));
                }
            }
            return(sdh);
        }
Exemple #4
0
 /// <summary>
 /// Start the publisher (necessary when using TCP as transport and it has been stopped)
 /// </summary>
 public void Start()
 {
     if (!started)
     {
         try
         {
             // Tell the sendDataHandler that we need it
             this.sendDataHandler = this.participant.GetSendDataHandler(topic);
             this.sendDataHandler.AddPublisher(this);
             started = true;
         }
         catch (Exception ex)
         {
             Logger.ExceptionLogger.LogMessage(this.GetType().Name + " Init: " + ex.ToString());
         }
     }
 }
Exemple #5
0
        ///LA TODO Protection ?? What if several subscribers at the same time
        /// Not needed since all calls go through the participant which is synched
        public ISendDataHandler GetSendDataHandler(Topic t, Participant participant)
        {
            // Get the local interface, doing a translation from subnet if necessary
            string localIF = InetAddress.DoSubnetTranslation(t.GetLocalInterface());
            string key     = MakeKey(t, localIF);

            if (SendDataHandlers.ContainsKey(key))
            {
                ISendDataHandler sender = SendDataHandlers[key];
                if (t.GetTransport().Equals(Topic.TRANSPORT_UDP))
                {
                    PostSetup(t, participant, (McUdpSendDataHandler)sender);
                }
                return(sender);
            }

            try
            {
                ISendDataHandler sender = null;
                if (t.GetTransport().Equals(Topic.TRANSPORT_MC))
                {
                    sender = new McSendDataHandler(t, localIF, t.GetTimeToLive());
                }
                else if (t.GetTransport().Equals(Topic.TRANSPORT_TCP))
                {
                    sender = new TcpSendDataHandler(t, localIF);
                }
                else if (t.GetTransport().Equals(Topic.TRANSPORT_UDP))
                {
                    // We have only one sender for all topics on an interface, so use the domain value for buffer size
                    sender = new McUdpSendDataHandler(participant.getDomain().GetOutSocketBufferSize(), localIF);
                    PostSetup(t, participant, (McUdpSendDataHandler)sender);
                }
                if (sender != null)
                {
                    SendDataHandlers.Add(key, sender);
                    return(sender);
                }

                throw new CommException("No such Transport " + t.GetTransport());
            }
            catch (System.IO.IOException ex)
            {
                throw new CommException("Error creating SendDataHandler. IOException -->" + ex.Message);
            }
        }
Exemple #6
0
 private void Init()
 {
     try
     {
         this.sendDataHandler = this.participant.GetSendDataHandler(topic);
         Start();
     }
     catch (Exception ex)
     {
         Logger.ExceptionLogger.LogMessage(this.GetType().Name + " Init: " + ex.ToString());
     }
 }