Announcement

Collapse
No announcement yet.

Multi Instance Plugins

Collapse
This is a sticky topic.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Multi Instance Plugins

    The documentation will have more details on this, but here is an overview on multi-instance plug-ins.

    Plug-ins can support multiple instances in 2 ways. The simple way is to just return True to the SupportsMultipleInstances property. HS will then allow the user to create another instance of your plugin EXE. In this mode, a second EXE is run and the instance name is passed to you as a parameter to main. You can use this instance name to distinguish between instances. Consider a plugin that supports some hardware through a COM port or network IP address. Normally, only one plugin can run so you can only support one piece of hardware. By enabling this feature, users can now install multiple hardware devices.

    A second option is supported with the property "SupportsMultipleInstancesSingleExe". If this is True, all instances are supported with one EXE. HS does not manage the instances in this mode. After your first instance is started, you can create a config page where users can add another instance. A new instance is created by calling "AddInstance(name as string)". This creates a new instance of your HSPI class and registers this with HS. The "AddInstance" function is provided to you in the HSPI_SAMPLE_BASICMI plugin sample source. Run this sample plugin to see how this works. The new instance will appear in the list of plug-ins on the HS manage plug-ins page.
    website | buy now | support | youtube

  • #2
    Thank you for implementing the second option. Much appreciated and was critical to convert the SqueezeBox plug-in. I converted one plugin to use and in the midst converting the SqueezeBox plug-in.

    One issue I am encountering is that you cannot define global trigger or actions for the "main" instance (i.e. the one that has a blank instance name) as well as specific ones for named instances. Is this by design? How could I define triggers and actions that apply to all instances?

    I have the main instance (with blank instance name) and several named instances. When I go to the events page, HS3 only queries for trigger and action counts and names via the named and unnamed instances but subsequent calls to build, validate, or check the configuration the ui seems only be done via calls to the main instance (i.e. with a blank instance name.

    NOTE: I updated the above text based on additional findings.
    Last edited by pcp; March 3rd, 2013, 12:01 PM. Reason: Additional details.

    Comment


    • #3
      Originally posted by rjh View Post
      A second option is supported with the property "SupportsMultipleInstancesSingleExe". If this is True, all instances are supported with one EXE. HS does not manage the instances in this mode. After your first instance is started, you can create a config page where users can add another instance. A new instance is created by calling "AddInstance(name as string)". This creates a new instance of your HSPI class and registers this with HS. The "AddInstance" function is provided to you in the HSPI_SAMPLE_BASICMI plugin sample source. Run this sample plugin to see how this works. The new instance will appear in the list of plug-ins on the HS manage plug-ins page.
      Rich,

      I noted that my .exe wasn't terminated when I stop my debugging session. The example should be extended to terminate all instances when the connection with the main thread is lost.

      I added this in the Main () procedure:

      PHP Code:
                  If Not bShutDown Then

                      
      Try
                          For 
      Each PIInstance In AllInstances
                              RemoveInstance
      (PIInstance.key)
                          
      Next
                      
      Catch ex As Exception
                          Log
      ("Error in main shutting down Instances with Error = " ex.MessageLogType.LOG_TYPE_ERROR)
                      
      End Try
                      
      gAppAPI.ShutdownIO()
                      
      Console.WriteLine("Connection lost, exiting")
                  Else
                      
      Console.WriteLine("Shutting down plugin")
                  
      End If 
      POSTEDIT: the .exe still hangs on occasion when I stop it in visual Studio and I need to stop/start HS3 again. Didn't have this before I changed it to multipleinstancesingleEXE

      Dirk
      Last edited by dcorsus; June 9th, 2013, 04:23 PM.

      Comment


      • #4
        Is the primary plugin or an instance that hangs when you shutdown? I am using the multipleinstancesingleEXE for two of my plugins and haven't run into an issue upon shutdown. I also added code to close all instances upon shutdown.

        Comment


        • #5
          Originally posted by pcp View Post
          Is the primary plugin or an instance that hangs when you shutdown? I am using the multipleinstancesingleEXE for two of my plugins and haven't run into an issue upon shutdown. I also added code to close all instances upon shutdown.
          Not sure what hangs, it is one single executable and I'm not sure what prevents windows from terminating the executable. At first when I changed the code to shutdown all instances, it appeared to work but I was wrong. It doesn't matter whether I stop the debugger or go into the "Plugin" page and disconnect the "primary PI". I'll have to rewrite the logging from the PI's terminal window so it logs to disk because I can't see what the last entries in the log are before the window closes.

          Have to admit, this multipleinstancesSingleEXE is pretty complicated and I wonder how real multipleInstances (of PI) is going to interact with this.

          Dirk

          Comment

          Working...
          X