Skip to content

Commit

Permalink
Rename ChildrenState to RequestState
Browse files Browse the repository at this point in the history
References #8
  • Loading branch information
andreashuber-lawo committed Dec 19, 2015
1 parent a00c2af commit 91b112f
Show file tree
Hide file tree
Showing 25 changed files with 214 additions and 205 deletions.
2 changes: 1 addition & 1 deletion Lawo.EmberPlusSharp/Glow/GlowLogInterpreter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void ApplyPayload()
{
this.root.Read(emberReader, this.pendingInvocations);
this.root.SetComplete();
this.root.UpdateChildrenState(true);
this.root.UpdateRequestState(true);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Lawo.EmberPlusSharp/Lawo.EmberPlusSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
<Compile Include="Model\Function6.cs" />
<Compile Include="Model\Function4.cs" />
<Compile Include="Model\Function2.cs" />
<Compile Include="Model\ChildrenState.cs" />
<Compile Include="Model\RequestState.cs" />
<Compile Include="Model\DynamicRoot.cs" />
<Compile Include="Model\DynamicNodeHelper.cs" />
<Compile Include="Model\DynamicNode.cs" />
Expand Down
77 changes: 0 additions & 77 deletions Lawo.EmberPlusSharp/Model/ChildrenState.cs

This file was deleted.

6 changes: 3 additions & 3 deletions Lawo.EmberPlusSharp/Model/CollectionNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public TElement this[int number]

[SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", Justification = "These are actual class names.")]
internal sealed override Element ReadNewChildContents(
EmberReader reader, ElementType actualType, Context context, out ChildrenState childChildrenState)
EmberReader reader, ElementType actualType, Context context, out RequestState childRequestState)
{
if (ReadContentsCallback == null)
{
Expand All @@ -57,7 +57,7 @@ internal sealed override Element ReadNewChildContents(
throw new ModelException(string.Format(CultureInfo.InvariantCulture, Format, this.GetPath()));
}

return ReadContentsCallback(reader, actualType, context, out childChildrenState);
return ReadContentsCallback(reader, actualType, context, out childRequestState);
}

[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Method is not public, CA bug?")]
Expand Down Expand Up @@ -93,6 +93,6 @@ private static ReadContentsMethod GetReadContentsMethod()
}

private delegate Element ReadContentsMethod(
EmberReader reader, ElementType actualType, Context context, out ChildrenState childChildrenState);
EmberReader reader, ElementType actualType, Context context, out RequestState childRequestState);
}
}
20 changes: 10 additions & 10 deletions Lawo.EmberPlusSharp/Model/Consumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ private async Task QueryChildrenAsync()

if ((await Task.WhenAny(queryChildrenTask, Task.Delay(this.queryChildrenTimeout))) != queryChildrenTask)
{
this.root.UpdateChildrenState(this.root.ChildrenState.Equals(ChildrenState.Complete));
this.root.UpdateRequestState(this.root.RequestState.Equals(RequestState.Complete));
var firstIncompleteNode = this.root.GetFirstIncompleteChild();
var message = firstIncompleteNode == null ?
"The provider failed to send all requested elements within the specified timeout." :
Expand Down Expand Up @@ -353,23 +353,23 @@ private async Task DelayAutoSend()

private async Task<bool> SendChildrenQuery()
{
var rootChildrenState = this.root.UpdateChildrenState(false);
var rootRequestState = this.root.UpdateRequestState(false);

if (rootChildrenState.Equals(ChildrenState.None))
if (rootRequestState.Equals(RequestState.None))
{
// There is no guarantee that the response we received is actually an answer to the previously sent
// getDirectory request. It could just as well be a parameter value update. ChildrenState indicates
// whether the former or the latter happened. If ChildrenState == ChildrenState.None, we have
// received at least one new node. If ChildrenState != ChildrenState.None, no new node without
// getDirectory request. It could just as well be a parameter value update. RequestState indicates
// whether the former or the latter happened. If RequestState == RequestState.None, we have
// received at least one new node. If RequestState != RequestState.None, no new node without
// children has been received and consequently no new getDirectory request needs to be sent.
// Of course, in the latter case the assumption is that the provider will at some point send an
// answer to our previous getDirectory request. If it doesn't, the timeout will take care of things.
MemoryStream stream;
WriteChildrenQuery(this.root, out stream);
WriteRequest(this.root, out stream);
await this.client.SendMessageAsync(this.emberDataMessage, stream.ToArray());
}

return !rootChildrenState.Equals(ChildrenState.Verified);
return !rootRequestState.Equals(RequestState.Verified);
}

private void ApplyChange(MessageReceivedEventArgs args)
Expand Down Expand Up @@ -410,13 +410,13 @@ private void ApplyChange(MessageReceivedEventArgs args)
}
}

