Esempio n. 1
0
        /// <summary>
        /// Sets a default value of the <see cref="Publisher" /> QoS policies which will be used for newly created <see cref="Publisher" /> entities in the
        /// case where the QoS policies are defaulted in the CreatePublisher operation.
        /// </summary>
        /// <remarks>
        /// This operation will check that the resulting policies are self consistent; if they are not, the operation will have no effect and
        /// return <see cref="ReturnCode.InconsistentPolicy" />.
        /// </remarks>
        /// <param name="qos">The default <see cref="PublisherQos" /> to be set.</param>
        /// <returns>The <see cref="ReturnCode" /> that indicates the operation result.</returns>
        public ReturnCode SetDefaultDataWriterQos(DataWriterQos qos)
        {
            if (qos is null)
            {
                return(ReturnCode.BadParameter);
            }

            var qosNative = qos.ToNative();
            var ret       = UnsafeNativeMethods.SetDefaultDataWriterQos(_native, qosNative);

            qos.Release();

            return(ret);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new <see cref="DataWriter" /> with the desired QoS policies and attaches to it the specified <see cref="DataWriterListener" />
        /// </summary>
        /// <remarks>
        /// <para>The created <see cref="DataWriter" /> will be attached and belongs to the <see cref="Publisher" /> that is its factory.</para>
        /// <para>The <see cref="Topic" /> passed to this operation must have been created from the same <see cref="DomainParticipant" /> that was used to create this
        /// <see cref="Publisher" />. If the <see cref="Topic" /> was created from a different <see cref="DomainParticipant" />,
        /// the operation will fail and return a <see langword="null"/> result.</para>
        /// </remarks>
        /// <param name="topic">The <see cref="Topic" /> that the <see cref="DataWriter" /> will be associated with.</param>
        /// <param name="qos">The <see cref="DataWriterQos" /> policies to be used for creating the new <see cref="DataWriter" />.</param>
        /// <param name="listener">The <see cref="DataWriterListener" /> to be attached to the newly created <see cref="DataWriter" />.</param>
        /// <param name="statusMask">The <see cref="StatusMask" /> of which status changes the listener should be notified.</param>
        /// <returns>The newly created <see cref="DataWriter" /> on success, otherwise <see langword="null"/>.</returns>
        public DataWriter CreateDataWriter(Topic topic, DataWriterQos qos, DataWriterListener listener, StatusMask statusMask)
        {
            if (topic is null)
            {
                throw new ArgumentNullException(nameof(topic));
            }

            DataWriterQosWrapper qosWrapper = default;

            if (qos is null)
            {
                qos = new DataWriterQos();
                var ret = GetDefaultDataWriterQos(qos);
                if (ret == ReturnCode.Ok)
                {
                    qosWrapper = qos.ToNative();
                }
            }
            else
            {
                qosWrapper = qos.ToNative();
            }

            IntPtr nativeListener = IntPtr.Zero;

            if (listener != null)
            {
                nativeListener = listener.ToNative();
            }

            IntPtr native = UnsafeNativeMethods.CreateDataWriter(_native, topic.ToNative(), qosWrapper, nativeListener, statusMask);

            if (native.Equals(IntPtr.Zero))
            {
                return(null);
            }

            qos.Release();

            var dw = new DataWriter(native)
            {
                Listener = listener,
            };

            EntityManager.Instance.Add((dw as Entity).ToNative(), dw);
            ContainedEntities.Add(dw);

            return(dw);
        }