diff --git a/Lawo.EmberPlusSharp/Lawo.EmberPlusSharp.csproj b/Lawo.EmberPlusSharp/Lawo.EmberPlusSharp.csproj index f3afd6b3..78a589bd 100644 --- a/Lawo.EmberPlusSharp/Lawo.EmberPlusSharp.csproj +++ b/Lawo.EmberPlusSharp/Lawo.EmberPlusSharp.csproj @@ -106,6 +106,8 @@ + + diff --git a/Lawo.EmberPlusSharp/Model/Consumer.cs b/Lawo.EmberPlusSharp/Model/Consumer.cs index 326ee270..c26a833d 100644 --- a/Lawo.EmberPlusSharp/Model/Consumer.cs +++ b/Lawo.EmberPlusSharp/Model/Consumer.cs @@ -25,7 +25,8 @@ namespace Lawo.EmberPlusSharp.Model /// The type of the root of the object tree that will mirror the state of the tree published /// by the provider. /// - public sealed class Consumer : IMonitoredConnection, IInvocationCollection where TRoot : Root + public sealed class Consumer : IMonitoredConnection, IInvocationCollection, IStreamedParameterCollection + where TRoot : Root { private static readonly EmberData EmberDataCommand = new EmberData(0x01, 0x0A, 0x02); @@ -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; @@ -366,7 +372,7 @@ private async Task 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. @@ -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); } } diff --git a/Lawo.EmberPlusSharp/Model/Element.cs b/Lawo.EmberPlusSharp/Model/Element.cs index 6b85a586..46054bcb 100644 --- a/Lawo.EmberPlusSharp/Model/Element.cs +++ b/Lawo.EmberPlusSharp/Model/Element.cs @@ -248,14 +248,14 @@ internal virtual RequestState UpdateRequestState(bool throwForMissingRequiredChi return RequestState.Verified; } - /// Writes the payload of a message that contains an appropriate requests for all elements that require + /// Writes the payload of a message that contains appropriate requests for all elements that require /// one. /// true if a provider response is expected due to the request; otherwise false. /// /// Recursively visits all children with a state equal to , writes /// a getDirectory command for nodes that do not yet have children or a subscribe command for stream parameters /// and changes their state accordingly. - internal virtual bool WriteRequest(EmberWriter writer) + internal virtual bool WriteRequest(EmberWriter writer, IStreamedParameterCollection streamedParameters) { return false; } diff --git a/Lawo.EmberPlusSharp/Model/IStreamedParameter.cs b/Lawo.EmberPlusSharp/Model/IStreamedParameter.cs new file mode 100644 index 00000000..7e78c02f --- /dev/null +++ b/Lawo.EmberPlusSharp/Model/IStreamedParameter.cs @@ -0,0 +1,12 @@ +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Copyright 2012-2015 Lawo AG (http://www.lawo.com). +// 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 + { + } +} diff --git a/Lawo.EmberPlusSharp/Model/IStreamedParameterCollection.cs b/Lawo.EmberPlusSharp/Model/IStreamedParameterCollection.cs new file mode 100644 index 00000000..9a7f225c --- /dev/null +++ b/Lawo.EmberPlusSharp/Model/IStreamedParameterCollection.cs @@ -0,0 +1,13 @@ +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Copyright 2012-2015 Lawo AG (http://www.lawo.com). +// 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); + } +} diff --git a/Lawo.EmberPlusSharp/Model/NodeBase.cs b/Lawo.EmberPlusSharp/Model/NodeBase.cs index bbe70051..35a1f887 100644 --- a/Lawo.EmberPlusSharp/Model/NodeBase.cs +++ b/Lawo.EmberPlusSharp/Model/NodeBase.cs @@ -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) { @@ -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; @@ -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)) { @@ -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) { diff --git a/Lawo.EmberPlusSharp/Model/ParameterBase.cs b/Lawo.EmberPlusSharp/Model/ParameterBase.cs index 13e4b940..e3f63f6f 100644 --- a/Lawo.EmberPlusSharp/Model/ParameterBase.cs +++ b/Lawo.EmberPlusSharp/Model/ParameterBase.cs @@ -20,7 +20,7 @@ namespace Lawo.EmberPlusSharp.Model /// The most-derived subtype of this class. /// The type of the value. /// - public abstract class ParameterBase : ElementWithSchemas, IParameter + public abstract class ParameterBase : ElementWithSchemas, IStreamedParameter where TMostDerived : ParameterBase { private TValue theValue; @@ -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)) { diff --git a/Lawo.EmberPlusSharp/Model/Root.cs b/Lawo.EmberPlusSharp/Model/Root.cs index c2e4563d..a5272d67 100644 --- a/Lawo.EmberPlusSharp/Model/Root.cs +++ b/Lawo.EmberPlusSharp/Model/Root.cs @@ -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; }