public static int ForwardEvent(MamaQueueEventCallback callback, object closure, IntPtr nativeHandle, MamaQueue sender) { // Create a new forwarder object to manage the .Net callback objects EnqueueEventForwarder forwarder = new EnqueueEventForwarder(callback, closure, sender); /* Invoke the native method, the index into the array will be passed as the clousure. */ return(NativeMethods.mamaQueue_enqueueEvent(nativeHandle, forwarder.NativeCallback, new IntPtr(forwarder.mIndex))); }
private static EnqueueEventForwarder GetForwarder(long key) { // Returns EnqueueEventForwarder ret = null; // Acquire the mutex mEventMutex.WaitOne(); // Obtain the forwarder from the dictionary ret = (EnqueueEventForwarder)mEventList[key]; // Release the mutex mEventMutex.ReleaseMutex(); return(ret); }
/// <summary> /// This function will enqueue an event on the mama queue. /// </summary> /// <param name="callback"> /// This callback will be invoked by the thread pumping the queue. /// </param> /// <param name="closure"> /// Utility object that will be passed back to the callback. /// </param> /// <exception cref="ArgumentNullException"> /// Thrown if the callback object is null. /// </exception> public void enqueueEvent(MamaQueueEventCallback callback, object closure) { // Verify that the callback object has been supplied if (callback == null) { throw new ArgumentNullException("callback"); } // Make sure the queue has been created EnsurePeerCreated(); // Create a new forwarder object to manage the .Net callback objects int code = EnqueueEventForwarder.ForwardEvent(callback, closure, nativeHandle, this); // Chek that the return code CheckResultCode(code); }
private static long AddForwarder(EnqueueEventForwarder forwarder) { // Returns long ret = mNextKey; // Acquire the mutex mEventMutex.WaitOne(); // Add the forwarder to the list mEventList.Add(mNextKey, forwarder); // Increment the next key index mNextKey++; // Release the mutex mEventMutex.ReleaseMutex(); return(ret); }
/// <summary> /// This function is called by the underlying C layer whenever an event is processed. /// </summary> /// <param name="queue"> /// The queue. /// </param> /// <param name="closure"> /// Utility object passed to mamaQueue_enqueueEvent. /// </param> internal static void OnEvent(IntPtr queue, IntPtr closure) { // Get the forward object from the event list EnqueueEventForwarder forwarder = GetForwarder(closure.ToInt32()); if (forwarder != null) { // Only invoke the callback object if it is valid. if (forwarder.mCallback != null) { /* Invoke the user supplied callback passing in the original closure, the one * sent up from the C layer is ignored as it will not be a valid .Net object. */ forwarder.mCallback.onEvent(forwarder.mSender, forwarder.mClosure); } // Remove the reference from the event list RemoveForwarder(forwarder.mIndex); } }
public static extern int mamaQueue_enqueueEvent( IntPtr nativeHandle, EnqueueEventForwarder.EnqueueCallback callback, IntPtr closure);
public static int ForwardEvent(MamaQueueEventCallback callback, object closure, IntPtr nativeHandle, MamaQueue sender) { // Create a new forwarder object to manage the .Net callback objects EnqueueEventForwarder forwarder = new EnqueueEventForwarder(callback, closure, sender); /* Invoke the native method, the index into the array will be passed as the clousure. */ return NativeMethods.mamaQueue_enqueueEvent(nativeHandle, forwarder.NativeCallback, new IntPtr(forwarder.mIndex)); }
private static long AddForwarder(EnqueueEventForwarder forwarder) { // Returns long ret = mNextKey; // Acquire the mutex mEventMutex.WaitOne(); // Add the forwarder to the list mEventList.Add(mNextKey, forwarder); // Increment the next key index mNextKey ++; // Release the mutex mEventMutex.ReleaseMutex(); return ret; }