Posts: 3,571
Joined: Sep 2009
Reputation:
110
Title says it all - are there any docs about how to do this - that is, start, stop and or restart a service add on from another add on? Or an add on tat does this so I can use the code itself as an example?
Or should my service add on basically just use sys.argv and modes to offer these start/stop methods??
Thanks as ever!
Addons I wrote &/or maintain:
OzWeather (Australian BOM weather) | Check Previous Episode | Playback Resumer | Unpause Jumpback | XSqueezeDisplay | (Legacy - XSqueeze & XZen)
Sorry, no help w/out a
*full debug log*.
Posts: 793
Joined: Oct 2010
Reputation:
17
As far as I'm aware, that's the only way to do it
Posts: 2,368
Joined: Mar 2010
Reputation:
60
giftie
Skilled Python Coder
Posts: 2,368
Since a lot of service addons run constantly(usually contain a while(1) loop) you could create a manager addon(runs as a service) that will trigger other addons. Then you could use skin properties to trigger the start of the addon(s). Not sure how your's runs though..
Posts: 2,529
Joined: Apr 2009
Reputation:
8
Start is one thing, stop is a bit harder?
It can be stopped by changing a setting in settings.xml, but that cannot be done from another addon?
Is it possible to trigger an abort request from python?
Posts: 2,529
Joined: Apr 2009
Reputation:
8
I do get the "make the while condition false and it will stop looping" part of the mystery.
I do not know how to set SomeReasonIWantToStopFor in a running instance of a service from another python script.
Posts: 3,571
Joined: Sep 2009
Reputation:
110
I basically want to build something that can a) be easily auto started (if in settings they nominate 'run at startup') - or that can be manually triggered to start/stop by another add on - this accomadates people who want to have this thing (external audio player) running all the time, and those that want it to start and stop with the addon.
So the service checks at startup to see if it should run, otherwise exits I guess? Or does it have to sleep if it's a service? There's not a lot of docs here so I can't really tell if a service is something special or jsut an addon that is called at startup...
The non-service addon then just calls the service addon with start in sys.argv and this then either actually starts up the player or reconnects to it if it is running (I can keep state in a token file or something I guess? Or, if the service addon is busy waiting, then I guess I have an isActive variable to check or whatever....
The service add on would also have a stop mode to
And restart just = call to service(stop) and then service(start)
Does that sound vaguely sensible??
Addons I wrote &/or maintain:
OzWeather (Australian BOM weather) | Check Previous Episode | Playback Resumer | Unpause Jumpback | XSqueezeDisplay | (Legacy - XSqueeze & XZen)
Sorry, no help w/out a
*full debug log*.
Posts: 2,529
Joined: Apr 2009
Reputation:
8
I dont't think you can call service(stop), that was my question but maybe I was not clear or I am badly mistaken.
If I understand it correctly you can change an addon setting to "off", have xbmc issue an abort request or you have to drop a file somewhere as a stop request. (or set some signal in another shared resource).
BTW, you can have the service and the non service part in the same add-on.
The the filecleaner mod I added a GUI to a service add-on. The advantage is that they use the same users data.
Posts: 3,571
Joined: Sep 2009
Reputation:
110
2012-06-05, 08:09
(This post was last modified: 2012-06-05, 08:15 by bossanova808.)
Well I guess in a way that's the question - is a service a re-entrant type of thing (so calling a stop method would work), or is each call to the RunScript(serveice.whatever) actually running a separate instance? (In which case it's not really a service at all, more a hack to run things at startup...)
Addons I wrote &/or maintain:
OzWeather (Australian BOM weather) | Check Previous Episode | Playback Resumer | Unpause Jumpback | XSqueezeDisplay | (Legacy - XSqueeze & XZen)
Sorry, no help w/out a
*full debug log*.
Posts: 2,529
Joined: Apr 2009
Reputation:
8
yes, that was what I meant.
Maybe it is possible, maybe xbmcaddon.Addon(id) will get you the instance if exists.
Meanwhile I am considering if it is possible to use xbmcaddon.Addon(id).setsetting.
I have not used it before but it may take care of this.
If you have an addon with a service and a program extension.
Where the service do:
while (not xbmc.abortRequested and xbmcaddon.Addon(id).getSetting("service_enabled") == "true"
and the program have a button that do
xbmcaddon.Addon(id).setSetting("service_enabled", "false")
I cant test it right now...
Posts: 793
Joined: Oct 2010
Reputation:
17
A service is just a regular addon that can be run at either startup or login. If you don't have a while loop, the service addon will exit just like any other addon.
I think the best way to manage state is by an addon setting which is not visible to the user. The you can call getSetting and setSetting to manage state. Then check that setting in each iteration of your while loop. If the setting is false, exit the while loop and the service addon will die. To start it again, call RunPlugin('plugin://service.whatever.mynameis/?key=value')
Any addon can call any other addon's getSetting and setSetting methods