-
Notifications
You must be signed in to change notification settings - Fork 219
Expand file tree
/
Copy pathAeAreaBrowser.cs
More file actions
285 lines (254 loc) · 9.13 KB
/
AeAreaBrowser.cs
File metadata and controls
285 lines (254 loc) · 9.13 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/* ========================================================================
* Copyright (c) 2005-2019 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* The complete license agreement can be found here:
* http://opcfoundation.org/License/MIT/1.00/
* ======================================================================*/
using System;
using System.Collections.Generic;
using System.Xml;
using System.IO;
using System.Reflection;
using System.Threading;
using Opc.Ua;
using Opc.Ua.Server;
using Opc.Ua.Com;
using OpcRcw.Ae;
using OpcRcw.Comn;
namespace Opc.Ua.Com.Client
{
/// <summary>
/// Browses the children of a segment.
/// </summary>
public class AeAreaBrower : NodeBrowser
{
#region Constructors
/// <summary>
/// Creates a new browser object with a set of filters.
/// </summary>
/// <param name="context">The system context to use.</param>
/// <param name="view">The view which may restrict the set of references/nodes found.</param>
/// <param name="referenceType">The type of references being followed.</param>
/// <param name="includeSubtypes">Whether subtypes of the reference type are followed.</param>
/// <param name="browseDirection">Which way the references are being followed.</param>
/// <param name="browseName">The browse name of a specific target (used when translating browse paths).</param>
/// <param name="additionalReferences">Any additional references that should be included.</param>
/// <param name="internalOnly">If true the browser should not making blocking calls to external systems.</param>
/// <param name="qualifiedName">Name of the qualified.</param>
/// <param name="namespaceIndex">Index of the namespace.</param>
public AeAreaBrower(
ISystemContext context,
ViewDescription view,
NodeId referenceType,
bool includeSubtypes,
BrowseDirection browseDirection,
QualifiedName browseName,
IEnumerable<IReference> additionalReferences,
bool internalOnly,
string qualifiedName,
ushort namespaceIndex)
:
base(
context,
view,
referenceType,
includeSubtypes,
browseDirection,
browseName,
additionalReferences,
internalOnly)
{
m_qualifiedName = qualifiedName;
m_namespaceIndex = namespaceIndex;
m_stage = Stage.Begin;
}
#endregion
#region Overridden Methods
/// <summary>
/// Returns the next reference.
/// </summary>
/// <returns>The next reference that meets the browse criteria.</returns>
public override IReference Next()
{
lock (DataLock)
{
IReference reference = null;
// enumerate pre-defined references.
// always call first to ensure any pushed-back references are returned first.
reference = base.Next();
if (reference != null)
{
return reference;
}
// don't start browsing huge number of references when only internal references are requested.
if (InternalOnly)
{
return null;
}
// fetch references from the server.
do
{
// fetch next reference.
reference = NextChild();
if (reference != null)
{
return reference;
}
// go to the next stage.
NextStage();
}
while (m_stage != Stage.Done);
// all done.
return null;
}
}
#endregion
#region Private Methods
/// <summary>
/// Returns the next child.
/// </summary>
private IReference NextChild()
{
// check if a specific browse name is requested.
if (QualifiedName.IsNull(base.BrowseName))
{
return NextChild(m_stage);
}
// keep fetching references until a matching browse name if found.
NodeStateReference reference = null;
do
{
reference = NextChild(m_stage);
if (reference != null)
{
// need to let the caller look up the browse name.
if (reference.Target == null)
{
return reference;
}
// check for browse name match.
if (reference.Target.BrowseName == base.BrowseName)
{
return reference;
}
}
}
while (reference != null);
// no match - need to go onto the next stage.
return null;
}
/// <summary>
/// Returns the next child.
/// </summary>
private NodeStateReference NextChild(Stage stage)
{
// fetch children.
if (stage == Stage.Children)
{
if (m_browser == null)
{
return null;
}
BaseObjectState node = m_browser.Next(SystemContext, m_namespaceIndex);
if (node != null)
{
return new NodeStateReference(ReferenceTypeIds.HasNotifier, false, node.NodeId);
}
// all done.
return null;
}
// fetch child parents.
if (stage == Stage.Parents)
{
return null;
}
return null;
}
/// <summary>
/// Initializes the next stage of browsing.
/// </summary>
private void NextStage()
{
ComAeClientManager system = (ComAeClientManager)this.SystemContext.SystemHandle;
ComAeClient client = system.SelectClient((ServerSystemContext)SystemContext, false);
// determine which stage is next based on the reference types requested.
for (Stage next = m_stage+1; next <= Stage.Done; next++)
{
if (next == Stage.Children)
{
if (IsRequired(ReferenceTypeIds.HasNotifier, false))
{
m_stage = next;
break;
}
}
else if (next == Stage.Parents)
{
if (IsRequired(ReferenceTypeIds.HasNotifier, true))
{
m_stage = next;
break;
}
}
else if (next == Stage.Done)
{
m_stage = next;
break;
}
}
// start enumerating areas.
if (m_stage == Stage.Children)
{
m_browser = new ComAeBrowserClient(client, m_qualifiedName);
return;
}
// start enumerating parents.
if (m_stage == Stage.Parents)
{
return;
}
// all done.
}
#endregion
#region Stage Enumeration
/// <summary>
/// The stages available in a browse operation.
/// </summary>
private enum Stage
{
Begin,
Children,
Parents,
Done
}
#endregion
#region Private Fields
private Stage m_stage;
private string m_qualifiedName;
private ushort m_namespaceIndex;
private ComAeBrowserClient m_browser;
#endregion
}
}