private static void WriteChildrenQuery(TRoot root, out MemoryStream stream)
private static void WriteRequest(TRoot root, out MemoryStream stream)
{
// TODO: Reuse MemoryStream and EmberWriter for all outgoing messages.
using (stream = new MemoryStream())
using (var writer = new EmberWriter(stream))
{
root.WriteChildrenQuery(writer);
root.WriteRequest(writer);
}
}

Expand Down
4 changes: 2 additions & 2 deletions Lawo.EmberPlusSharp/Model/DynamicNodeBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ internal DynamicNodeBase()

[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Method is not public, CA bug?")]
internal sealed override Element ReadNewDynamicChildContents(
EmberReader reader, ElementType actualType, Context context, out ChildrenState childChildrenState)
EmberReader reader, ElementType actualType, Context context, out RequestState childRequestState)
{
return DynamicNodeHelper.ReadDynamicChildContents(reader, actualType, context, out childChildrenState);
return DynamicNodeHelper.ReadDynamicChildContents(reader, actualType, context, out childRequestState);
}
}
}
8 changes: 4 additions & 4 deletions Lawo.EmberPlusSharp/Model/DynamicNodeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ internal static Element ReadDynamicChildContents(
EmberReader reader,
ElementType actualType,
Context context,
out ChildrenState childChildrenState)
out RequestState childRequestState)
{
switch (actualType)
{
case ElementType.Parameter:
return DynamicParameter.ReadContents(reader, actualType, context, out childChildrenState);
return DynamicParameter.ReadContents(reader, actualType, context, out childRequestState);
case ElementType.Node:
return DynamicNode.ReadContents(reader, actualType, context, out childChildrenState);
return DynamicNode.ReadContents(reader, actualType, context, out childRequestState);
default:
return DynamicFunction.ReadContents(reader, actualType, context, out childChildrenState);
return DynamicFunction.ReadContents(reader, actualType, context, out childRequestState);
}
}

Expand Down
4 changes: 2 additions & 2 deletions Lawo.EmberPlusSharp/Model/DynamicRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public ReadOnlyObservableCollection<IElement> DynamicChildren
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

internal sealed override Element ReadNewDynamicChildContents(
EmberReader reader, ElementType actualType, Context context, out ChildrenState childChildrenState)
EmberReader reader, ElementType actualType, Context context, out RequestState childRequestState)
{
return DynamicNodeHelper.ReadDynamicChildContents(reader, actualType, context, out childChildrenState);
return DynamicNodeHelper.ReadDynamicChildContents(reader, actualType, context, out childRequestState);
}

internal sealed override bool ChangeOnlineStatus(IElement child)
Expand Down
48 changes: 24 additions & 24 deletions Lawo.EmberPlusSharp/Model/Element.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,38 +193,38 @@ internal void SetConsumerValue<T>(ref T field, T newValue, [CallerMemberName] st
}
}

internal virtual void SetChildrenState(bool isEmpty, ref ChildrenState newChildrenState)
internal virtual void SetRequestState(bool isEmpty, ref RequestState newRequestState)
{
newChildrenState = ChildrenState.Complete;
newRequestState = RequestState.Complete;
}

internal abstract ChildrenState ReadContents(EmberReader reader, ElementType actualType);
internal abstract RequestState ReadContents(EmberReader reader, ElementType actualType);

/// <summary>Recursively reads the children of an element as they appear in the message payload and returns
/// the state of this element.</summary>
/// <remarks>
/// <para>Nodes for which an empty children collection is received are marked with
/// <see cref="ChildrenState.Complete"/>. The same happens if the collection only contains children we're not
/// <see cref="RequestState.Complete"/>. The same happens if the collection only contains children we're not
/// interested in. In all other cases, the state of the node is lowered to the lowest state of the
/// interesting children appearing in the payload.</para>
/// <para>This approach ensures that any node for which incomplete interesting children have been received will
/// be visited by <see cref="UpdateChildrenState"/>. This is necessary because some providers send messages with
/// be visited by <see cref="UpdateRequestState"/>. This is necessary because some providers send messages with
/// payloads where the same node appears multiple times. For example, the first time the state of the node may
/// be set to <see cref="ChildrenState.None"/>, due to the fact that there are indirect children for which a
/// getDirectory request needs to be sent. The second time the node appears only with direct and indirect
/// children that have the state <see cref="ChildrenState.Complete"/>. Now the state of the node cannot be set
/// to <see cref="ChildrenState.Complete"/> because then no getDirectory requests would be issued for the children
/// that appeared the first time.</para>
/// be set to <see cref="RequestState.None"/>, due to the fact that there are indirect children for which a
/// <code>getDirectory</code> request needs to be sent. The second time the node appears only with direct and
/// indirect children that have the state <see cref="RequestState.Complete"/>. Now the state of the node cannot
/// be set to <see cref="RequestState.Complete"/> because then no <code>getDirectory</code> requests would be
/// issued for the children that appeared the first time.</para>
/// <para>It follows that the state of a node cannot be set to its definitive value while its children are read.
/// Instead there needs to be a second step that visits all affected nodes and updates their state, which is
/// implemented by <see cref="UpdateChildrenState"/>.</para></remarks>
internal virtual ChildrenState ReadChildren(EmberReader reader)
/// implemented by <see cref="UpdateRequestState"/>.</para></remarks>
internal virtual RequestState ReadChildren(EmberReader reader)
{
reader.Skip();
return ChildrenState.Complete;
return RequestState.Complete;
}

