Beispiel #1
0
        public IDataWriter CreateDataWriter(
            ITopic topic,
            IDataWriterListener listener,
            StatusKind mask)
        {
            DataWriter dataWriter = null;
            Topic      topicObj   = topic as Topic;

            if (listener != null)
            {
                // Note: we use the same gapi lister as the DataWriter since the
                // publisher doesn't add anything unique
                OpenSplice.Gapi.gapi_publisherDataWriterListener gapiListener;
                PublisherDataWriterListenerHelper listenerHelper = new PublisherDataWriterListenerHelper();
                listenerHelper.Listener = listener;
                listenerHelper.CreateListener(out gapiListener);
                using (PublisherDataWriterListenerMarshaler listenerMarshaler =
                           new PublisherDataWriterListenerMarshaler(ref gapiListener))
                {
                    IntPtr gapiPtr = Gapi.Publisher.create_datawriter(
                        GapiPeer,
                        topicObj.GapiPeer,
                        Gapi.NativeConstants.GapiDataWriterQosDefault,
                        listenerMarshaler.GapiPtr,
                        mask);
                    if (gapiPtr != IntPtr.Zero)
                    {
                        TypeSupport typeSupport = topic.Participant.GetTypeSupport(topic.TypeName)
                                                  as OpenSplice.TypeSupport;
                        dataWriter = typeSupport.CreateDataWriter(gapiPtr);
                        dataWriter.SetListener(listenerHelper);
                    }
                }
            }
            else
            {
                IntPtr gapiPtr = Gapi.Publisher.create_datawriter(
                    GapiPeer,
                    topicObj.GapiPeer,
                    Gapi.NativeConstants.GapiDataWriterQosDefault,
                    IntPtr.Zero,
                    mask);
                if (gapiPtr != IntPtr.Zero)
                {
                    TypeSupport typeSupport = topic.Participant.GetTypeSupport(topic.TypeName)
                                              as OpenSplice.TypeSupport;
                    dataWriter = typeSupport.CreateDataWriter(gapiPtr);
                }
            }

            if (dataWriter != null)
            {
                PublisherQos pubQos = null;
                ReturnCode   result = GetQos(ref pubQos);
                if (result == ReturnCode.Ok)
                {
                    if (pubQos.EntityFactory.AutoenableCreatedEntities)
                    {
                        dataWriter.Enable();
                    }
                }
            }

            return(dataWriter);
        }
        public IDataWriter CreateDataWriter(
            ITopic topic,
            DataWriterQos qos,
            IDataWriterListener listener,
            StatusKind mask)
        {
            ReturnCode result     = DDS.ReturnCode.AlreadyDeleted;
            DataWriter dataWriter = null;
            Topic      topicObj   = topic as Topic;

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

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

                                if (result == DDS.ReturnCode.Ok)
                                {
                                    writerList.Add(dataWriter);
                                    if (rlReq_AutoEnableCreatedEntities)
                                    {
                                        result = dataWriter.Enable();
                                    }
                                }
                            }
                            else
                            {
                                // ALREADY_DELETED may only apply to the Publisher in this context,
                                // so for a deleted topic use BAD_PARAMETER instead.
                                result = DDS.ReturnCode.BadParameter;
                            }
                        }
                    }

                    if (result != ReturnCode.Ok && dataWriter != null)
                    {
                        // Ignore result because we prefer the original error.
                        DeleteDataWriter(dataWriter);
                        dataWriter = null;
                    }
                }
            }
            ReportStack.Flush(this, result != ReturnCode.Ok);

            return(dataWriter);
        }
Beispiel #3
0
        public IDataWriter CreateDataWriter(
            ITopic topic,
            DataWriterQos qos,
            IDataWriterListener listener,
            StatusKind mask)
        {
            DataWriter dataWriter = null;
            Topic      topicObj   = topic as Topic;

            using (OpenSplice.CustomMarshalers.DataWriterQosMarshaler marshaler =
                       new OpenSplice.CustomMarshalers.DataWriterQosMarshaler())
            {
                if (marshaler.CopyIn(qos) == ReturnCode.Ok)
                {
                    if (listener != null)
                    {
                        // Note: we use the same gapi lister as the DataWriter since the
                        // publisher doesn't add anything unique
                        OpenSplice.Gapi.gapi_publisherDataWriterListener gapiListener;
                        PublisherDataWriterListenerHelper listenerHelper = new PublisherDataWriterListenerHelper();
                        listenerHelper.Listener = listener;
                        listenerHelper.CreateListener(out gapiListener);
                        using (PublisherDataWriterListenerMarshaler listenerMarshaler =
                                   new PublisherDataWriterListenerMarshaler(ref gapiListener))
                        {
                            IntPtr gapiPtr = Gapi.Publisher.create_datawriter(
                                GapiPeer,
                                topicObj.GapiPeer,
                                marshaler.GapiPtr,
                                listenerMarshaler.GapiPtr,
                                mask);
                            if (gapiPtr != IntPtr.Zero)
                            {
                                DDS.OpenSplice.DomainParticipant participantImpl;

                                participantImpl = topic.Participant as DDS.OpenSplice.DomainParticipant;
                                TypeSupportFactory tsFactory = participantImpl.GetTypeSupportFactory(topic.TypeName);
                                dataWriter = tsFactory.CreateDataWriter(gapiPtr);
                                dataWriter.SetListener(listenerHelper);
                            }
                        }
                    }
                    else
                    {
                        // Invoke the corresponding gapi function.
                        IntPtr gapiPtr = Gapi.Publisher.create_datawriter(
                            GapiPeer,
                            topicObj.GapiPeer,
                            marshaler.GapiPtr,
                            IntPtr.Zero,
                            mask);
                        if (gapiPtr != IntPtr.Zero)
                        {
                            DDS.OpenSplice.DomainParticipant participantImpl;

                            participantImpl = topic.Participant as DDS.OpenSplice.DomainParticipant;
                            TypeSupportFactory tsFactory = participantImpl.GetTypeSupportFactory(topic.TypeName);
                            dataWriter = tsFactory.CreateDataWriter(gapiPtr);
                        }
                    }
                }
            }

            if (dataWriter != null)
            {
                PublisherQos pubQos = null;
                ReturnCode   result = GetQos(ref pubQos);
                if (result == ReturnCode.Ok)
                {
                    if (pubQos.EntityFactory.AutoenableCreatedEntities)
                    {
                        dataWriter.Enable();
                    }
                }
            }

            return(dataWriter);
        }