-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBNFlowGraphLayoutRequest.cs
More file actions
156 lines (141 loc) · 5.73 KB
/
Copy pathBNFlowGraphLayoutRequest.cs
File metadata and controls
156 lines (141 loc) · 5.73 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
namespace BinaryNinja
{
/// <summary>
/// Represents an asynchronous flow graph layout operation. The request tracks whether
/// the layout algorithm has finished arranging the graph's nodes. The caller owns the
/// request handle returned by the layout engine and is responsible for disposing it.
/// </summary>
public class FlowGraphLayoutRequest : AbstractSafeHandle<FlowGraphLayoutRequest>
{
private NativeDelegates.BNCustomFlowGraphEvent? completionCallback;
/// <summary>
/// Initializes a new FlowGraphLayoutRequest wrapper around an existing native handle.
/// </summary>
/// <param name="handle">The native pointer to the BNFlowGraphLayoutRequest object.</param>
/// <param name="owner">True if this wrapper owns the handle and should free it on dispose.</param>
internal FlowGraphLayoutRequest(
IntPtr handle,
bool owner,
NativeDelegates.BNCustomFlowGraphEvent? completionCallback = null
)
: base(handle, owner)
{
this.completionCallback = completionCallback;
}
/// <summary>
/// Creates an owned reference by incrementing the native reference count.
/// Returns null if the handle is zero.
/// </summary>
/// <param name="handle">The native BNFlowGraphLayoutRequest pointer.</param>
/// <returns>A new owned FlowGraphLayoutRequest, or null if the handle is zero.</returns>
internal static FlowGraphLayoutRequest? NewFromHandle(IntPtr handle)
{
if (handle == IntPtr.Zero)
{
return null;
}
return new FlowGraphLayoutRequest(
NativeMethods.BNNewFlowGraphLayoutRequestReference(handle),
true
);
}
/// <summary>
/// Creates an owned reference by incrementing the native reference count.
/// Throws if the handle is zero.
/// </summary>
/// <param name="handle">The native BNFlowGraphLayoutRequest pointer.</param>
/// <returns>A new owned FlowGraphLayoutRequest.</returns>
internal static FlowGraphLayoutRequest MustNewFromHandle(IntPtr handle)
{
if (handle == IntPtr.Zero)
{
throw new ArgumentNullException(nameof(handle));
}
return new FlowGraphLayoutRequest(
NativeMethods.BNNewFlowGraphLayoutRequestReference(handle),
true
);
}
/// <summary>
/// Takes ownership of an existing handle without incrementing the reference count.
/// Returns null if the handle is zero.
/// </summary>
/// <param name="handle">The native BNFlowGraphLayoutRequest pointer.</param>
/// <returns>A new owned FlowGraphLayoutRequest, or null if the handle is zero.</returns>
internal static FlowGraphLayoutRequest? TakeHandle(IntPtr handle)
{
if (handle == IntPtr.Zero)
{
return null;
}
return new FlowGraphLayoutRequest(handle, true);
}
/// <summary>
/// Takes ownership of an existing handle without incrementing the reference count.
/// Throws if the handle is zero.
/// </summary>
/// <param name="handle">The native BNFlowGraphLayoutRequest pointer.</param>
/// <returns>A new owned FlowGraphLayoutRequest.</returns>
internal static FlowGraphLayoutRequest MustTakeHandle(IntPtr handle)
{
if (handle == IntPtr.Zero)
{
throw new ArgumentNullException(nameof(handle));
}
return new FlowGraphLayoutRequest(handle, true);
}
/// <summary>
/// Releases the native BNFlowGraphLayoutRequest handle when this instance is disposed or finalized.
/// </summary>
/// <returns>True if the handle was successfully released.</returns>
protected override bool ReleaseHandle()
{
if (!this.IsInvalid)
{
NativeMethods.BNAbortFlowGraphLayoutRequest(this.handle);
this.completionCallback = null;
NativeMethods.BNFreeFlowGraphLayoutRequest(this.handle);
this.SetHandleAsInvalid();
}
return true;
}
/// <summary>
/// Gets a value indicating whether the layout operation has finished.
/// True means the nodes have been positioned and the graph is ready to render.
/// </summary>
public bool Complete
{
get
{
// Query the native engine for the completion status of this layout operation.
return NativeMethods.BNIsFlowGraphLayoutRequestComplete(this.handle);
}
}
/// <summary>
/// Gets the flow graph that this layout request is operating on.
/// Returns null if the native engine cannot resolve the graph.
/// </summary>
public FlowGraph? Graph
{
get
{
// Retrieve a new reference to the graph being laid out.
return FlowGraph.TakeHandle(
NativeMethods.BNGetGraphForFlowGraphLayoutRequest(this.handle)
);
}
}
/// <summary>
/// Requests cancellation of this layout operation. The layout may not stop immediately.
/// </summary>
public void Abort()
{
NativeMethods.BNAbortFlowGraphLayoutRequest(this.handle);
this.completionCallback = null;
}
}
}