Skip to content

Commit

Permalink
Significant refactoring after accepting pull request from mjmeans. It…
Browse files Browse the repository at this point in the history
… was agreed that PwmProviderManager should work with classes that implement IPwmProvider rather than classes that implement IPwmControllerProvider. However this change meant that PWM classes needed to be refactored and the same pattern should also be applied for AdcProviderManager and ADC classes for consistency. For ADC and PWM classes that will only ever return a single controller, we've decided to implement the Provider and Controller interfaces in the same class. This greatly reduces file count and code complexity. It also keeps the samples and existing user code compiling since it uses the same signature. For the same reason, namespaces were returned to their original state.
  • Loading branch information
Jared Bienz committed Mar 22, 2016
1 parent 0a03941 commit c3b06aa
Show file tree
Hide file tree
Showing 13 changed files with 494 additions and 649 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ publish/
#!**/packages/repositories.config
# VSIX Packages OK
!**/VisualStudio/VSFeatureEngine/Packages/*
# Lock files
**/project.lock.json

# Windows Azure Build Output
csx/
Expand Down
33 changes: 19 additions & 14 deletions Lib/Microsoft.IoT.DeviceCore/Adc/AdcProviderManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
namespace Microsoft.IoT.DeviceCore.Adc
{
/// <summary>
/// An implementation of <see cref="IAdcProvider"/> that allows multiple ADC
/// controllers to be registered as a simple collection.
/// Allows multiple ADC controllers from various sources to be managed as a simple
/// disposable collection.
/// </summary>
/// <remarks>
/// All controllers should be added to the <see cref="Providers"/> collection
/// before calling <see cref="AdcProviderManager.GetControllersAsync"/>.
/// All providers should be added to the <see cref="Providers"/> collection
/// before calling <see cref="AdcProviderManager.GetControllersAsync">GetControllersAsync</see>.
/// </remarks>
public sealed class AdcProviderManager : IAdcProvider, IDisposable
{
#region Member Variables
private List<IAdcControllerProvider> providers;
private List<IAdcProvider> providers;
#endregion // Member Variables

#region Constructors
Expand All @@ -32,10 +32,22 @@ public sealed class AdcProviderManager : IAdcProvider, IDisposable
/// </summary>
public AdcProviderManager()
{
providers = new List<IAdcControllerProvider>();
providers = new List<IAdcProvider>();
}
#endregion // Constructors

#region IAdcProvider Interface
IReadOnlyList<IAdcControllerProvider> IAdcProvider.GetControllers()
{
var controllers = new List<IAdcControllerProvider>();
for (int i = 0; i < providers.Count; i++)
{
controllers.AddRange(providers[i].GetControllers());
}
return controllers;
}
#endregion // IAdcProvider Interface

#region Public Methods
/// <inheritdoc/>
public void Dispose()
Expand Down Expand Up @@ -68,20 +80,13 @@ public IAsyncOperation<IReadOnlyList<AdcController>> GetControllersAsync()
/// <value>
/// The collection of providers stored in the manager.
/// </value>
public IList<IAdcControllerProvider> Providers
public IList<IAdcProvider> Providers
{
get
{
return providers;
}
}
#endregion // Public Properties

#region IAdcProvider Interface
IReadOnlyList<IAdcControllerProvider> IAdcProvider.GetControllers()
{
return providers;
}
#endregion // IAdcProvider Interface
}
}
40 changes: 20 additions & 20 deletions Lib/Microsoft.IoT.DeviceCore/Pwm/PwmProviderManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
namespace Microsoft.IoT.DeviceCore.Pwm
{
/// <summary>
/// An implementation of <see cref="IPwmProvider"/> that allows multiple PWM
/// controllers to be registered as a simple collection.
/// Allows multiple PWM controllers from various sources to be managed as a simple
/// disposable collection.
/// </summary>
/// <remarks>
/// All controllers should be added to the <see cref="Providers"/> collection
/// before calling <see cref="PwmProviderManager.GetControllersAsync"/>.
/// All providers should be added to the <see cref="Providers"/> collection
/// before calling <see cref="PwmProviderManager.GetControllersAsync">GetControllersAsync</see>.
/// </remarks>
public sealed class PwmProviderManager : IPwmProvider, IDisposable
{
Expand All @@ -36,24 +36,36 @@ public PwmProviderManager()
}
#endregion // Constructors

#region IPwmProvider Interface
IReadOnlyList<IPwmControllerProvider> IPwmProvider.GetControllers()
{
var controllers = new List<IPwmControllerProvider>();
for (int i = 0; i < providers.Count; i++)
{
controllers.AddRange(providers[i].GetControllers());
}
return controllers;
}
#endregion // IPwmProvider Interface

#region Public Methods
/// <inheritdoc/>
public void Dispose()
{
// Dispose and remove each provider
for (int i = Providers.Count - 1; i >= 0; i--)
for (int i = providers.Count - 1; i >= 0; i--)
{
var provider = providers[i] as IDisposable;
if (provider != null) { provider.Dispose(); }
Providers.RemoveAt(i);
providers.RemoveAt(i);
}
}

/// <summary>
/// Gets the <see cref="PwmController"/> instances for each controller provider.
/// Gets a collection of <see cref="PwmController"/> instances that represent all controllers returned by all providers.
/// </summary>
/// <returns>
/// An IAsyncOperation that yields the list of controllers.
/// An IAsyncOperation that yields the controllers.
/// </returns>
public IAsyncOperation<IReadOnlyList<PwmController>> GetControllersAsync()
{
Expand All @@ -76,17 +88,5 @@ public IList<IPwmProvider> Providers
}
}
#endregion // Public Properties

#region IPwmControllerProvider Interface
IReadOnlyList<IPwmControllerProvider> IPwmProvider.GetControllers()
{
var controllers = new List<IPwmControllerProvider>();
for (int i=0; i<providers.Count; i++)
{
controllers.AddRange(providers[i].GetControllers());
}
return controllers;
}
#endregion // IPwmProvider Interface
}
}
Loading

0 comments on commit c3b06aa

Please sign in to comment.