コード例 #1
0
            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)));
            }
コード例 #2
0
            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);
            }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
            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);
            }
コード例 #5
0
            /// <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);
                }
            }
コード例 #6
0
ファイル: MamaQueue.cs プロジェクト: jacobraj/MAMA
 public static extern int mamaQueue_enqueueEvent(
     IntPtr nativeHandle,
     EnqueueEventForwarder.EnqueueCallback callback,
     IntPtr closure);
コード例 #7
0
ファイル: MamaQueue.cs プロジェクト: jacobraj/MAMA
            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));
            }
コード例 #8
0
ファイル: MamaQueue.cs プロジェクト: jacobraj/MAMA
            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;
            }