Skip to content

Commit

Permalink
Add IStreamedParameter and IStreamedParameterCollection interfaces
Browse files Browse the repository at this point in the history
References #8
  • Loading branch information
andreashuber-lawo committed Jan 6, 2016
1 parent 9ae2c8d commit 64ce792
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 14 deletions.
2 changes: 2 additions & 0 deletions Lawo.EmberPlusSharp/Lawo.EmberPlusSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@
<Compile Include="Model\Function6.cs" />
<Compile Include="Model\Function4.cs" />
<Compile Include="Model\Function2.cs" />
<Compile Include="Model\IStreamedParameter.cs" />
<Compile Include="Model\IStreamedParameterCollection.cs" />
<Compile Include="Model\RequestState.cs" />
<Compile Include="Model\DynamicRoot.cs" />
<Compile Include="Model\DynamicNodeHelper.cs" />
Expand Down
14 changes: 10 additions & 4 deletions Lawo.EmberPlusSharp/Model/Consumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ namespace Lawo.EmberPlusSharp.Model
/// <typeparam name="TRoot">The type of the root of the object tree that will mirror the state of the tree published
/// by the provider.</typeparam>
/// <threadsafety static="true" instance="false"/>
public sealed class Consumer<TRoot> : IMonitoredConnection, IInvocationCollection where TRoot : Root<TRoot>
public sealed class Consumer<TRoot> : IMonitoredConnection, IInvocationCollection, IStreamedParameterCollection
where TRoot : Root<TRoot>
{
private static readonly EmberData EmberDataCommand = new EmberData(0x01, 0x0A, 0x02);

Expand Down Expand Up @@ -201,6 +202,11 @@ int IInvocationCollection.Add(IInvocationResult invocationResult)
return this.lastInvocationId;
}

void IStreamedParameterCollection.Add(IStreamedParameter parameter)
{
throw new NotImplementedException();
}

private Consumer(S101Client client, int timeout, byte slot)
{
this.client = client;
Expand Down Expand Up @@ -366,7 +372,7 @@ private async Task<bool> SendRequestAsync()
// answer to our previous getDirectory request. If it doesn't, the timeout will take care of things.
MemoryStream stream;

if (!WriteRequest(this.root, out stream))
if (!this.WriteRequest(out stream))
{
// If no answer is expected from the provider due to the request, we need to update the request
// state again to see whether there's still something missing.
Expand Down Expand Up @@ -417,13 +423,13 @@ private void ApplyChange(MessageReceivedEventArgs args)
}
}

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

Expand Down
4 changes: 2 additions & 2 deletions Lawo.EmberPlusSharp/Model/Element.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,14 @@ internal virtual RequestState UpdateRequestState(bool throwForMissingRequiredChi
return RequestState.Verified;
}

/// <summary>Writes the payload of a message that contains an appropriate requests for all elements that require
/// <summary>Writes the payload of a message that contains appropriate requests for all elements that require
/// one.</summary>
/// <returns><c>true</c> if a provider response is expected due to the request; otherwise <c>false</c>.
/// </returns>
/// <remarks>Recursively visits all children with a state equal to <see cref="RequestState.None"/>, writes
/// a getDirectory command for nodes that do not yet have children or a subscribe command for stream parameters
/// and changes their state accordingly.</remarks>
internal virtual bool WriteRequest(EmberWriter writer)
internal virtual bool WriteRequest(EmberWriter writer, IStreamedParameterCollection streamedParameters)
{
return false;
}
Expand Down
12 changes: 12 additions & 0 deletions Lawo.EmberPlusSharp/Model/IStreamedParameter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// <copyright>Copyright 2012-2015 Lawo AG (http://www.lawo.com).</copyright>
// 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)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

namespace Lawo.EmberPlusSharp.Model
{
internal interface IStreamedParameter : IParameter
{
}
}
13 changes: 13 additions & 0 deletions Lawo.EmberPlusSharp/Model/IStreamedParameterCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// <copyright>Copyright 2012-2015 Lawo AG (http://www.lawo.com).</copyright>
// 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)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

namespace Lawo.EmberPlusSharp.Model
{
internal interface IStreamedParameterCollection
{
void Add(IStreamedParameter parameter);
}
}
8 changes: 4 additions & 4 deletions Lawo.EmberPlusSharp/Model/NodeBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ internal void ReadChild(EmberReader reader, ElementType actualType)
this.ReadChild(reader, actualType, reader.AssertAndReadContentsAsInt32());
}

internal bool WriteCommandCollection(EmberWriter writer)
internal bool WriteCommandCollection(EmberWriter writer, IStreamedParameterCollection streamedParameters)
{
if (this.children.Count == 0)
{
Expand All @@ -75,7 +75,7 @@ internal bool WriteCommandCollection(EmberWriter writer)
foreach (var child in this.children.Values)
{
// We want to avoid short-circuit logic, which is why we use | rather than ||.
result |= child.WriteRequest(writer);
result |= child.WriteRequest(writer, streamedParameters);
}

return result;
Expand Down Expand Up @@ -204,7 +204,7 @@ internal sealed override RequestState UpdateRequestState(bool throwForMissingReq
}
}

internal override bool WriteRequest(EmberWriter writer)
internal override bool WriteRequest(EmberWriter writer, IStreamedParameterCollection streamedParameters)
{
if (this.RequestState.Equals(RequestState.None))
{
Expand All @@ -219,7 +219,7 @@ internal override bool WriteRequest(EmberWriter writer)
GlowQualifiedNode.Children.OuterId, GlowElementCollection.InnerNumber);
}

var result = this.WriteCommandCollection(writer);
var result = this.WriteCommandCollection(writer, streamedParameters);

if (isEmpty)
{
Expand Down
4 changes: 2 additions & 2 deletions Lawo.EmberPlusSharp/Model/ParameterBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Lawo.EmberPlusSharp.Model
/// <typeparam name="TMostDerived">The most-derived subtype of this class.</typeparam>
/// <typeparam name="TValue">The type of the value.</typeparam>
/// <threadsafety static="true" instance="false"/>
public abstract class ParameterBase<TMostDerived, TValue> : ElementWithSchemas<TMostDerived>, IParameter
public abstract class ParameterBase<TMostDerived, TValue> : ElementWithSchemas<TMostDerived>, IStreamedParameter
where TMostDerived : ParameterBase<TMostDerived, TValue>
{
private TValue theValue;
Expand Down Expand Up @@ -230,7 +230,7 @@ internal virtual TValue AssertValueType(object value)
}
}

internal sealed override bool WriteRequest(EmberWriter writer)
internal sealed override bool WriteRequest(EmberWriter writer, IStreamedParameterCollection streamedParameters)
{
if (this.RequestState.Equals(RequestState.None))
{
Expand Down
4 changes: 2 additions & 2 deletions Lawo.EmberPlusSharp/Model/Root.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ internal sealed override bool ReadChildrenCore(EmberReader reader)
}

[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Method is not public, CA bug?")]
internal sealed override bool WriteRequest(EmberWriter writer)
internal sealed override bool WriteRequest(EmberWriter writer, IStreamedParameterCollection streamedParameters)
{
writer.WriteStartApplicationDefinedType(GlowGlobal.Root.OuterId, GlowRootElementCollection.InnerNumber);
var result = this.WriteCommandCollection(writer);
var result = this.WriteCommandCollection(writer, streamedParameters);
writer.WriteEndContainer();
return result;
}
Expand Down

0 comments on commit 64ce792

Please sign in to comment.