Reference to Current Plugin in External Thread

Posted on
Sat Mar 18, 2017 10:49 pm
RogueProeliator offline
User avatar
Posts: 2501
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Reference to Current Plugin in External Thread

Okay... so I have run into an issue that I am not quite sure to solve in the most "Pythonic" way. The setup is that I have a plugin that launches a socket server (standard Python ThreadedTCPServer that is using a ThreadedTCPRequestHandler to handle the requests that come in.

Inside of this request handler, I need to be able to dispatch actions to arbitrary plugins -- works great via a simple:
Code: Select all
# get the plugin that was requested from the indigo server
indigoPlugin = indigo.server.getPlugin(pluginId)
               
if indigoPlugin is None:
     commandResponse = u'ERROR: Invalid plugin specified'
else:
     actionPropDict = eval(actionProps)
     indigoPlugin.executeAction(actionId, deviceId=int(deviceId), props=actionPropDict)
     commandResponse = u'OK'


The issue comes in whenever the pluginId happens to be the same plugin in which the socket server is running -- "InternalError -- cannot dispatch plugin method ExecuteAction back to the same plugin (com.duncanware.domoPadMobileClient)". I assume this is due to an attempt at inter-process communications but it is trying to talk back to itself. I get that, no problem... but the response server has no way to reference the current plugin class directly. SO, I know a few ways to handle this in other languages but what about Python -- what would be the best approach here?

Thanks!

Posted on
Sun Mar 19, 2017 12:39 pm
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: Reference to Current Plugin in External Thread

When you create the socket server can you pass it the current plugins's ID, then inside your action dispatch compare that to the ID of the target action? Also, indigo.activePlugin contains the plugin instance of the hosted plugin being run, so you can dispatch the action call to that.

Image

Posted on
Sun Mar 19, 2017 12:48 pm
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Reference to Current Plugin in External Thread

You could create a queue in your plugin and pass that to the threads which could just add a message to the queue and have the plugin (in RCT) pick messages off and do whatever. More work, but it's a reasonable approach as well.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Mar 19, 2017 10:02 pm
RogueProeliator offline
User avatar
Posts: 2501
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: Reference to Current Plugin in External Thread

When you create the socket server can you pass it the current plugins's ID, then inside your action dispatch compare that to the ID of the target action? Also, indigo.activePlugin contains the plugin instance of the hosted plugin being run, so you can dispatch the action call to that.

Thanks for the responses, guys... this activePlugin worked beautifully as it fell in line with the existing code which gets the plugin via its ID. Jay, your solution was one I had considered, but since I had other code that required going through the plugin object, it would have been a rather significantly different branch of code to accomplish the same thing as the non-current plugins. I'll keep that in mind as an acceptable method if a similar situation comes up in the future. Thanks again, that got me moving forward!

Adam

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests