コード例 #1
0
        /// <summary>
        /// Handler for all messages received across the cluster.
        /// TODO: should just be sent to the kernel
        /// </summary>
        void ClusterMessage_Received(ClusterMessage msg)
        {
            // keep track of all nodes detected, and announce ourselves
            // whenever a new node is discovered
            if (msg is HelloClusterMessage)
            {
                ClusterNode node = null;
                node = (msg as HelloClusterMessage).Node;
                if (node == null)
                {
                    return;
                }

                lock (Current)
                {
                    if (Current.Nodes.Contains(node) == false)
                    {
                        // this is for testing
                        Parent.Console.Add("Detected new node: " + node.ToString());

                        // announce to this specific ip in case it can't hear the broadcasts
                        if (node != ClusterNode.Local)
                        {
                            ClusterClient.Instance.Send(node.IP, new HelloClusterMessage()
                            {
                                Node = ClusterNode.Local
                            });
                        }

                        // add to the list
                        Current.Nodes.Add(node);
                    }
                }

                node.LastHeardFrom = DateTime.Now;
            }
            else if (msg is OSCClusterMessage)
            {
                // TODO: send this value to the OSC manager
                var oscMessage = msg as OSCClusterMessage;
                if (oscMessage == null)
                {
                    return;
                }

                Parent.OSC.FromCluster(oscMessage.OSCAddress, oscMessage.OSCValues);

                // TODO: cause implant events to notice this new value
            }
        }