Skip to content

Commit

Permalink
Send subscribe commands for parameters with StreamIdentifiers
Browse files Browse the repository at this point in the history
References #8
  • Loading branch information
andreashuber-lawo committed Jan 6, 2016
1 parent fa82879 commit 47d048c
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 16 deletions.
15 changes: 13 additions & 2 deletions Lawo.EmberPlusSharp/Model/ElementWithSchemas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ internal ElementWithSchemas(RequestState onlineRequestState)

/// <summary>Gets or sets the request state.</summary>
/// <remarks>This property (along with its backing fields) has nothing to do with schemas. However, it so
/// happens that all subclasses (parameters and nodes) need this member. If this fact ever changes, it probably
/// makes sense to move this member to its own base class (named e.g. RequestedElement).</remarks>
/// happens that all subclasses (parameters, nodes and matrices) need this member. If this fact ever changes, it
/// probably makes sense to move this member to its own base class (named e.g. RequestedElement).</remarks>
internal RequestState RequestState
{
get
Expand Down Expand Up @@ -95,6 +95,17 @@ internal sealed override void SetRequestState(bool isEmpty, ref RequestState new
this.RequestState = newRequestState;
}

internal override RequestState UpdateRequestState(bool throwForMissingRequiredChildren)
{
if (!this.IsOnline || (this.RequestState.Equals(RequestState.Complete) &&
this.AreRequiredChildrenAvailable(throwForMissingRequiredChildren)))
{
this.RequestState = base.UpdateRequestState(throwForMissingRequiredChildren);
}

return this.RequestState;
}

internal override void SetComplete()
{
this.RequestState = RequestState.Complete;
Expand Down
16 changes: 4 additions & 12 deletions Lawo.EmberPlusSharp/Model/NodeBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,9 @@ internal sealed override RequestState ReadQualifiedChild(

internal sealed override RequestState UpdateRequestState(bool throwForMissingRequiredChildren)
{
if (!this.IsOnline)
if (!this.IsOnline || (this.children.Count == 0))
{
this.RequestState = RequestState.Verified;
}
else if (this.children.Count == 0)
{
if (this.RequestState.Equals(RequestState.Complete) &&
this.AreRequiredChildrenAvailable(throwForMissingRequiredChildren))
{
this.RequestState = RequestState.Verified;
}
return base.UpdateRequestState(throwForMissingRequiredChildren);
}
else
{
Expand All @@ -207,9 +199,9 @@ internal sealed override RequestState UpdateRequestState(bool throwForMissingReq
this.RequestState =
this.GetRequestState(throwForMissingRequiredChildren, accumulatedChildRequestState);
}
}

return this.RequestState;
return this.RequestState;
}
}

internal override bool WriteRequest(EmberWriter writer)
Expand Down
35 changes: 33 additions & 2 deletions Lawo.EmberPlusSharp/Model/ParameterBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,18 @@ public ParameterType Type
/// <inheritdoc/>
public int? StreamIdentifier
{
get { return this.streamIdentifier; }
private set { this.SetValue(ref this.streamIdentifier, value); }
get
{
return this.streamIdentifier;
}

private set
{
if (this.SetValue(ref this.streamIdentifier, value) && value.HasValue && this.IsOnline)
{
this.RequestState = RequestState.None;
}
}
}

/// <inheritdoc/>
Expand Down Expand Up @@ -220,6 +230,23 @@ internal virtual TValue AssertValueType(object value)
}
}

internal sealed override bool WriteRequest(EmberWriter writer)
{
if (this.RequestState.Equals(RequestState.None))
{
writer.WriteStartApplicationDefinedType(
GlowElementCollection.Element.OuterId, GlowQualifiedParameter.InnerNumber);
writer.WriteValue(GlowQualifiedParameter.Path.OuterId, this.NumberPath);
writer.WriteStartApplicationDefinedType(
GlowQualifiedParameter.Children.OuterId, GlowElementCollection.InnerNumber);
this.WriteCommandCollection(writer, GlowCommandNumber.Subscribe, RequestState.Complete);
writer.WriteEndContainer();
writer.WriteEndContainer();
}

return false;
}

