private static uint KeepListener( GLib.Signal.EmissionHook listener, string objType, string signalName) { GLib.GType type = GLib.GType.FromName(objType); if (type != GLib.GType.Invalid) { //FIXME: drop this workaround for bug#386950 if (signalName.Contains("property")) { return(0); } lock (listenerListSync) { ListenerInfo info = new ListenerInfo(); info.Id = (uint)ListenerList.Count + 1; info.SignalName = signalName; info.Type = type; info.HookId = GLib.Signal.AddEmissionHook(signalName, type, listener); ListenerList.Add(info.Id, info); return(info.Id); } } else { throw new NotSupportedException("Invalid object type " + objType); } }
/// <summary> /// Returns a MessageStreamListener instance based on this instance's configuration (timeout, bucket name etc.) /// /// When multiple listeners are requested with the exact same parameters (usually when multiple clients are instantiated from the same configuration), /// the same listener will be returned each time. /// </summary> /// <returns></returns> private MessageStreamListener GetPooledListener() { // create a unique key based on the parameters // to find out if we already have a listener attached to this pool var hcc = new HashCodeCombiner(); hcc.Add(this.Timeout); hcc.Add(this.DeadTimeout); hcc.Add(this.RetryCount); hcc.Add(this.RetryTimeout.GetHashCode()); hcc.Add(this.bucketName.GetHashCode()); if (credential != null) { hcc.Add((this.credential.UserName ?? String.Empty).GetHashCode()); hcc.Add((this.credential.Password ?? String.Empty).GetHashCode()); hcc.Add((this.credential.Domain ?? String.Empty).GetHashCode()); } for (var i = 0; i < this.poolUrls.Length; i++) { hcc.Add(this.poolUrls[i].GetHashCode()); } var hash = hcc.CurrentHash; MessageStreamListener retval; lock (ListenerSync) if (listeners.TryGetValue(hash, out retval)) { listenerRefs[retval].RefCount++; retval.Subscribe(this.HandleMessage); } else { var name = this.bucketName; // create a new listener for the pool urls retval = new MessageStreamListener(poolUrls, heartbeatUri, heartbeatInterval, isHeartbeatEnabled, (client, root) => ResolveBucketUri(client, root, name)); retval.ConnectionTimeout = this.Timeout; retval.DeadTimeout = this.DeadTimeout; retval.Credentials = this.credential; retval.RetryCount = this.RetryCount; retval.RetryTimeout = this.RetryTimeout; retval.Subscribe(this.HandleMessage); listeners[hash] = retval; listenerRefs[retval] = new ListenerInfo { RefCount = 1, HashKey = hash }; retval.Start(); } return(retval); }
/// <summary> /// Thread method for a single listener thread /// </summary> private void ListenerThreadProc(object listenerInfo) { ListenerInfo myListenerInfo = (ListenerInfo)listenerInfo; try { NamedPipeServerStream serverPipe = new NamedPipeServerStream(_pipeName, PipeDirection.InOut, _maxClients, PipeTransmissionMode.Byte, PipeOptions.Asynchronous); serverPipe.WaitForConnection(); _logger.InfoFormat("New client connection to '{0}'", _pipeName); //Once the client is connected we "convert" the listener to a simple connection, //there is no need to know afterwards that this was a Listener...sometime ago... NamedPipeConnection pipe = new NamedPipeConnection(serverPipe); RaiseClientConnectedEvent(pipe); lock (_listeners) { _listeners.Remove(myListenerInfo); } Listen(); } catch (ThreadAbortException) { } }
public static void UnRegisterEvent(string eventType, MethodInfo methodInfo, object listener) { if (!listenerMap.ContainsKey(eventType)) { return; } List <ListenerInfo> listenInfos = listenerMap[eventType]; int count = listenInfos.Count; for (int i = 0; i < count; ++i) { ListenerInfo listenerInfo = listenInfos[i]; if (methodInfo == null) { if (listenerInfo.listener == listener) { listenInfos.Remove(listenerInfo); break; } } else { if (listenerInfo.listener == listener && listenerInfo.methodInfo == methodInfo) { listenInfos.Remove(listenerInfo); break; } } } }
private void InitListener() { string hostName = Dns.GetHostName(); IPAddress[] ipasAddresses = Dns.GetHostAddresses(hostName); List <IPAddress> list = new List <IPAddress>(ipasAddresses) { IPAddress.Parse("127.0.0.1") }; _Listeners = new List <ISocketListener>(list.Count); foreach (IPAddress ipa in list) { ListenerInfo info = new ListenerInfo() { BackLog = Config.BackLog, EndPoint = new IPEndPoint(ipa, Config.ListenPort) }; ISocketListener socketListener = new TcpSocketListener(info); socketListener.NewClientAccepted += tcpSocketListener_NewClientAccepted; socketListener.Error += tcpSocketListener_Error; socketListener.Stopped += tcpSocketListener_Stopped; socketListener.Start(); _Listeners.Add(socketListener); } }
public bool Check() { bool didAnything = false; foreach (IWorldComm comms in m_modules) { if (comms.HasMessages()) { while (comms.HasMessages()) { ListenerInfo lInfo = (ListenerInfo)comms.GetNextMessage(); //Deliver data to prim's listen handler object[] resobj = new object[] { new LSL_Types.LSLInteger(lInfo.GetChannel()), new LSL_Types.LSLString(lInfo.GetName()), new LSL_Types.LSLString(lInfo.GetID().ToString()), new LSL_Types.LSLString(lInfo.GetMessage()) }; m_ScriptEngine.PostScriptEvent( lInfo.GetItemID(), lInfo.GetHostID(), new EventParams( "listen", resobj, new DetectParams[0]), EventPriority.Suspended); } didAnything = true; } } return(didAnything); }
public void Register( UOSEventListener listener, UpDevice device, string driver, string instanceId = null, string eventKey = null, IDictionary <string, object> parameters = null) { // If the listener is already registered it cannot be registered again string eventIdentifier = GetEventIdentifier(device, driver, instanceId, eventKey); logger.Log("Registering listener for event :" + eventIdentifier); List <ListenerInfo> list; if (!listenerMap.TryGetValue(eventIdentifier, out list)) { list = null; } if (FindListener(listener, list) == null) { ListenerInfo info = new ListenerInfo(); info.driver = driver; info.instanceId = instanceId; info.eventKey = eventKey; info.listener = listener; info.device = device; RegisterNewListener(device, parameters, eventIdentifier, info); } }
public void Check() { foreach (IWorldComm comms in m_modules) { if (comms.HasMessages()) { while (comms.HasMessages()) { ListenerInfo lInfo = (ListenerInfo)comms.GetNextMessage(); //Deliver data to prim's listen handler object[] resobj = new object[] { new LSL_Types.LSLInteger(lInfo.GetChannel()), new LSL_Types.LSLString(lInfo.GetName()), new LSL_Types.LSLString(lInfo.GetID().ToString()), new LSL_Types.LSLString(lInfo.GetMessage()) }; m_ScriptEngine.PostScriptEvent( lInfo.GetItemID(), lInfo.GetHostID(), new EventParams( "listen", resobj, new DetectParams[0])); } } } }
private ListenerInfo GetListenerInfo(Control listener) { lock (listenerInfoLockObject) { var listenerType = listener.GetType(); if (!types.ContainsKey(listenerType)) { var listenerInfo = new ListenerInfo { Interfaces = new List <InterfaceInfo>() }; var interfaces = listenerType.GetInterfaces().Where(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IListener <>)); foreach (var intf in interfaces) { var dataType = intf.GetGenericArguments()?.Count() == 1 ? intf.GetGenericArguments()[0] : null; if (dataType != null) { var packageType = typeof(List <>).MakeGenericType(dataType); var method = intf.GetMethod(nameof(IListener <object> .DataReceived)); if (packageType != null && method != null) { listenerInfo.Interfaces.Add(new InterfaceInfo { DataType = dataType, PackageType = packageType, Method = method }); } } } types.Add(listenerType, listenerInfo); return(listenerInfo); } return(types[listenerType]); } }
public async Task ReadAsyncLong_Commands_Back() { var factory = _eventBusImpl.Factory; var connection = factory.CreateConnection(); var channel = connection.CreateModel(); var queueInfo = ListenerInfo.FromCommand(typeof(TestCommand)); string jsonResult = String.Empty; var ouOk = channel.QueueDeclare(queue: queueInfo.QueueName, durable: false, exclusive: false, autoDelete: false, arguments: null); var consumer = new AsyncEventingBasicConsumer(channel); Console.WriteLine($"Read QN: {ouOk.QueueName} CC: {ouOk.ConsumerCount} MC: {ouOk.MessageCount}"); consumer.Received += ConsumerOnReceived; for (int j = 0; j < 3; j++) { var message = "Message Id: " + j + " " + RandomMessageGenerator(); _eventBusImpl.Send(new TestCommand() { AggregateId = Guid.NewGuid(), Version = j, Message = message }); channel.BasicConsume(queue: queueInfo.RoutingKey, autoAck: true, consumer: consumer); } Thread.Sleep(5000); }
public void CheckListeners() { if (m_CmdManager.m_ScriptEngine.World == null) { return; } if (m_commsPlugin != null) { while (m_commsPlugin.HasMessages()) { ListenerInfo lInfo = (ListenerInfo)m_commsPlugin.GetNextMessage(); //Deliver data to prim's listen handler object[] resobj = new object[] { new LSL_Types.LSLInteger(lInfo.GetChannel()), new LSL_Types.LSLString(lInfo.GetName()), new LSL_Types.LSLString(lInfo.GetID().ToString()), new LSL_Types.LSLString(lInfo.GetMessage()) }; foreach (IScriptEngine e in m_CmdManager.ScriptEngines) { e.PostScriptEvent( lInfo.GetItemID(), new EventParams( "listen", resobj, new DetectParams[0])); } } } }
/// <summary> /// Checks if the specified listener is compatible with the event. /// </summary> /// <param name="listener">The listener.</param> /// <param name="eventArgs">The <see cref="T:System.EventArgs" /> instance containing the event data.</param> /// <returns> /// <c>true</c> if the event is compatible with <paramref name="listener" />; otherwise, <c>false</c>. /// </returns> protected override bool OnChooseListener(ListenerInfo listener, EventArgs eventArgs) { var sourcePropName = (eventArgs as PropertyChangedEventArgs)?.PropertyName; return(base.OnChooseListener(listener, eventArgs) && ((PropertyListenerInfo)listener).PropertyName.Length == 0 || string.Equals(sourcePropName, ((PropertyListenerInfo)listener).PropertyName, StringComparison.Ordinal)); }
public override async Task Register(ListenerInfo request, IServerStreamWriter <Broadcast> responseStream, ServerCallContext context) { Console.WriteLine($"Listener named \"{request.Name}\" registered."); ListenerSkeleton skeleton = new ListenerSkeleton(request, responseStream); requests.Add(skeleton); await skeleton.DoWork(); }
public void ClearOnExitListeners() { ListenerInfo li = CurrentListenerInfo; if (li.OnExitListeners == null || li.OnExitListeners.Count == 0) { return; } li.OnExitListeners.Clear(); }
private InventoryAggregate(IEventStoreRepository eventStoreRepository) : base(eventStoreRepository) { _eventBus = new EventBusImpl(); Register <ItemAddedToInventory>(Apply); Register <ItemRemovedFromInventory>(Apply); Register <ItemUpdatedInInventory>(Apply); _eventBus.RegisterAsync(ListenerInfo.FromCommand(typeof(AddItemToInventoryCommand)), AddItemToInventoryCommand); _eventBus.RegisterAsync(ListenerInfo.FromCommand(typeof(RemoveItemFromInventory)), RemoveItemFromInventoryCommand); _eventBus.RegisterAsync(ListenerInfo.FromCommand(typeof(UpdateItemInInventory)), UpdateItemInInventoryCommand); }
private void OnBeginAcceptTcpClient(IAsyncResult ar) { if (Unloaded) { return; } ListenerInfo info = (ListenerInfo)ar.AsyncState; try { if (!info.Listener.Server.IsBound) { Bind(info, true); return; } if (Unloaded) // Check a second time because there's some delay. { return; } TcpClient client = info.Listener.EndAcceptTcpClient(ar); try { switch (info.Binding.Protocol) { case Protocols.Rfc2812: case Protocols.Rfc2812Ssl: Console.WriteLine("Client connecting from {0}.", client.Client.RemoteEndPoint); AcceptClient(client, info); break; case Protocols.InterServer: Console.WriteLine("Client connecting from {0}.", client.Client.RemoteEndPoint); AcceptServer(client, info); break; default: client.Close(); break; } } catch { client.Close(); } info.Listener.BeginAcceptTcpClient(OnBeginAcceptTcpClient, info); } catch { Bind(info, true); } }
public ListenerInfo GetListener(string id) { var found = Android.FindListener(id); if (found == null) { return(null); } return(ListenerInfo.Create(found)); }
/// <summary> /// /// </summary> /// <param name="objListenerInfo"></param> public void DeleteListener(ListenerInfo objListenerInfo) { Requires.NotNull(objListenerInfo); Requires.PropertyNotNegative(objListenerInfo, "ListenerID"); using (IDataContext ctx = DataContext.Instance()) { var rep = ctx.GetRepository <ListenerInfo>(); rep.Update(objListenerInfo); } }
/// <summary> /// Private method to remove the specified listener from the list of listeners /// on the specified source. /// </summary> /// <param name="listener">The object to remove as a listener.</param> private void PrivateRemoveListener(IWeakEventListener listener) { if (_list != null) { lock (SyncLock) { string propertyName = null; ListenerInfo toRemove = null; foreach (var list in _list) { foreach (var info in list.Value) { if (info.Listener == listener) { propertyName = list.Key; toRemove = info; break; } } if (!string.IsNullOrEmpty(propertyName)) { break; } } if (string.IsNullOrEmpty(propertyName)) { return; } _list[propertyName].Remove(toRemove); if (_list[propertyName].Count == 0) { _list.Remove(propertyName); } var checkInstance = _list.Any( l => l.Value.Any( i => i.InstanceReference != null && i.InstanceReference.IsAlive && i.InstanceReference.Target != null && i.InstanceReference.Target.Equals(toRemove.InstanceReference.Target))); if (!checkInstance) { StopListening((INotifyPropertyChanged)toRemove.InstanceReference.Target); } } } }
/// <summary> /// /// </summary> /// <param name="objListenerInfo"></param> /// <returns></returns> public int AddListener(ListenerInfo objListenerInfo) { Requires.NotNull(objListenerInfo); Requires.PropertyNotNegative(objListenerInfo, "PortalID"); using (IDataContext ctx = DataContext.Instance()) { var rep = ctx.GetRepository <ListenerInfo>(); rep.Insert(objListenerInfo); return(objListenerInfo.ListenerID); } }
public void AddOnExitListener(IOnExitListener l) { ListenerInfo li = CurrentListenerInfo; if (li.OnExitListeners == null) { li.OnExitListeners = new List <IOnExitListener>(); } if (!li.OnExitListeners.Contains(l)) { li.OnExitListeners.Add(l); } }
public void Read_Commands_Back() { _eventBusImpl.Register <TestCommand>(ListenerInfo.FromCommand(typeof(TestCommand)), Callback); for (int j = 0; j < 3; j++) { var message = "Message Id: " + j + " " + RandomMessageGenerator(); _eventBusImpl.Send(new TestCommand() { AggregateId = Guid.NewGuid(), Version = 1, Message = message }); } Thread.Sleep(5000); }
/// <summary> /// Private method to remove the specified listener from the list of listeners /// on the specified source. /// </summary> /// <param name="listener">The object to remove as a listener.</param> private void PrivateRemoveListener(IWeakEventListener listener) { if (this.list != null) { lock (SyncLock) { string propertyName = null; ListenerInfo toRemove = null; foreach (KeyValuePair <string, List <ListenerInfo> > list in this.list) { foreach (ListenerInfo info in list.Value.Where(info => info.Listener == listener)) { propertyName = list.Key; toRemove = info; break; } if (!string.IsNullOrEmpty(propertyName)) { break; } } if (string.IsNullOrEmpty(propertyName)) { return; } this.list[propertyName].Remove(toRemove); if (this.list[propertyName].Count == 0) { this.list.Remove(propertyName); } bool checkInstance = this.list.Any( l => l.Value.Any( i => i.InstanceReference != null && i.InstanceReference.IsAlive && i.InstanceReference.Target != null && i.InstanceReference.Target.Equals( toRemove.InstanceReference.Target))); if (!checkInstance) { this.StopListening((INotifyPropertyChanged)toRemove.InstanceReference.Target); } } } }
private void Bind(ListenerInfo info, bool rebind) { if (Unloaded) { return; } if (rebind) { Console.WriteLine("Appear to have lost a binding. Rebinding."); } info.Listener.Start(info.Binding.Backlog); info.Listener.BeginAcceptTcpClient(OnBeginAcceptTcpClient, info); }
private Call BuildRegisterCall(IDictionary <string, object> parameters, ListenerInfo info) { Call serviceCall = new Call(info.driver, REGISTER_LISTENER_SERVICE, info.instanceId); serviceCall.AddParameter(REGISTER_EVENT_LISTENER_EVENT_KEY_PARAMETER, info.eventKey); if (parameters != null) { foreach (var pair in parameters) { if (pair.Key.Equals(REGISTER_EVENT_LISTENER_EVENT_KEY_PARAMETER, System.StringComparison.InvariantCultureIgnoreCase)) { throw new System.ArgumentException("Can't use reserved keys as parameters for registerForEvent"); } serviceCall.AddParameter(pair.Key, pair.Value); } } return(serviceCall); }
private void UnregisterForEvent(ListenerInfo listenerInfo) { // Send the event register request to the called device Call call = new Call(listenerInfo.driver, UNREGISTER_LISTENER_SERVICE, listenerInfo.instanceId); call.AddParameter(REGISTER_EVENT_LISTENER_EVENT_KEY_PARAMETER, listenerInfo.eventKey); Response response = CallService(listenerInfo.device, call); if (response == null) { throw new ServiceCallException("No response receive from unregister service call."); } if (!string.IsNullOrEmpty(response.error)) { throw new ServiceCallException(response.error); } }
private static Action <ListenOptions> ConfigureKestrelForSsl(ListenerInfo info) { return(options => { X509Store store = new X509Store(info.SslCertStoreName, StoreLocation.LocalMachine); store.Open(OpenFlags.ReadOnly); foreach (var cert in store.Certificates) { if (string.Equals(cert.Subject, info.SslCertSubject, StringComparison.InvariantCultureIgnoreCase)) { options.UseHttps(cert); break; } } }); }
public static void PublishEvent(string eventType, object sender, object eventArg) { if (!listenerMap.ContainsKey(eventType)) { return; } List <ListenerInfo> listenInfos = listenerMap[eventType]; ListenerInfo[] listenInfoArr = new ListenerInfo[listenInfos.Count]; listenInfos.CopyTo(listenInfoArr); foreach (ListenerInfo listenerInfo in listenInfoArr) { object[] objs = null; if (listenerInfo.methodInfo.GetParameters().Length != 0) { objs = new object[] { sender, eventArg }; } listenerInfo.methodInfo.Invoke(listenerInfo.listener, objs); } }
private void AcceptClient(TcpClient client, ListenerInfo info) { IPEndPoint ep = (IPEndPoint)client.Client.RemoteEndPoint; if (IsKLined(ep.Address)) { Console.WriteLine("Client is K:lined! Dropping."); client.Close(); return; } string ip = ep.Address.ToString(); HostMask mask = HostMask.Parse("*!:" + ep.Port + "@" + ip); mask.Account = "/" + ip; LocalUser user = new LocalUser(this, client, mask, info.Binding.Protocol == Protocols.Rfc2812 ? false : true); user.Start(); UsersByMask.Add(user.Mask, user); }
/// <summary> /// Starts the listening process /// </summary> /// <remarks> /// This method is also called internally after a client connection has been /// established, to refresh the count of listeners /// </remarks> public void Listen() { lock (_listeners) { int listenersToStart = Math.Max(0, _maxClients - _listeners.Count); if (_alwaysListeningClients != null) { listenersToStart = Math.Min(_alwaysListeningClients.Value, listenersToStart); } _logger.InfoFormat("Starting {0}-Listeners on pipe '{1}'", listenersToStart, _pipeName); for (int listenerCounter = 0; listenerCounter < listenersToStart; listenerCounter++) { Thread listenerThread = new Thread(new ParameterizedThreadStart(ListenerThreadProc)); ListenerInfo currentListenerInfo = new ListenerInfo(DateTime.Now, listenerThread); _listeners.Add(currentListenerInfo); listenerThread.Start(currentListenerInfo); } } }
private static uint KeepListener ( GLib.Signal.EmissionHook listener, string objType, string signalName, string hookData) { GLib.GType type = GLib.GType.FromName (objType); if (type != GLib.GType.Invalid) { lock (listenerListMutex) { ListenerInfo info = new ListenerInfo(); info.Id = (uint) ListenerList.Count + 1; info.SignalName = signalName; info.Type = type; info.HookId = GLib.Signal.AddEmissionHook (signalName, type, listener); ListenerList.Add (info.Id, info); return info.Id; } } else { throw new NotSupportedException ("Invalid object type " + objType); } }
/// <summary> /// Returns a MessageStreamListener instance based on this instance's configuratino (timeout, bucket name etc.) /// /// When multiple listeners are requested with the exact same parameters (usually when multiple clients are instantiated from the same configuration), /// the same listener will be returned each time. /// </summary> /// <returns></returns> private MessageStreamListener GetPooledListener() { // create a unique key based on the parameters // to find out if we already have a listener attached to this pool var hcc = new HashCodeCombiner(); hcc.Add(this.Timeout); hcc.Add(this.DeadTimeout); hcc.Add(this.RetryCount); hcc.Add(this.RetryTimeout.GetHashCode()); hcc.Add(this.bucketName.GetHashCode()); if (credential != null) { hcc.Add((this.credential.UserName ?? String.Empty).GetHashCode()); hcc.Add((this.credential.Password ?? String.Empty).GetHashCode()); hcc.Add((this.credential.Domain ?? String.Empty).GetHashCode()); } for (var i = 0; i < this.poolUrls.Length; i++) hcc.Add(this.poolUrls[i].GetHashCode()); var hash = hcc.CurrentHash; MessageStreamListener retval; lock (ListenerSync) if (listeners.TryGetValue(hash, out retval)) { listenerRefs[retval].RefCount++; retval.Subscribe(this.HandleMessage); } else { var name = this.bucketName; // create a new listener for the pool urls retval = new MessageStreamListener(poolUrls, (client, root) => ResolveBucketUri(client, root, name)); retval.Timeout = this.Timeout; retval.DeadTimeout = this.DeadTimeout; retval.Credentials = this.credential; retval.RetryCount = this.RetryCount; retval.RetryTimeout = this.RetryTimeout; retval.Subscribe(this.HandleMessage); listeners[hash] = retval; listenerRefs[retval] = new ListenerInfo { RefCount = 1, HashKey = hash }; retval.Start(); } return retval; }
private void UnregisterForEvent(ListenerInfo listenerInfo) { // Send the event register request to the called device Call call = new Call(listenerInfo.driver, UNREGISTER_LISTENER_SERVICE, listenerInfo.instanceId); call.AddParameter(REGISTER_EVENT_LISTENER_EVENT_KEY_PARAMETER, listenerInfo.eventKey); Response response = CallService(listenerInfo.device, call); if (response == null) throw new ServiceCallException("No response receive from unregister service call."); if (!string.IsNullOrEmpty(response.error)) throw new ServiceCallException(response.error); }
public override void Restart() { Stop(); Remotes.Clear(); ConnectRemotes(Odd); try { foreach (Binding b in Settings.Bindings) { for (int i = 0; i < b.Interfaces.Length; i++) { try { IPAddress ip; if (!IPAddress.TryParse(b.Interfaces[i], out ip)) { Console.WriteLine("Skipping invalid interface: {0}", b.Interfaces[i]); continue; } ListenerInfo listener = new ListenerInfo(new TcpListener(ip, b.Port), b); Bind(listener, false); Listeners.Add(listener); } catch (Exception ex) { Console.WriteLine("Error binding to interface: {0}", ex.Message); } } } } catch (Exception ex) { Console.WriteLine("Unable to read bindings from settings. Cannot receive incoming connections! ({0})", ex.Message); } }
/// <summary> /// Starts the listening process /// </summary> /// <remarks> /// This method is also called internally after a client connection has been /// established, to refresh the count of listeners /// </remarks> public void Listen() { lock (_listeners) { int listenersToStart = Math.Max(0, _maxClients - _listeners.Count); if (_alwaysListeningClients != null) listenersToStart = Math.Min(_alwaysListeningClients.Value, listenersToStart); _logger.InfoFormat("Starting {0}-Listeners on pipe '{1}'", listenersToStart, _pipeName); for (int listenerCounter = 0; listenerCounter < listenersToStart; listenerCounter++) { Thread listenerThread = new Thread(new ParameterizedThreadStart(ListenerThreadProc)); ListenerInfo currentListenerInfo = new ListenerInfo(DateTime.Now, listenerThread); _listeners.Add(currentListenerInfo); listenerThread.Start(currentListenerInfo); } } }
private void AcceptServer(TcpClient client, ListenerInfo info) { // TODO }
private Call BuildRegisterCall(IDictionary<string, object> parameters, ListenerInfo info) { Call serviceCall = new Call(info.driver, REGISTER_LISTENER_SERVICE, info.instanceId); serviceCall.AddParameter(REGISTER_EVENT_LISTENER_EVENT_KEY_PARAMETER, info.eventKey); if (parameters != null) { foreach (var pair in parameters) { if (pair.Key.Equals(REGISTER_EVENT_LISTENER_EVENT_KEY_PARAMETER, System.StringComparison.InvariantCultureIgnoreCase)) throw new System.ArgumentException("Can't use reserved keys as parameters for registerForEvent"); serviceCall.AddParameter(pair.Key, pair.Value); } } return serviceCall; }
public void Register( UOSEventListener listener, UpDevice device, string driver, string instanceId = null, string eventKey = null, IDictionary<string, object> parameters = null) { // If the listener is already registered it cannot be registered again string eventIdentifier = GetEventIdentifier(device, driver, instanceId, eventKey); logger.Log("Registering listener for event :" + eventIdentifier); List<ListenerInfo> list; if (!listenerMap.TryGetValue(eventIdentifier, out list)) list = null; if (FindListener(listener, list) == null) { ListenerInfo info = new ListenerInfo(); info.driver = driver; info.instanceId = instanceId; info.eventKey = eventKey; info.listener = listener; info.device = device; RegisterNewListener(device, parameters, eventIdentifier, info); } }
private static uint KeepListener ( GLib.Signal.EmissionHook listener, string objType, string signalName) { GLib.GType type = GLib.GType.FromName (objType); if (type != GLib.GType.Invalid) { //FIXME: drop this workaround for bug#386950 if (signalName.Contains ("property")) return 0; lock (listenerListSync) { ListenerInfo info = new ListenerInfo(); info.Id = (uint) ListenerList.Count + 1; info.SignalName = signalName; info.Type = type; info.HookId = GLib.Signal.AddEmissionHook (signalName, type, listener); ListenerList.Add (info.Id, info); return info.Id; } } else { throw new NotSupportedException ("Invalid object type " + objType); } }
private void SendRegister(UpDevice device, IDictionary<string, object> parameters, ListenerInfo info) { // Send the event register request to the called device Call serviceCall = new Call(info.driver, REGISTER_LISTENER_SERVICE, info.instanceId); serviceCall.AddParameter(REGISTER_EVENT_LISTENER_EVENT_KEY_PARAMETER, info.eventKey); if (parameters != null) { foreach (var pair in parameters) { if (pair.Key.Equals(REGISTER_EVENT_LISTENER_EVENT_KEY_PARAMETER, System.StringComparison.InvariantCultureIgnoreCase)) throw new System.ArgumentException("Can't use reserved keys as parameters for registerForEvent"); serviceCall.AddParameter(pair.Key, pair.Value); } } Response response = CallService(device, serviceCall); if (response == null) throw new System.Exception("No response received during register process."); else if (!string.IsNullOrEmpty(response.error)) throw new System.Exception(response.error); }
private void RegisterNewListener( UpDevice device, IDictionary<string, object> parameters, string eventIdentifier, ListenerInfo info) { if (device != null) SendRegister(device, parameters, info); // If the registry process goes ok, then add the listenner to the listener map List<ListenerInfo> listeners = null; if (!listenerMap.TryGetValue(eventIdentifier, out listeners)) listenerMap[eventIdentifier] = listeners = new List<ListenerInfo>(); listeners.Add(info); logger.Log("Registered listener for event :" + eventIdentifier); }