/// <summary> /// Remove the sigevent handler from the active channel. /// </summary> /// <param name="sigevent">he sigevent that was filled in by a call to <see cref="AddSigeventHandler"/>.</param> /// <returns>true if the sigevent handler was successfully removed from the channel, false if otherwise.</returns> public bool RemoveSigeventHandler(SafeSigeventHandle sigevent) { if (disposed) { throw new ObjectDisposedException("BPS"); } if (sigevent == null) { throw new ArgumentNullException("sigevent"); } if (sigevent.IsInvalid) { throw new ArgumentException("Sigevent is invalid"); } var pointer = sigevent.DangerousGetHandle(); var success = bps_remove_sigevent_handler(pointer) == BPS_SUCCESS; if (handleToStructPointer.ContainsKey(pointer) && success) { var dataPtr = handleToStructPointer[pointer]; handleToStructPointer.Remove(pointer); allocatedPointers.Remove(dataPtr); Util.FreeSerializePointer(dataPtr); } return(success); }
/// <summary> /// Add a sigevent handler to the active channel. /// </summary> /// <param name="sigevent">An allocated sigevent that will be filled in by this function.</param> /// <param name="sigeventHandler"> /// The sigevent callback that gets fired whenever the channel receives the corresponding sigevent. If the function returns false, than it is removed from the active channel. /// </param> /// <param name="handlerData">Service specific data that will be passed into every call to <paramref name="sigeventHandler"/>.</param> /// <returns>true if the sigevent handler was successfully registered, and sigevent was filled in. false if otherwise.</returns> public bool AddSigeventHandler(SafeSigeventHandle sigevent, Func <object, bool> sigeventHandler, object handlerData = null) { if (disposed) { throw new ObjectDisposedException("BPS"); } if (sigevent == null) { throw new ArgumentNullException("sigevent"); } if (sigevent.IsInvalid) { throw new ArgumentException("Sigevent is invalid"); } if (sigeventHandler == null) { throw new ArgumentNullException("sigeventHandler"); } var toSerialize = handlerData == null ? sigeventHandler : (object)new object[] { sigeventHandler, handlerData }; var data = Util.SerializeToPointer(toSerialize); if (data == IntPtr.Zero) { return(false); } var handle = sigevent.DangerousGetHandle(); var success = bps_add_sigevent_handler(handle, HandleSigevent, data) == BPS_SUCCESS; if (success) { handleToStructPointer.Add(handle, data); allocatedPointers.Add(data); } else { Util.FreeSerializePointer(data); } return(success); }