Skip to content

Commit ed2e050

Browse files
author
Softing
committed
Initial check-in of UA .NET source code
1 parent d3c8bd3 commit ed2e050

4,787 files changed

Lines changed: 2145581 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 285 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,285 @@
1+
/* ========================================================================
2+
* Copyright (c) 2005-2013 The OPC Foundation, Inc. All rights reserved.
3+
*
4+
* OPC Foundation MIT License 1.00
5+
*
6+
* Permission is hereby granted, free of charge, to any person
7+
* obtaining a copy of this software and associated documentation
8+
* files (the "Software"), to deal in the Software without
9+
* restriction, including without limitation the rights to use,
10+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the
12+
* Software is furnished to do so, subject to the following
13+
* conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be
16+
* included in all copies or substantial portions of the Software.
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24+
* OTHER DEALINGS IN THE SOFTWARE.
25+
*
26+
* The complete license agreement can be found here:
27+
* http://opcfoundation.org/License/MIT/1.00/
28+
* ======================================================================*/
29+
30+
using System;
31+
using System.Collections.Generic;
32+
using System.Xml;
33+
using System.IO;
34+
using System.Reflection;
35+
using System.Threading;
36+
using Opc.Ua;
37+
using Opc.Ua.Server;
38+
using Opc.Ua.Com;
39+
using OpcRcw.Ae;
40+
using OpcRcw.Comn;
41+
42+
namespace Opc.Ua.Com.Client
43+
{
44+
/// <summary>
45+
/// Browses the children of a segment.
46+
/// </summary>
47+
public class AeAreaBrower : NodeBrowser
48+
{
49+
#region Constructors
50+
/// <summary>
51+
/// Creates a new browser object with a set of filters.
52+
/// </summary>
53+
/// <param name="context">The system context to use.</param>
54+
/// <param name="view">The view which may restrict the set of references/nodes found.</param>
55+
/// <param name="referenceType">The type of references being followed.</param>
56+
/// <param name="includeSubtypes">Whether subtypes of the reference type are followed.</param>
57+
/// <param name="browseDirection">Which way the references are being followed.</param>
58+
/// <param name="browseName">The browse name of a specific target (used when translating browse paths).</param>
59+
/// <param name="additionalReferences">Any additional references that should be included.</param>
60+
/// <param name="internalOnly">If true the browser should not making blocking calls to external systems.</param>
61+
/// <param name="qualifiedName">Name of the qualified.</param>
62+
/// <param name="namespaceIndex">Index of the namespace.</param>
63+
public AeAreaBrower(
64+
ISystemContext context,
65+
ViewDescription view,
66+
NodeId referenceType,
67+
bool includeSubtypes,
68+
BrowseDirection browseDirection,
69+
QualifiedName browseName,
70+
IEnumerable<IReference> additionalReferences,
71+
bool internalOnly,
72+
string qualifiedName,
73+
ushort namespaceIndex)
74+
:
75+
base(
76+
context,
77+
view,
78+
referenceType,
79+
includeSubtypes,
80+
browseDirection,
81+
browseName,
82+
additionalReferences,
83+
internalOnly)
84+
{
85+
m_qualifiedName = qualifiedName;
86+
m_namespaceIndex = namespaceIndex;
87+
m_stage = Stage.Begin;
88+
}
89+
#endregion
90+
91+
#region Overridden Methods
92+
/// <summary>
93+
/// Returns the next reference.
94+
/// </summary>
95+
/// <returns>The next reference that meets the browse criteria.</returns>
96+
public override IReference Next()
97+
{
98+
lock (DataLock)
99+
{
100+
IReference reference = null;
101+
102+
// enumerate pre-defined references.
103+
// always call first to ensure any pushed-back references are returned first.
104+
reference = base.Next();
105+
106+
if (reference != null)
107+
{
108+
return reference;
109+
}
110+
111+
// don't start browsing huge number of references when only internal references are requested.
112+
if (InternalOnly)
113+
{
114+
return null;
115+
}
116+
117+
// fetch references from the server.
118+
do
119+
{
120+
// fetch next reference.
121+
reference = NextChild();
122+
123+
if (reference != null)
124+
{
125+
return reference;
126+
}
127+
128+
// go to the next stage.
129+
NextStage();
130+
}
131+
while (m_stage != Stage.Done);
132+
133+
// all done.
134+
return null;
135+
}
136+
}
137+
#endregion
138+
139+
#region Private Methods
140+
/// <summary>
141+
/// Returns the next child.
142+
/// </summary>
143+
private IReference NextChild()
144+
{
145+
// check if a specific browse name is requested.
146+
if (QualifiedName.IsNull(base.BrowseName))
147+
{
148+
return NextChild(m_stage);
149+
}
150+
151+
// keep fetching references until a matching browse name if found.
152+
NodeStateReference reference = null;
153+
154+
do
155+
{
156+
reference = NextChild(m_stage);
157+
158+
if (reference != null)
159+
{
160+
// need to let the caller look up the browse name.
161+
if (reference.Target == null)
162+
{
163+
return reference;
164+
}
165+
166+
// check for browse name match.
167+
if (reference.Target.BrowseName == base.BrowseName)
168+
{
169+
return reference;
170+
}
171+
}
172+
}
173+
while (reference != null);
174+
175+
// no match - need to go onto the next stage.
176+
return null;
177+
}
178+
179+
/// <summary>
180+
/// Returns the next child.
181+
/// </summary>
182+
private NodeStateReference NextChild(Stage stage)
183+
{
184+
// fetch children.
185+
if (stage == Stage.Children)
186+
{
187+
if (m_browser == null)
188+
{
189+
return null;
190+
}
191+
192+
BaseObjectState node = m_browser.Next(SystemContext, m_namespaceIndex);
193+
194+
if (node != null)
195+
{
196+
return new NodeStateReference(ReferenceTypeIds.HasNotifier, false, node.NodeId);
197+
}
198+
199+
// all done.
200+
return null;
201+
}
202+
203+
// fetch child parents.
204+
if (stage == Stage.Parents)
205+
{
206+
return null;
207+
}
208+
209+
return null;
210+
}
211+
212+
/// <summary>
213+
/// Initializes the next stage of browsing.
214+
/// </summary>
215+
private void NextStage()
216+
{
217+
ComAeClientManager system = (ComAeClientManager)this.SystemContext.SystemHandle;
218+
ComAeClient client = system.SelectClient((ServerSystemContext)SystemContext, false);
219+
220+
// determine which stage is next based on the reference types requested.
221+
for (Stage next = m_stage+1; next <= Stage.Done; next++)
222+
{
223+
if (next == Stage.Children)
224+
{
225+
if (IsRequired(ReferenceTypeIds.HasNotifier, false))
226+
{
227+
m_stage = next;
228+
break;
229+
}
230+
}
231+
232+
else if (next == Stage.Parents)
233+
{
234+
if (IsRequired(ReferenceTypeIds.HasNotifier, true))
235+
{
236+
m_stage = next;
237+
break;
238+
}
239+
}
240+
241+
else if (next == Stage.Done)
242+
{
243+
m_stage = next;
244+
break;
245+
}
246+
}
247+
248+
// start enumerating areas.
249+
if (m_stage == Stage.Children)
250+
{
251+
m_browser = new ComAeBrowserClient(client, m_qualifiedName);
252+
return;
253+
}
254+
255+
// start enumerating parents.
256+
if (m_stage == Stage.Parents)
257+
{
258+
return;
259+
}
260+
261+
// all done.
262+
}
263+
#endregion
264+
265+
#region Stage Enumeration
266+
/// <summary>
267+
/// The stages available in a browse operation.
268+
/// </summary>
269+
private enum Stage
270+
{
271+
Begin,
272+
Children,
273+
Parents,
274+
Done
275+
}
276+
#endregion
277+
278+
#region Private Fields
279+
private Stage m_stage;
280+
private string m_qualifiedName;
281+
private ushort m_namespaceIndex;
282+
private ComAeBrowserClient m_browser;
283+
#endregion
284+
}
285+
}

0 commit comments

Comments
 (0)