Esempio n. 1
0
        private void HandleWhisperMessage(NetMQMessage msg)
        {
            string whispertype = msg[3].ConvertToString();

            if (whispertype == Endpoint.Commands.REQ_FULL_GRAPH.ToString())
            {
                SendFullGraph();
            }
            else if (whispertype == Endpoint.Commands.SEND_GRAPH.ToString())
            {
                ReceivedGraph(_remoteEndpoints[new Guid(msg[1].Buffer)], msg[4].ConvertToString());
            }
            else if (whispertype == Endpoint.Commands.PLUG_MSG.ToString())
            {
                Log("Received remote message for local plug: " + msg.ToString());
                Message    remotemsg = Message.FromZyreWhisper(msg);
                OutputPlug outplug   = RemoteEndpoints[new Guid(msg[1].Buffer)].LocateOutputPlugAtAddress(remotemsg.address);
                outplug.Update(remotemsg);
            }
            else if (whispertype == Endpoint.Commands.PLUG_CONNECT.ToString())
            {
                Address inputaddress  = Address.FromFullPath(msg[4].ConvertToString());
                Address outputaddress = Address.FromFullPath(msg[5].ConvertToString());

                Log(string.Format("Remote request to connect O->:{0} to ->I:{1}", inputaddress.ToString(), outputaddress.ToString()));
                OutputPlug outplug = RemoteEndpoints[new Guid(msg[1].Buffer)].LocateOutputPlugAtAddress(outputaddress);
                InputPlug  inplug  = LocateInputPlugAtAddress(inputaddress);
                inplug.Connect(outplug);
            }
            else
            {
                Log("Unknown whisper type received for message " + msg.ToString());
            }
        }
Esempio n. 2
0
        public bool OnMouseUp(Vector2 p)
        {
            if (m_mdown)
            {
                m_mdown = false;
            }
            if (Test(p))
            {
                OutputPlug oplug = m_parent.GetEditorWindow().GetActiveOutputPlug();
                if (oplug != null)
                {
                    if (m_srcplug != null)
                    {
                        m_srcplug.RemoveTarget(this);          // disconnect
                    }
                    oplug.AddTarget(this);                     // Connect
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 3
0
        public OutputPlug LocateOutputPlugAtAddress(Address address)
        {
            Node       n = Nodes.Find(node => node.Name == address.node);
            OutputPlug p = n.Outputs.Find(outplug => outplug.Name == address.originPlug);

            return(Nodes.Find(node => node.Name == address.node)?.Outputs.Find(outplug => outplug.Name == address.originPlug));
        }
Esempio n. 4
0
        public OutputPlug AddOutput(string name)
        {
            OutputPlug oplug = new OutputPlug(this, 90, PlugCount() * 15 + 20, name);

            m_outplugs.Add(oplug);
            m_rect.height = PlugCount() * 15 + 20;
            return(oplug);
        }
Esempio n. 5
0
        private void ReceivedGraph(Endpoint remoteEndpoint, string graphjson)
        {
            Console.WriteLine("Got graph update from " + remoteEndpoint.Name);

            JsonSerializerSettings settings = new JsonSerializerSettings
            {
                ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
                ContractResolver    = new PrivateResolver()
            };

            List <GraphUpdate> remoteupdates = JsonConvert.DeserializeObject <List <GraphUpdate> >(graphjson, settings);

            foreach (GraphUpdate nodeupdate in remoteupdates)
            {
                //Create or retrieve current node
                Node activenode = remoteEndpoint.CreateNode(nodeupdate.node);

                var missingremoteinputs  = nodeupdate.node.Inputs.Where(i => i.destroyed);
                var missingremoteoutputs = nodeupdate.node.Outputs.Where(o => o.destroyed);

                var newremoteinputs  = nodeupdate.node.Inputs.Where(p => !activenode.Inputs.Any(l => p.Path == l.Path) && !p.destroyed);
                var newremoteoutputs = nodeupdate.node.Outputs.Where(p => !activenode.Outputs.Any(l => p.Path == l.Path) && !p.destroyed);

                //Remove old plugs from the local node
                foreach (InputPlug input in missingremoteinputs)
                {
                    InputPlug localinput = activenode.Inputs.Find(i => input.Name == i.Name);
                    localinput.Dispose();
                }

                foreach (OutputPlug output in missingremoteoutputs)
                {
                    OutputPlug localoutput = activenode.Outputs.Find(o => output.Name == o.Name);
                    localoutput.Dispose();
                }

                //Add new plugs to nodes.
                foreach (InputPlug newinput in newremoteinputs)
                {
                    activenode.CreateInputPlug(newinput);
                }

                foreach (OutputPlug newoutput in newremoteoutputs)
                {
                    activenode.CreateOutputPlug(newoutput);
                }
            }

            //Remove missing nodes that have disappeared from the remote endpoint
            var missingnodes = remoteEndpoint.Nodes.Where(p => !remoteupdates.Any(l => p.Name == l.node.Name));

            foreach (Node node in missingnodes)
            {
                node.Dispose();
            }

            Nodes.RemoveAll(n => missingnodes.Any(o => o.Name == n.Name));
        }
Esempio n. 6
0
        public override void PlugConnectionRequest(InputPlug input, OutputPlug output)
        {
            NetMQMessage msg = new NetMQMessage(3);

            msg.Append(Endpoint.Commands.PLUG_CONNECT.ToString());
            msg.Append(input.Path.ToString());
            msg.Append(output.Path.ToString());
            Whisper(Uuid, msg);
        }
Esempio n. 7
0
        public OutputPlug CreateOutputPlug(string plugname)
        {
            if (Outputs.Any(p => p.Name == plugname))
            {
                throw new ArgumentException("Output plug already exists!");
            }

            Endpoint.Log(String.Format("Creating output {0} for {1}", plugname, _name));
            OutputPlug output = new OutputPlug(plugname, this);

            _outputs.Add(output);
            Endpoint.UpdateGraph(this, GraphUpdate.UpdateType.UPDATED);
            return(output);
        }
Esempio n. 8
0
        public OutputPlug CreateOutputPlug(OutputPlug plug)
        {
            if (!Outputs.Any(p => p.Name == plug.Name))
            {
                plug.Owner = this;
                Outputs.Add(plug);
            }
            else
            {
                OutputPlug existing = Outputs.Find(p => p.Name == plug.Name);
                if (existing.Owner == null)
                {
                    existing.Owner = this;
                }
                return(existing);
            }

            return(plug);
        }
    void preset()
    {
        Node       node1 = AddNode("Node1");
        OutputPlug plug1 = node1.AddOutput("OutABC");

        node1.SetPos(10, 100);
        node1.AddInput("InABC");

        Node node2 = AddNode("Node2");

        node2.SetPos(250, 150);
        node2.AddOutput("OutDDD");
        InputPlug plug2 = node2.AddInput("InFFF");

        node2.AddInput("InGGG");

        plug1.AddTarget(plug2);         // Link

        Node node3 = AddNode("Node3");

        node3.AddOutput("OutHHH");
        node3.SetPos(10, 300);
    }
Esempio n. 10
0
        public void RegisterListener(InputPlug input, OutputPlug output)
        {
            if (!ConnectedInputs.ContainsKey(output.Path.ToString()))
            {
                ConnectedInputs.Add(output.Path.ToString(), new List <InputPlug>());
            }

            if (!ConnectedInputs[output.Path.ToString()].Contains(input))
            {
                ConnectedInputs[output.Path.ToString()].Add(input);
                Endpoint.RegisterListenerNode(this);
                Endpoint.CheckPolling();

                if (input.Owner.Endpoint != output.Owner.Endpoint)
                {
                    Endpoint.Log("In plug connection request");
                    Endpoint.PlugConnectionRequest(input, output);
                }
            }
            else
            {
                Endpoint.Log("Plug is already connected");
            }
        }
Esempio n. 11
0
 public void SetActiveOutputPlug(OutputPlug plug)
 {
     m_activePlug = plug;
 }
Esempio n. 12
0
    public void OnNodeGUI()
    {
        //Debug.Log("OnGUI Type=" + Event.current.type);

        if (s_boxNodeStyle == null)
        {
            s_boxNodeStyle = new GUIStyle(GUI.skin.box);
            s_boxNodeStyle.normal.background = MakeTex(2, 2, s_nodeBaseColor);
            s_boxNodeStyle.normal.textColor  = s_nodeTextColor;
        }
        if (s_boxOutputPlugStyle == null)
        {
            s_boxOutputPlugStyle = new GUIStyle(GUI.skin.box);
            s_boxOutputPlugStyle.normal.background = MakeTex(2, 2, s_outputPlugColor);
        }
        if (s_boxInputPlugStyle == null)
        {
            s_boxInputPlugStyle = new GUIStyle(GUI.skin.box);
            s_boxInputPlugStyle.normal.background = MakeTex(2, 2, s_inputPlugColor);
        }
        if (s_outputTextStyle == null)
        {
            s_outputTextStyle = new GUIStyle(GUI.skin.label);
            s_outputTextStyle.normal.textColor = s_outputTextColor;
            s_outputTextStyle.alignment        = TextAnchor.UpperRight;      // Right Align
        }
        if (s_inputTextStyle == null)
        {
            s_inputTextStyle = new GUIStyle(GUI.skin.label);
            s_inputTextStyle.normal.textColor = s_inputTextColor;
        }

        // Draw Lines
        for (int i = 0; i < m_nodes.Count; ++i)
        {
            m_nodes[i].DrawLines();
        }

        // Draw Nodes
        for (int i = 0; i < m_nodes.Count; ++i)
        {
            m_nodes[i].Layout();
        }

        // Node Events
        Vector2 mousePos = Event.current.mousePosition;

        if (Event.current.type == EventType.MouseDown)
        {
            m_oldMousePos = mousePos;
        }
        for (int i = m_nodes.Count - 1; i >= 0; --i)
        {
            Node node = m_nodes[i];

            bool r = false;
            if (Event.current.type == EventType.MouseDown)
            {
                r = node.OnMouseDown(mousePos);
            }
            else if (Event.current.type == EventType.MouseUp)
            {
                r = node.OnMouseUp(mousePos);
            }
            else if (Event.current.type == EventType.MouseDrag)
            {
                node.OnMouseDrag(mousePos, new Vector2(mousePos.x - m_oldMousePos.x, mousePos.y - m_oldMousePos.y));
            }
            if (r)
            {
                m_nodes.Add(node);
                m_nodes.RemoveAt(i);
                break;
            }
        }
        if (Event.current.type == EventType.MouseDrag)
        {
            m_oldMousePos = mousePos;
        }

        if (Event.current.type == EventType.MouseUp)
        {
            SetActiveOutputPlug(null);
        }

        OutputPlug activePlug = GetActiveOutputPlug();

        if (activePlug != null)
        {
            Vector2 sp = activePlug.GetPos();
            Vector2 ep = mousePos;
            drawLine(sp, ep, s_activeLineColor, 2);
        }
    }
Esempio n. 13
0
 public void SetSrcPlug(OutputPlug plug)
 {
     m_srcplug = plug;
 }
Esempio n. 14
0
 public abstract void PlugConnectionRequest(InputPlug input, OutputPlug output);
Esempio n. 15
0
 public override void PlugConnectionRequest(InputPlug input, OutputPlug output)
 {
     Log("Local endpoint trying to initiate remote plug connection. Triggered from remote endpoint connection. Can safely ignore.");
 }
Esempio n. 16
0
        public static void Main(string[] args)
        {
            string guid       = Guid.NewGuid().ToString();
            string endpointid = guid.Substring(Math.Max(0, guid.Length - 4));

            using (ZyreEndpoint local = new ZyreEndpoint(endpointid, (s) => { Console.WriteLine("LOCAL: " + s); }))
            {
                Console.WriteLine("Starting Showtime test");
                System.Threading.Thread.Sleep(1000);

                Console.Clear();

                Console.WriteLine("How many nodes to create?");
                CreateNodes(local, 2);
                LinkNodesInChain(local);

                Console.WriteLine("Connect to local or remote? (l/r)");
                Endpoint targetEndpoint = null;
                while (targetEndpoint == null)
                {
                    char key = Console.ReadKey().KeyChar;
                    Console.WriteLine("");
                    if (key == 'l')
                    {
                        targetEndpoint = local;

                        Console.WriteLine("Test node chain?");
                        if ((Console.ReadKey().KeyChar == 'y') ? true : false)
                        {
                            LinkNodesInChain(targetEndpoint);
                            TestNodeLink(targetEndpoint);
                        }
                    }
                    else if (key == 'r')
                    {
                        local.StartZyre();
                        local.ListNodes();
                        Console.WriteLine("Waiting for remote nodes...");

                        while (local.RemoteEndpoints.Values.Count == 0)
                        {
                            System.Threading.Thread.Sleep(100);
                        }

                        foreach (Endpoint remoteEndpoint in local.RemoteEndpoints.Values)
                        {
                            targetEndpoint = remoteEndpoint;
                            break;
                        }
                    }
                    else
                    {
                        Console.WriteLine(string.Format("Didn't understand input \'{0}\'. Please enter l or r", key));
                    }
                }

                //Setup message test
                local.ListNodes();
                Console.WriteLine("\nEnter index of source node");
                Node outnode = local.Nodes[int.Parse(Console.ReadLine())];

                outnode.ListOutputs();
                Console.WriteLine("\nEnter index of source plug");
                OutputPlug output = outnode.Outputs[int.Parse(Console.ReadLine())];

                targetEndpoint.ListNodes();
                Console.WriteLine("\nEnter index of destination node");
                Node innode = targetEndpoint.Nodes[int.Parse(Console.ReadLine())];

                innode.ListInputs();
                Console.WriteLine("\nEnter index of destination plug");
                InputPlug input = innode.Inputs[int.Parse(Console.ReadLine())];


                Console.WriteLine(string.Format("About to connect {0} -> {1}", output.Path, input.Path));
                input.Connect(output);

                System.Threading.Thread.Sleep(1000);

                do
                {
                    Console.WriteLine("\nEnter message:");
                    output.Update(Console.ReadLine());
                } while (Console.ReadKey(true).Key != ConsoleKey.Escape);


                Console.WriteLine("Testing local output removal");
                output.Dispose();

                Console.WriteLine("\nRemaining outputs:");
                outnode.ListOutputs();

                System.Threading.Thread.Sleep(1000);


                Console.WriteLine("Testing local node removal");
                outnode.Dispose();

                Console.WriteLine("\nRemaining nodes:");
                local.ListNodes();

                System.Threading.Thread.Sleep(1000);

                //local.Dispose();
            }
        }