Exemple #1
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)
        {
            // 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
        public Publisher(Topic topic)
        {
            this.topic = topic;
            this.bytes = new byte[topic.GetSampleMaxSize()];

            this.participant = Participant.GetInstance(topic.GetDomainID(), topic.GetParticipantID());
            this.inProcessTransport = participant.GetInProcessTransport();
            Init();
        }
Exemple #3
0
 public ReceiveDataHandler(Topic t, Participant part, IReceiver receiver)
 {
     topic = t;
     bytes = new byte[t.GetSampleMaxSize()];
     headerBytes = new byte[FRAGMENT_HEADER_SIZE];
     participant = part;
     fragmentSize = Globals.MAX_SEGMENT_SIZE;
     this.receiver = receiver;
 }
Exemple #4
0
 public Subscriber(Topic t)
 {
     if (t == null)
     {
         throw new OPSInvalidTopicException("Not possible to create Subscriber with null Topic!");
     }
     this.topic = t;
     this.participant = Participant.GetInstance(topic.GetDomainID(), topic.GetParticipantID());
     deadlineNotifier = DeadlineNotifier.GetInstance();
     inProcessTransport = participant.GetInProcessTransport();
 }
        /// Protection is not needed since all calls go through the participant which is synched
        public ReceiveDataHandler GetReceiveDataHandler(Topic top, Participant participant)
        {
            // In the case that we use the same port for several topics, we need to find the receiver for the transport::address::port used
            string key = MakeKey(top);

            if (ReceiveDataHandlers.ContainsKey(key))
            {
                ReceiveDataHandler rdh = ReceiveDataHandlers[key];

                // Check if any of the topics have a sample size larger than MAX_SEGMENT_SIZE
                // This will lead to a problem when using the same port, if samples becomes > MAX_SEGMENT_SIZE
                if ((rdh.GetSampleMaxSize() > Globals.MAX_SEGMENT_SIZE) || (top.GetSampleMaxSize() > Globals.MAX_SEGMENT_SIZE))
                {
                    if (top.GetTransport().Equals(Topic.TRANSPORT_UDP))
                    {
                        Logger.ExceptionLogger.LogMessage("Warning: UDP transport is used with Topics with 'sampleMaxSize' > " + Globals.MAX_SEGMENT_SIZE);
                    }
                    else
                    {
                        Logger.ExceptionLogger.LogMessage("Warning: Same port (" + top.GetPort() + ") is used with Topics with 'sampleMaxSize' > " + Globals.MAX_SEGMENT_SIZE);
                    }
                }
                return rdh;
            }

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

            // Didn't exist, create one if transport is known
            if ( (top.GetTransport().Equals(Topic.TRANSPORT_MC)) || (top.GetTransport().Equals(Topic.TRANSPORT_TCP)) )
            {
                ReceiveDataHandlers.Add(key,
                    new ReceiveDataHandler(top, participant, ReceiverFactory.CreateReceiver(top, localIF)));
                return ReceiveDataHandlers[key];
            }
            else if (top.GetTransport().Equals(Topic.TRANSPORT_UDP))
            {
                IReceiver rec = ReceiverFactory.CreateReceiver(top, localIF);
                ReceiveDataHandlers.Add(key, new ReceiveDataHandler(top, participant, rec));

                participant.SetUdpTransportInfo(((UdpReceiver)rec).IP, ((UdpReceiver)rec).Port);

                return ReceiveDataHandlers[key];
            }
            return null;
        }
Exemple #6
0
        /// 
        /// <param name="domain"></param>
        /// <param name="participantID"></param>
        internal Participant GetParticipant(Domain domain, string participantID)
        {
            string hashKey = domain.GetDomainID() + " " + participantID;

            if (!instances.ContainsKey(hashKey))
            {
                Participant newInst = new Participant(domain, participantID);
                Domain tDomain = newInst.getDomain();

                if (tDomain != null)
                {
                    instances.Add(hashKey, newInst);
                }
                else
                {
                    return null;
                }
            }
            return instances[hashKey];
        }
        /// Protection is not needed since all calls go through the participant which is synched
        public void ReleaseReceiveDataHandler(Topic top, Participant participant)
        {
            // In the case that we use the same port for several topics, we need to find the receiver for the transport::address::port used
            string key = MakeKey(top);

            if (ReceiveDataHandlers.ContainsKey(key))
            {
                ReceiveDataHandler rdh = ReceiveDataHandlers[key];

                if (rdh.GetNrOfSubscribers() == 0)
                {
                    ReceiveDataHandlers.Remove(key);

                    if (rdh.GetTransport().Equals(Topic.TRANSPORT_UDP))
                    {
                        participant.SetUdpTransportInfo("", 0);
                    }
                }

            }
        }
 public ParticipantInfoDataListener(Participant part, McUdpSendDataHandler sendDataHandler)
 {
     this.participant = part;
     this.udpSendDataHandler = sendDataHandler;
 }
Exemple #9
0
 public ParticipantInfoDataListener(Participant part, McUdpSendDataHandler sendDataHandler)
 {
     this.participant        = part;
     this.udpSendDataHandler = sendDataHandler;
 }