Exemplo n.º 1
0
        public static void EventDispatch(IntPtr sender, uint eventType, IntPtr eventData)
        {
            List <EventSubscription> eventReceivers;

            if (!eventReceiverLookup.TryGetValue(eventType, out eventReceivers))
            {
                // This should not happen, as event NET objects are subscribed to are filtered
                throw new InvalidOperationException("NativeCore.EventDispatch - received unregistered event type");
            }

            // iterate over copy of list so we can modify it while running
            ScriptVariantMap scriptMap       = null;
            NativeEventData  nativeEventData = null;

            AObject receiver;

            foreach (EventSubscription er in eventReceivers.ToList())
            {
                // GC'd?
                if (!er.Receiver.TryGetTarget(out receiver))
                {
                    continue;
                }

                if (er.Sender != IntPtr.Zero && er.Sender != sender)
                {
                    continue;
                }

                if (scriptMap == null)
                {
                    if (svmDepth == svmMax)
                    {
                        throw new InvalidOperationException("NativeCore.EventDispatch - exceeded max svm");
                    }

                    scriptMap = svm[svmDepth++];
                    scriptMap.CopyVariantMap(eventData);
                    nativeEventData = NativeEvents.GetNativeEventData(eventType, scriptMap);
                    nativeEventData.sourceEventData = eventData;
                }

                receiver.HandleEvent(eventType, scriptMap, nativeEventData);
            }

            if (scriptMap != null)
            {
                svmDepth--;

                if (nativeEventData != null)
                {
                    NativeEvents.ReleaseNativeEventData(nativeEventData);
                }
            }
        }
Exemplo n.º 2
0
        public static void EventDispatch(uint eventType, IntPtr eventData)
        {
            List <WeakReference <AObject> > eventReceivers;

            if (!eventReceiverLookup.TryGetValue(eventType, out eventReceivers))
            {
                // This should not happen, as event NET objects are subscribed to are filtered
                throw new System.InvalidOperationException("NativeCore.EventDispatch - received unregistered event type");
            }

            ScriptVariantMap scriptMap = null;
            AObject          receiver;

            // iterate over copy of list so we can modify it while running
            foreach (var w in eventReceivers.ToList())
            {
                // GC'd?
                if (!w.TryGetTarget(out receiver))
                {
                    continue;
                }

                if (scriptMap == null)
                {
                    if (svmDepth == svmMax)
                    {
                        throw new System.InvalidOperationException("NativeCore.EventDispatch - exceeded max svm");
                    }

                    scriptMap = svm[svmDepth++];
                    scriptMap.CopyVariantMap(eventData);
                }

                receiver.HandleEvent(eventType, scriptMap);
            }

            if (scriptMap != null)
            {
                svmDepth--;
            }
        }
Exemplo n.º 3
0
        public static void EventDispatch(IntPtr sender, uint eventType, IntPtr eventData)
        {
            List <EventSubscription> eventReceivers;

            if (!eventReceiverLookup.TryGetValue(eventType, out eventReceivers))
            {
                // This should not happen, as event NET objects are subscribed to are filtered
                throw new InvalidOperationException("NativeCore.EventDispatch - received unregistered event type");
            }

            AObject managedSender = null;
            WeakReference <RefCounted> wr;

            if (sender != IntPtr.Zero &&
                nativeLookup.TryGetValue(sender, out wr))
            {
                RefCounted refCounted;
                if (wr.TryGetTarget(out refCounted))
                {
                    managedSender = refCounted as AObject;
                }
            }

            // iterate over copy of list so we can modify it while running
            ScriptVariantMap scriptMap = null;
            AObject          receiver;

            foreach (EventSubscription er in eventReceivers.ToList())
            {
                // GC'd?
                if (!er.Receiver.TryGetTarget(out receiver))
                {
                    continue;
                }

                if (scriptMap == null)
                {
                    if (svmDepth == svmMax)
                    {
                        throw new InvalidOperationException("NativeCore.EventDispatch - exceeded max svm");
                    }

                    scriptMap = svm[svmDepth++];
                    scriptMap.CopyVariantMap(eventData);
                }

                if (managedSender != null && er.Sender == sender)
                {
                    receiver.HandleEvent(managedSender, eventType, scriptMap);
                }
                else if (er.Sender == IntPtr.Zero)
                {
                    receiver.HandleEvent(eventType, scriptMap);
                }
            }

            if (scriptMap != null)
            {
                svmDepth--;
            }
        }