internal override RequestState ReadContents(EmberReader reader, ElementType actualType)
{
this.AssertElementType(ElementType.Parameter, actualType);
Expand Down Expand Up @@ -265,6 +292,10 @@ internal override RequestState ReadContents(EmberReader reader, ElementType actu
break;
case GlowParameterContents.IsOnline.OuterNumber:
this.IsOnline = reader.AssertAndReadContentsAsBoolean();
var send = (this.IsOnlineChangeStatus == IsOnlineChangeStatus.Changed) &&
this.IsOnline && this.StreamIdentifier.HasValue;
var newRequestState = this.RequestState & (send ? RequestState.None : RequestState.Complete);
this.SetRequestState(false, ref newRequestState);
break;
case GlowParameterContents.Formula.OuterNumber:
this.FormulaCore = reader.AssertAndReadContentsAsString();
Expand Down
72 changes: 72 additions & 0 deletions Lawo.EmberPlusSharpTest/Model/Test/EmberDataPayloads/MainLog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,78 @@ Three</enumeration>
<Command>EmberData 01 0A 02</Command>
<Payload>
<Root type="RootElementCollection">
<RootElement type="QualifiedParameter">
<path type="RelativeObjectIdentifier">1</path>
<children type="ElementCollection">
<Element type="Command">
<number type="Integer">30</number>
</Element>
</children>
</RootElement>
<RootElement type="QualifiedParameter">
<path type="RelativeObjectIdentifier">2</path>
<children type="ElementCollection">
<Element type="Command">
<number type="Integer">30</number>
</Element>
</children>
</RootElement>
<RootElement type="QualifiedParameter">
<path type="RelativeObjectIdentifier">3</path>
<children type="ElementCollection">
<Element type="Command">
<number type="Integer">30</number>
</Element>
</children>
</RootElement>
<RootElement type="QualifiedParameter">
<path type="RelativeObjectIdentifier">4</path>
<children type="ElementCollection">
<Element type="Command">
<number type="Integer">30</number>
</Element>
</children>
</RootElement>
<RootElement type="QualifiedParameter">
<path type="RelativeObjectIdentifier">5</path>
<children type="ElementCollection">
<Element type="Command">
<number type="Integer">30</number>
</Element>
</children>
</RootElement>
<RootElement type="QualifiedParameter">
<path type="RelativeObjectIdentifier">6</path>
<children type="ElementCollection">
<Element type="Command">
<number type="Integer">30</number>
</Element>
</children>
</RootElement>
<RootElement type="QualifiedParameter">
<path type="RelativeObjectIdentifier">7</path>
<children type="ElementCollection">
<Element type="Command">
<number type="Integer">30</number>
</Element>
</children>
</RootElement>
<RootElement type="QualifiedParameter">
<path type="RelativeObjectIdentifier">8</path>
<children type="ElementCollection">
<Element type="Command">
<number type="Integer">30</number>
</Element>
</children>
</RootElement>
<RootElement type="QualifiedParameter">
<path type="RelativeObjectIdentifier">9</path>
<children type="ElementCollection">
<Element type="Command">
<number type="Integer">30</number>
</Element>
</children>
</RootElement>
<RootElement type="QualifiedNode">
<path type="RelativeObjectIdentifier">10</path>
<children type="ElementCollection">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,78 @@
<!-- Distributed under the Boost Software License, Version 1.0. -->
<!-- (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<Root type="RootElementCollection">
<RootElement type="QualifiedParameter">
<path type="RelativeObjectIdentifier">1</path>
<children type="ElementCollection">
<Element type="Command">
<number type="Integer">30</number>
</Element>
</children>
</RootElement>
<RootElement type="QualifiedParameter">
<path type="RelativeObjectIdentifier">2</path>
<children type="ElementCollection">
<Element type="Command">
<number type="Integer">30</number>
</Element>
</children>
</RootElement>
<RootElement type="QualifiedParameter">
<path type="RelativeObjectIdentifier">3</path>
<children type="ElementCollection">
<Element type="Command">
<number type="Integer">30</number>
</Element>
</children>
</RootElement>
<RootElement type="QualifiedParameter">
<path type="RelativeObjectIdentifier">4</path>
<children type="ElementCollection">
<Element type="Command">
<number type="Integer">30</number>
</Element>
</children>
</RootElement>
<RootElement type="QualifiedParameter">
<path type="RelativeObjectIdentifier">5</path>
<children type="ElementCollection">
<Element type="Command">
<number type="Integer">30</number>
</Element>
</children>
</RootElement>
<RootElement type="QualifiedParameter">
<path type="RelativeObjectIdentifier">6</path>
<children type="ElementCollection">
<Element type="Command">
<number type="Integer">30</number>
</Element>
</children>
</RootElement>
<RootElement type="QualifiedParameter">
<path type="RelativeObjectIdentifier">7</path>
<children type="ElementCollection">
<Element type="Command">
<number type="Integer">30</number>
</Element>
</children>
</RootElement>
<RootElement type="QualifiedParameter">
<path type="RelativeObjectIdentifier">8</path>
<children type="ElementCollection">
<Element type="Command">
<number type="Integer">30</number>
</Element>
</children>
</RootElement>
<RootElement type="QualifiedParameter">
<path type="RelativeObjectIdentifier">9</path>
<children type="ElementCollection">
<Element type="Command">
<number type="Integer">30</number>
</Element>
</children>
</RootElement>
<RootElement type="QualifiedNode">
<path type="RelativeObjectIdentifier">10</path>
<children type="ElementCollection">
Expand Down

0 comments on commit 47d048c

Please sign in to comment.