/// <summary> /// Sets the <see cref="DataWriterListener" />. /// </summary> /// <param name="listener">The <see cref="DataWriterListener" /> to be set.</param> /// <param name="mask">The <see cref="StatusMask" /> of which status changes the listener should be notified.</param> /// <returns>The <see cref="ReturnCode" /> that indicates the operation result.</returns> public ReturnCode SetListener(DataWriterListener listener, StatusMask mask) { Listener = listener; IntPtr ptr = IntPtr.Zero; if (listener != null) { ptr = listener.ToNative(); } return(UnsafeNativeMethods.SetListener(_native, ptr, mask)); }
/// <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); }