Service/Gui interaction - multiple entry points
#1
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?
Reply
#2
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).
Reply
#3
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?
Reply
#4
(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.
Reply
#5
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?
Reply
#6
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.
Reply
#7
Damn just checking out the setProperty stuff that library data provider uses. It seems it only supports saving string data rather than complex object Sad

I might be able to take everything down to json and rebuild it for the gui but it would be a massive error prone process =[
Reply
#8
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.
Reply
#9
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.
Reply
#10
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.
Reply
#11
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?
Reply
#12
(2014-06-29, 00:48)ianuk2005 Wrote: 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.

Thats also why I made LazyTV a service and a script. On a normal PC the script-only solution was fast enough, but it was taking too long to run on the RPi. Now it doesnt take too long to get all the data from the service, but it is not a lot of data I suppose. The script talks to the service about only a couple of things, I just have the loop in the service constantly checking the communication property stored in home. Also, the update of data is structured and not continuous (at most it requires a manual refresh), so that helps too.

Could you separate the background function in the service on to a different thread and have the gui (on its own thread) launched by the script? I have only started trying to get my head around threading, so not sure how this would work in practice.
Reply
#13
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!
Reply

Logout Mark Read Team Forum Stats Members Help
Service/Gui interaction - multiple entry points0