public void Clear() { lock (CallbackTypes) { CallbackTypes.Clear(); Callbacks.Clear(); } }
public Callback Pop(CallbackTypes type) { if (!m_callbacks.ContainsKey(type)) return null; Callback result = m_callbacks[type]; m_callbacks.Remove(type); return result; }
public void Definition(INode node, IValuePortAttribute info) { Id = new PortId(node.NodeId, info.Name); Node = node; Name = info.Name; Direction = info.Direction; Capacity = info.Capacity; GraphPort = info.GraphPort; ValueType = typeof(T); if (info.CallbackInfo == null) { return; } var parameters = info.CallbackInfo.GetParameters(); if (parameters.Length > 0) { Debug.LogWarning($"ValuePort Callback for '{node}.{info.CallbackInfo.Name}' has {parameters.Length} parameter(s). Callback cannot accept any parameters"); return; } if (VoidType.IsAssignableFrom(info.CallbackInfo.ReturnType)) { _simpleCallback = (Action)info.CallbackInfo.CreateDelegate(SimpleCallbackType, node); _callbackType = CallbackTypes.Simple; } if (ValueType.IsAssignableFrom(info.CallbackInfo.ReturnType)) { _valueCallback = (Func <T>)info.CallbackInfo.CreateDelegate(ValueCallbackType, node); _callbackType = CallbackTypes.Value; } if (_callbackType == CallbackTypes.None) { Debug.LogWarning($"ValuePort Callback for '{node}.{info.CallbackInfo.Name}' did not have one of the following method signatures [Action, Func<T>]"); } }
public void Push(CallbackTypes type, Callback callback, string exception = "Callback already exists") { if (m_callbacks.ContainsKey(type)) { throw new InvalidOperationException(exception); } m_callbacks[type] = callback; }
public Callback Pop(CallbackTypes type) { if (!m_callbacks.ContainsKey(type)) { return(null); } Callback result = m_callbacks[type]; m_callbacks.Remove(type); return(result); }
public void Off(Guid id) { lock (CallbackTypes) { if (CallbackTypes.ContainsKey(id)) { var type = CallbackTypes[id]; lock (Callbacks) { Callbacks[type].Remove(id); } CallbackTypes.Remove(id); } } }
public void Definition(INode node, IFlowPortAttribute info) { Id = new PortId(node.NodeId, info.Name); Node = node; Name = info.Name; Direction = info.Direction; Capacity = info.Capacity; GraphPort = info.GraphPort; if (info.CallbackInfo == null) { return; } var parameters = info.CallbackInfo.GetParameters(); if (parameters.Length != 1) { Debug.LogWarning($"FlowPort Callback for '{node}.{info.CallbackInfo.Name}' has {parameters.Length} parameter(s). Can only accept 1 parameter of type 'IFlow'"); return; } var paramType = parameters[0].ParameterType; if (paramType != FlowType) { Debug.LogWarning($"FlowPort Callback for '{node}.{info.CallbackInfo.Name}' has 1 parameter that takes type '{paramType}'. Can only accept 1 parameter of type 'IFlow'"); return; } if (VoidType.IsAssignableFrom(info.CallbackInfo.ReturnType)) { _simpleCallback = (Action <IFlow>)info.CallbackInfo.CreateDelegate(SimpleCallbackType, node); _callbackType = CallbackTypes.Simple; } if (FlowPortType.IsAssignableFrom(info.CallbackInfo.ReturnType)) { _syncCallback = (Func <IFlow, IFlowPort>)info.CallbackInfo.CreateDelegate(SyncCallbackType, node); _callbackType = CallbackTypes.Sync; } if (EnumerableType.IsAssignableFrom(info.CallbackInfo.ReturnType)) { _asyncCallback = (Func <IFlow, IEnumerable>)info.CallbackInfo.CreateDelegate(AsyncCallbackType, node); _callbackType = CallbackTypes.Async; } if (_callbackType == CallbackTypes.None) { Debug.LogWarning($"FlowPort Callback for '{node}.{info.CallbackInfo.Name}' did not have one of the following method signatures [Action<IFlow>, Func<IFlow, IFlowPort>, Func<IFlow, IEnumerable>]"); } }
public Guid On <T>(Action <T> callback) { lock (Callbacks) { if (!Callbacks.ContainsKey(typeof(T))) { Callbacks.Add(typeof(T), new Dictionary <Guid, MulticastDelegate>()); } var id = Guid.NewGuid(); Callbacks[typeof(T)].Add(id, callback); lock (CallbackTypes) { CallbackTypes.Add(id, typeof(T)); } return(id); } }