public SubscriberCallbackAttribute(Type eventType, 
     NotifyPriority priority = DEFAULT_PRIORITY, ThreadMode threadMode = DEFAULT_THREAD_MODE)
 {
     EventType = eventType;
     Priority = priority;
     ThreadMode = threadMode;
 }
 public SubscriberCallbackAttribute(Type eventType,
                                    NotifyPriority priority = DEFAULT_PRIORITY, ThreadMode threadMode = DEFAULT_THREAD_MODE)
 {
     EventType  = eventType;
     Priority   = priority;
     ThreadMode = threadMode;
 }
Exemplo n.º 3
0
 public AnonymousSubscriber(
     Action <T> action,
     ThreadMode threadMode,
     bool stack,
     IThreadHelper threadHelper)
     : base(Description.FromGeneric <T>(threadMode, stack), action, threadHelper)
 {
 }
Exemplo n.º 4
0
        //>>>>>>>>>>the slowest

        /*var target1 = Expression.Property(Expression.Constant(_subscriber), typeof(WeakReference), "Target");
         * var target = Expression.Constant(Subscriber);
         * MethodCallExpression methodCall = Expression.Call(target, method);
         * _callback = Expression.Lambda<Action>(methodCall).Compile();*/

        //>>>>>>>>>>it will keep the object reference
        //_callback = (Action) method.CreateDelegate(typeof(Action), Subscriber);

        //>>>>>>>>>30% slower than delegate
        //_callback = method.Invoke(Subscriber);

        public Subscription(object subscriber, MethodInfo method, Type eventType, NotifyPriority priority, ThreadMode threadMode)
        {
            _subscriber = new WeakReference(subscriber);
            Priority    = priority;
            EventType   = eventType;
            ThreadMode  = threadMode;
            InitMethod(subscriber, method);
        }
Exemplo n.º 5
0
 public static Description FromGeneric <T>(ThreadMode threadMode, bool stack)
 {
     return(new Description
     {
         ThreadMode = threadMode,
         ParameterType = typeof(T),
         Stack = stack
     });
 }
Exemplo n.º 6
0
        /// <summary>
        /// Register a <see cref="Action{T}"/> to listen to an incomming message.
        /// You should keep the instance of the <see cref="Action{T}"/> to unregister
        /// later if you need.
        /// </summary>
        /// <typeparam name="T">
        /// Type of incomming message which wants to receive.
        /// </typeparam>
        /// <param name="subscriberAction">
        /// The <see cref="Action{T}"/> will be called when the incomming message is reached.
        /// The message data will be passed to the argument of <see cref="subscriberAction"/>.
        /// </param>
        /// <param name="threadMode">
        /// Configure thead mode, see <see cref="ThreadMode"/> for more detail.
        /// </param>
        /// <param name="stack">
        /// If it's true, it itents to receive stacked messages.
        /// </param>
        public void Register <T>(Action <T> subscriberAction, ThreadMode threadMode, bool stack)
        {
            Precondition.ArgumentNotNull(subscriberAction, nameof(subscriberAction));

            lock (_subscriberList)
            {
                var subscriber = new AnonymousSubscriber <T>(subscriberAction, threadMode, stack, _threadHelper);
                RegisterSubscriber(subscriber);
            }
        }
Exemplo n.º 7
0
        //Перевод из режима расчета в строку
        public static string ToRussian(this ThreadMode m)
        {
            switch (m)
            {
            case ThreadMode.Periodic:
                return("Периодический");

            case ThreadMode.Single:
                return("Разовый");

            case ThreadMode.RealTime:
                return("Моментальный");

            case ThreadMode.Hand:
                return("Ручной");

            case ThreadMode.Error:
                return("");
            }
            return("");
        }
Exemplo n.º 8
0
        //Перевод из режима расчета в строку
        public static string ToCode(this ThreadMode m)
        {
            switch (m)
            {
            case ThreadMode.Periodic:
                return("Periodic");

            case ThreadMode.Single:
                return("Single");

            case ThreadMode.RealTime:
                return("RealTime");

            case ThreadMode.Hand:
                return("Hand");

            case ThreadMode.Error:
                return("");
            }
            return("");
        }
Exemplo n.º 9
0
        public static void ThrowManagedException(ThreadMode mode)
        {
            switch (mode)
            {
            case ThreadMode.MainThread:
                Exceptions.ThrowManagedExceptionThroughNativeCode();
                break;

            case ThreadMode.BackgroundThread:
                new Thread(Exceptions.ThrowManagedExceptionThroughNativeCode)
                {
                    IsBackground = true,
                }.Start();
                break;

            case ThreadMode.ThreadPool:
                ThreadPool.QueueUserWorkItem((v) => Exceptions.ThrowManagedExceptionThroughNativeCode());
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(mode), $"Unknown thread mode: ${mode}");
            }
        }
Exemplo n.º 10
0
 public EventMethodInfo(UnityEngine.Object subscribe, MethodInfo method, EventCode type, string methodName, ThreadMode mode, bool sticky)
 {
     this.Subscribe  = subscribe;
     this.Method     = method;
     this.EventType  = type;
     this.Mode       = mode;
     this.Sticky     = sticky;
     this.MethodName = methodName;
 }
Exemplo n.º 11
0
 /// <seealso cref="Register{T}(Action{T}, ThreadMode, bool)"/>
 public void Register <T>(Action <T> subscriberAction, ThreadMode threadMode)
 {
     Precondition.ArgumentNotNull(subscriberAction, nameof(subscriberAction));
     Register(subscriberAction, threadMode, false);
 }
Exemplo n.º 12
0

        
Exemplo n.º 13
0
 public SubscribeAttribute(ThreadMode mode = ThreadMode.Post)
 {
     ThreadMode = mode;
 }
Exemplo n.º 14
0
 /// <summary>
 /// Initializes a new <see cref="ThreadModeAttribute"/> and sets the <see cref="ThreadMode"/>.
 /// </summary>
 /// <param name="mode">The type's thread mode.</param>
 public ThreadModeAttribute(ThreadMode mode)
 {
     this.Mode = mode;
 }
Exemplo n.º 15
0
		public static extern bool FinalizeNexPlugin(); // 0x00F916C0-0x00F916E0
		public static bool InitializeNexAsync(out uint asyncId, ThreadMode threadMode, AsyncResultCB callback = null) {
			asyncId = default;
			return default;
		} // 0x00F916E0-0x00F916F0
Exemplo n.º 16
0
		} // 0x00F916E0-0x00F916F0
		public static extern bool InitializeNex(ThreadMode threadMode); // 0x00F91800-0x00F91820
Exemplo n.º 17
0
 public Subscribe(ThreadMode threadMode)
 {
     this.threadMode = threadMode;
 }
Exemplo n.º 18
0
 public SubscriberAttribute(ThreadMode ThreadMode = ThreadMode.Main)
 {
     this._threadMode = ThreadMode;
 }
Exemplo n.º 19
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="mode"></param>
 public ThreadModeAttribute(ThreadMode mode)
 {
     ThreadMode = mode;
 }