Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions HSPI/Connector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ public static class Connector
Justification = "The function wouldn't do anything without a plugin.")]
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes",
Justification = "I don't know what kinds of exceptions it _could_ throw.")]
public static void Connect<TPlugin>(string[] args) where TPlugin : HspiBase, new()
public static TPlugin Connect<TPlugin>(string[] args, bool pollForShutdown = true) where TPlugin : HspiBase, new()
{

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if pollForShutdown is true, the app will exit when the plugin shuts down, and this method will block until it does. And if it isn’t true, this method will return a plug-in instance. Do multiple plugins get loaded at a time? If one of them is polling for shutdown and shuts down then the whole app will exit. Is this intended?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HS does support multiple plugin instances, but that's ultimately going to be different code. The current HSPI code doesn't support multiple instances. Still have to figure out how all that works.

// create an instance of our plugin.
var myPlugin = new TPlugin();
Console.WriteLine(myPlugin.Name);

if (Environment.UserInteractive)
{
Console.Title = myPlugin.Name;
}

Parser.Default.ParseArguments<Options>(args)
.WithParsed(options =>
{
// create an instance of our plugin.
var myPlugin = new TPlugin();
Console.WriteLine(myPlugin.Name);

if (Environment.UserInteractive)
{
Console.Title = myPlugin.Name;
}

// Get our plugin to connect to HomeSeer
Console.WriteLine($"\nConnecting to HomeSeer at {options.Server}:{options.Port} ...");
try
Expand All @@ -43,7 +43,7 @@ public static class Connector
// let the plugin do it's thing, wait until it shuts down or the connection to HomeSeer fails.
try
{
while (true)
while (pollForShutdown)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, based on the behavior you may want to rename it exitOnShutdown and say if (exitOnShutdown) while true {...} }. It’d make it easier to understand.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meh, I get what you're saying, but I don't know about exitOnShutdown either. I kinda half-ass threw pollForShutdown on the table just to see if it stuck. Apparently, it didn't. I'll think about it some more before merging, as changing the name later would result in a breaking change.

{
// do nothing for a bit
Thread.Sleep(200);
Expand All @@ -68,8 +68,13 @@ public static class Connector
Console.WriteLine($"Unhandled exception from Plugin: {ex.Message}");
}

if (pollForShutdown)
{
Environment.Exit(0);
}
});
Environment.Exit(0);

return myPlugin;
}
}
}
12 changes: 8 additions & 4 deletions HSPI/HSPIBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ namespace Hspi
// ReSharper disable once InconsistentNaming
public abstract class HspiBase : IPlugInAPI
{
protected IAppCallbackAPI Callback { get; set; }
// ReSharper disable once MemberCanBePrivate.Global
public IAppCallbackAPI Callback { get; set; }

protected IScsServiceClient<IAppCallbackAPI> CallbackClient { get; set; }
// ReSharper disable once MemberCanBePrivate.Global
public IScsServiceClient<IAppCallbackAPI> CallbackClient { get; set; }

protected IHSApplication HS { get; set; }
// ReSharper disable once MemberCanBeProtected.Global
public IHSApplication HS { get; set; }

[SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Hs",
Justification = "R# doesn't like MS's standard.")]
protected IScsServiceClient<IHSApplication> HsClient { get; set; }
// ReSharper disable once MemberCanBePrivate.Global
public IScsServiceClient<IHSApplication> HsClient { get; set; }

public bool Shutdown { get; set; }

Expand Down