Пример #1
0
        public IDataReader CreateDataReader(
            ITopicDescription topic,
            DataReaderQos qos,
            IDataReaderListener listener,
            StatusKind mask)
        {
            ReturnCode            result     = DDS.ReturnCode.AlreadyDeleted;
            DataReader            dataReader = null;
            ITopicDescriptionImpl topicObj   = topic as ITopicDescriptionImpl;

            ReportStack.Start();
            lock (this)
            {
                if (this.rlReq_isAlive)
                {
                    if (topicObj == null)
                    {
                        result = DDS.ReturnCode.BadParameter;
                        ReportStack.Report(result, "TopicDescription is invalid (null), or not of type " +
                                           "DDS::OpenSplice::TopicDescription.");
                    }
                    else
                    {
                        result = QosManager.checkQos(qos);
                    }

                    if (result == DDS.ReturnCode.Ok)
                    {
                        lock (topicObj)
                        {
                            if ((topicObj as SacsSuperClass).rlReq_isAlive)
                            {
                                TypeSupport ts = topicObj.rlReq_TypeSupport;
                                if (ts != null)
                                {
                                    DatabaseMarshaler marshaler = DatabaseMarshaler.GetMarshaler(participant, ts.TypeSpec);
                                    dataReader = ts.CreateDataReader(marshaler);
                                    result     = dataReader.init(this, qos, topicObj, "reader <" + topicObj.Name + ">");
                                    if (result == ReturnCode.Ok)
                                    {
                                        dataReader.wlReq_ListenerDispatcher = this.wlReq_ListenerDispatcher;
                                        result = dataReader.SetListener(listener, mask);
                                    }
                                    else
                                    {
                                        dataReader = null;
                                    }

                                    if (result == DDS.ReturnCode.Ok)
                                    {
                                        readerList.Add(dataReader);
                                        if (rlReq_AutoEnableCreatedEntities && this.IsEnabled())
                                        {
                                            result = dataReader.Enable();
                                        }
                                    }
                                }
                                else
                                {
                                    ReportStack.Report(DDS.ReturnCode.PreconditionNotMet, "Were not able to locate TypeSupport belonging to topic " + topic.Name + ".");
                                }
                            }
                            else
                            {
                                // ALREADY_DELETED may only apply to the Subscriber in this context,
                                // so for a deleted TopicDescription use BAD_PARAMETER instead.
                                result = DDS.ReturnCode.BadParameter;
                            }
                        }
                        if (result != ReturnCode.Ok && dataReader != null)
                        {
                            // Ignore result because we prefer the original error.
                            DeleteDataReader(dataReader);
                            dataReader = null;
                        }
                    }
                }
            }
            ReportStack.Flush(this, result != ReturnCode.Ok);

            return(dataReader);
        }
Пример #2
0
        public IDataReader CreateDataReader(
            ITopicDescription topic,
            IDataReaderListener listener,
            StatusKind mask)
        {
            DataReader dataReader = null;

            if (topic != null)
            {
                SacsSuperClass superObj = (SacsSuperClass)topic;

                if (listener != null)
                {
                    OpenSplice.Gapi.gapi_dataReaderListener gapiListener;
                    DataReaderListenerHelper listenerHelper = new DataReaderListenerHelper();
                    listenerHelper.Listener = listener;
                    listenerHelper.CreateListener(out gapiListener);
                    using (DataReaderListenerMarshaler listenerMarshaler =
                               new DataReaderListenerMarshaler(ref gapiListener))
                    {
                        IntPtr gapiPtr = Gapi.Subscriber.create_datareader(
                            GapiPeer,
                            superObj.GapiPeer,
                            IntPtr.Zero,
                            listenerMarshaler.GapiPtr,
                            mask);
                        if (gapiPtr != IntPtr.Zero)
                        {
                            TypeSupport typeSupport = topic.Participant.GetTypeSupport(topic.TypeName)
                                                      as OpenSplice.TypeSupport;
                            dataReader = typeSupport.CreateDataReader(gapiPtr);
                            dataReader.SetListener(listenerHelper);
                        }
                    }
                }
                else
                {
                    IntPtr gapiPtr = Gapi.Subscriber.create_datareader(
                        GapiPeer,
                        superObj.GapiPeer,
                        IntPtr.Zero,
                        IntPtr.Zero,
                        StatusKind.Any);
                    if (gapiPtr != IntPtr.Zero)
                    {
                        TypeSupport typeSupport = topic.Participant.GetTypeSupport(topic.TypeName)
                                                  as OpenSplice.TypeSupport;
                        dataReader = typeSupport.CreateDataReader(gapiPtr);
                    }
                }
            }

            if (dataReader != null)
            {
                SubscriberQos subQos = null;
                ReturnCode    result = GetQos(ref subQos);
                if (result == ReturnCode.Ok)
                {
                    if (subQos.EntityFactory.AutoenableCreatedEntities)
                    {
                        dataReader.Enable();
                    }
                }
            }

            return(dataReader);
        }