internal virtual ChildrenState ReadQualifiedChild(
internal virtual RequestState ReadQualifiedChild(
EmberReader reader, ElementType actualType, int[] path, int index)
{
const string Format =
Expand All @@ -238,21 +238,21 @@ internal virtual void ReadAdditionalFields(EmberReader reader)
}

/// <summary>Recursively updates the state of all children and returns the state of this element.</summary>
/// <remarks>Only the children with a state not equal to <see cref="ChildrenState.Verified"/> are visited.
/// <remarks>Only the children with a state not equal to <see cref="RequestState.Verified"/> are visited.
/// The state of a node is set to the lowest state of its children. If a node without children has the state
/// <see cref="ChildrenState.Complete"/> and does not require children, the state is lifted to
/// <see cref="ChildrenState.Verified"/>. In all other cases, the state is left as is.</remarks>
internal virtual ChildrenState UpdateChildrenState(bool throwForMissingRequiredChildren)
/// <see cref="RequestState.Complete"/> and does not require children, the state is lifted to
/// <see cref="RequestState.Verified"/>. In all other cases, the state is left as is.</remarks>
internal virtual RequestState UpdateRequestState(bool throwForMissingRequiredChildren)
{
return ChildrenState.Verified;
return RequestState.Verified;
}

/// <summary>Writes the payload of a message that contains a getDirectory request for all nodes that require
/// <summary>Writes the payload of a message that contains an appropriate requests for all elements that require
/// one.</summary>
/// <remarks>Recursively visits all children with a state equal to <see cref="ChildrenState.None"/>, writes
/// a getDirectory request for nodes that do not yet have children and marks them with
/// <see cref="ChildrenState.GetDirectorySent"/>.</remarks>
internal virtual void WriteChildrenQuery(EmberWriter writer)
/// <remarks>Recursively visits all children with a state equal to <see cref="RequestState.None"/>, writes
/// a getDirectory request for nodes that do not yet have children or a subscribe request for stream parameters
/// and changes their state accordingly.</remarks>
internal virtual void WriteRequest(EmberWriter writer)
{
}

Expand Down
4 changes: 2 additions & 2 deletions Lawo.EmberPlusSharp/Model/Element1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ internal static TMostDerived Construct(Context context)
}

internal static TMostDerived ReadContents(
EmberReader reader, ElementType actualType, Context context, out ChildrenState childrenState)
EmberReader reader, ElementType actualType, Context context, out RequestState requestState)
{
var result = Construct(context);
childrenState = result.ReadContents(reader, actualType);
requestState = result.ReadContents(reader, actualType);
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion Lawo.EmberPlusSharp/Model/EnumParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal sealed override IReadOnlyList<KeyValuePair<string, int>> EnumMapCore
set { this.impl.EnumMapCore = value; }
}

internal sealed override ChildrenState ReadContents(EmberReader reader, ElementType actualType)
internal sealed override RequestState ReadContents(EmberReader reader, ElementType actualType)
{
return this.impl.ReadContents(base.ReadContents, reader, actualType);
}
Expand Down
4 changes: 2 additions & 2 deletions Lawo.EmberPlusSharp/Model/EnumParameterImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ internal IReadOnlyList<KeyValuePair<string, int>> EnumMapCore
}

[SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", Justification = "Official Glow name.")]
internal ChildrenState ReadContents(
Func<EmberReader, ElementType, ChildrenState> baseImpl, EmberReader reader, ElementType actualType)
internal RequestState ReadContents(
Func<EmberReader, ElementType, RequestState> baseImpl, EmberReader reader, ElementType actualType)
{
if (!IsEnum)
{
Expand Down
Loading

0 comments on commit 91b112f

Please sign in to comment.