Posts: 240
Joined: Mar 2014
Reputation:
6
Hi,
The addon i'm creating has a need to be run continuously in the background to store and up data in the background. However it also requires a gui for interaction with the data like a regular plugin.
I'm wondering the best way to handle this as i'm not sure how to have a service running and the a separate entry point like a regular plugin to manage the gui.
Atm I have it setup in the addon xml like so:
<extension point="xbmc.service" library="startup.py" start="[login|startup]">
</extension>
<extension point="xbmc.python.pluginsource" library="pluginStartup.py">
<provides>video</provides>
</extension>
the first bit runs the service which continues in it's own thread in the background.
The second adds a entry to the video addons section in xbmc and runs when selected. However as it's treated as a completely separate addon has no access to any data from the service.
Is there anything I can do to share the data from the service with the video addon?
removed151214
Unregistered
removed151214
Unregistered
Posts: N/A
One possibility is the way that the
library data provider script works - the service element saves the data to window properties, the plugin element reads it from them. (Or check out older revisions, where the service element saved the data to disk, which was actually a lot better in terms of avoiding race conditions, though it was slower and caused a lot more disk i/o).
Posts: 240
Joined: Mar 2014
Reputation:
6
Thanks,
Will check it out and hopefully I can add some form of checking to avoid racing situations once I have a solution working.
Also if possible it would be much easier if I could add a listing to the program or video add on directories from the service scripts and tie that to a function call. Or even just have a key listener if that is possible?
removed151214
Unregistered
removed151214
Unregistered
Posts: N/A
(2014-06-28, 23:42)ianuk2005 Wrote: Thanks,
Will check it out and hopefully I can add some form of checking to avoid racing situations once I have a solution working.
Library data provider has some, it's just not as good as locking a file!
(2014-06-28, 23:42)ianuk2005 Wrote: Also if possible it would be much easier if I could add a listing to the program or video add on directories from the service scripts and tie that to a function call. Or even just have a key listener if that is possible?
You mean have the plugin be able to trigger an update of data? Library data provider has that as well.
Posts: 240
Joined: Mar 2014
Reputation:
6
No, I mean instead of having this:
<extension point="xbmc.python.pluginsource" library="pluginStartup.py">
<provides>video</provides>
</extension>
To add a listing to the video add ons directory. Could I do that programmatically in my service script so I don't to run them as 2 independent scripts?
removed151214
Unregistered
removed151214
Unregistered
Posts: N/A
To the best of my knowledge you can't do that. You need two entry points in your addon.xml file.
They could both link to the same .py file (though this would probably cause problems down the line), but even then they'd run as two separate instances.
removed151214
Unregistered
removed151214
Unregistered
Posts: N/A
A lot of python objects can be repr()'ed and then eval()'ed, unfortunately XBMC items like xbmcgui.ListItem don't support this so, yes, (until someone comes along with a better method), need to be built on the plugin side from the services data.
Posts: 1,088
Joined: Nov 2012
Reputation:
51
What object do you need to send?
A list/dict/tuple can be sent as a string really easily, and then ast.literal_eval() can change it back into the list/dict/tuple.
For sending other stuff, a combination of pickle and SOCKET would do it, I think. I havent implemented that myself so cant say for sure.
Posts: 240
Joined: Mar 2014
Reputation:
6
Ideally a full class with all variables and function access. The service holds a majority of the library data which has been fetched using the json RPC api in the background. That data is then organised for user defined channels and updated in the background.
The GUI needs to be able to read all the channels data to display. It also needs to be able to edit this data as the user interacts with it.
It also needs to access all the data the service has gotten from the json RPC calls for creating new channels. It also needs to be able to tell the service to get more data if it needs it.
I'm not sure using pickle or json will cut it as its way to much data to continuesly serialise/deserialise. The whole reason I made it as a service was to avoid long delays parsing data when they open up the GUI.
Posts: 240
Joined: Mar 2014
Reputation:
6
Doing some digging and storing complex data (classes) between scripts just seems like a total no go with python.
I guess my optimal solution if possible is to have a way to open a gui from the service. Is there any way to have a gui open by a key press, add it to a menu or anything else that a user can trigger?
Posts: 240
Joined: Mar 2014
Reputation:
6
Was just looking more at pickle, it's actually really good and can store complex data much better than json. I can save out a full class structure with lists of other instanced classes with data and it rebuilds it all when you load it in which works really well and quick. Will definitely be using it for storing data between sessions!
Your last post just gave me an idea though. The addons entry point now set's a single persistent property "openGui:bool". And in the services main loop it checks if it's true and if so starts a new thread for the gui which can access all the services data.
Problem solved, should have figured this ouch much quicker!