-
Notifications
You must be signed in to change notification settings - Fork 189
/
Pin.cs
118 lines (101 loc) · 2.95 KB
/
Pin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System;
using System.Runtime.InteropServices;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using SlimDX;
using VVVV.Core.Logging;
using VVVV.PluginInterfaces.V1;
using VVVV.PluginInterfaces.V2;
using VVVV.Utils.Streams;
using VVVV.Utils.VMath;
namespace VVVV.PluginInterfaces.V2
{
[ComVisible(false)]
public delegate void PinUpdatedEventHandler(object sender, EventArgs args);
[ComVisible(false)]
public delegate void PinConnectionEventHandler(object sender, PinConnectionEventArgs args);
[ComVisible(false)]
public class PinConnectionEventArgs : EventArgs
{
public IPin OtherPin
{
get;
private set;
}
public PinConnectionEventArgs(IPin otherPin)
{
OtherPin = otherPin;
}
}
[ComVisible(false)]
public class Pin<T> : Spread<T>, ISpread<T>, IDisposable
{
private readonly IIOFactory FFactory;
private readonly IPluginIO FPluginIO;
private bool FConnected;
public Pin(IIOFactory factory, IPluginIO pluginIO, MemoryIOStream<T> stream)
: base(stream)
{
FFactory = factory;
FPluginIO = pluginIO;
// Can be null in case of Texture and Mesh pins which call CreateTextureOutput2/CreateMeshOutput2 internally
if (pluginIO != null)
FConnected = pluginIO.IsConnected;
FFactory.Connected += HandleConnected;
FFactory.Disconnected += HandleDisconnected;
}
public void Dispose()
{
FFactory.Connected -= HandleConnected;
FFactory.Disconnected -= HandleDisconnected;
}
public override string ToString()
{
return base.ToString() + ": " + FPluginIO.Name;
}
public bool IsConnected
{
get { return FConnected; }
}
public IPluginIO PluginIO
{
get
{
return FPluginIO;
}
}
public event PinConnectionEventHandler Connected;
protected virtual void OnConnected(PinConnectionEventArgs args)
{
if (Connected != null)
{
Connected(this, args);
}
}
public event PinConnectionEventHandler Disconnected;
protected virtual void OnDisconnected(PinConnectionEventArgs args)
{
if (Disconnected != null)
{
Disconnected(this, args);
}
}
void HandleConnected(object sender, ConnectionEventArgs e)
{
if (e.PluginIO == FPluginIO)
{
FConnected = this.PluginIO.IsConnected;
OnConnected(new PinConnectionEventArgs(e.OtherPin));
}
}
void HandleDisconnected(object sender, ConnectionEventArgs e)
{
if (e.PluginIO == FPluginIO)
{
FConnected = this.PluginIO.IsConnected;
OnDisconnected(new PinConnectionEventArgs(e.OtherPin));
}
}
}
}