private void ListenerWork() { while (_receiver.State != OscSocketState.Closed) { // if we are in a state to recieve if (_receiver.State == OscSocketState.Connected) { // get the next message // this will block until one arrives or the socket is closed OscPacket packet = _receiver.Receive(); // parse the message string[] msg = OscDeserializer.ParseOscPacket(packet); string[] msgAddress = OscDeserializer.GetMessageAddress(msg); var ip = OscDeserializer.GetMessageIp(msg); var port = OscDeserializer.GetMessagePort(msg); var binSeq = OscDeserializer.GetMessageBinSeq(msg); // if the sessionWorker already exists, update config. Otherwise, create a new sessionWorker SessionWorker session = CheckSession(ip, port); if (session == null) { session = new SessionWorker(ip, port, _dataPub, _sessionManager); _sessionManager.AddConnection(session); session.SetTimers(); } session.SetLookupFlags(binSeq); } } }
private void updateFlags() { var jointTypes = Enum.GetValues(typeof(JointType)); // Copy session workers so iteration doesnt break the collection SessionWorker[] workers = new SessionWorker[_sessionManager.OpenConnections.Count]; _sessionManager.OpenConnections.CopyTo(workers); foreach (SessionWorker sw in workers) { // Get the port and IP of this session string id = sw.Ip + ":" + sw.Port.ToString(); // Copy the flags ConfigFlags flags = sw.ConfigFlags; // Get the list of active joints List<string> jointList = new List<string>(); foreach (JointType jt in jointTypes) { if (flags.JointFlags[jt]) { jointList.Add(jt.ToString()); } } // If this session already exists update the flags if (_localSessions.Exists(tab => tab.Header == id)) { _localSessions.Find(tab => tab.Header.Equals(id)).displayFlags = flags.JointFlags; _localSessions.Find(tab => tab.Header.Equals(id)).Items = jointList; _localSessions.Find(tab => tab.Header.Equals(id)).Active = true; } else { TabData tabData = new TabData(id, jointList, flags.JointFlags, true); _localSessions.Add(tabData); } } updateTabs(); }
public void AddConnection(SessionWorker session) { _openConnections.Add(session); }