Extending new generated api
#1
How can I extend the python interface now with the new swig system in place?

Correct me if I'm wrong, but this is isn't vanilla swig.. For instance: how do I map a simple struct?
When defining it in the .i files, I still end up with compilation error saying something like 'Cannot convert swig type'
Reply
#2
If i understood correctly you just add the C++ implementation and and include the header of c++ into the .i file.
AppleTV4/iPhone/iPod/iPad: HowTo find debug logs and everything else which the devs like so much: click here
HowTo setup NFS for Kodi: NFS (wiki)
HowTo configure avahi (zeroconf): Avahi_Zeroconf (wiki)
READ THE IOS FAQ!: iOS FAQ (wiki)
Reply
#3
See http://wiki.xbmc.org/index.php?title=Codegeneration
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
Reply
#4
@takoi, If you want to add more functionality to the python api, you should only need to add more straight c++ (non-python dependent) methods to the appropriate place in xbmc/interfaces/legacy.

If you want to add an entire class and you add a new header file. Make sure it gets included in the appropriate module *.i file in the xbmc/interfaces/swig directory.

Reply
#5
Keep in mind we're still working through bugs with this changes.
Reply
#6
So if I understand this correctly it doesnt use swig to generate code, but a custom generator written in groovy. And it doesn't support everything swig do yet (?)

For instance, if I define a simple struct in xbmc/interfaces/legacy
Code:
struct mystruct {
  int a;
  int b;
};

.. the generated code wont compile:
Code:
generated/AddonModuleXbmcvfs.cpp: In function ‘void PythonBindings::initPyXBMCAddon_xbmcvfs_mystruct_Type()’:
generated/AddonModuleXbmcvfs.cpp:892:48: error: ‘xbmcvfs_XBMCAddon_xbmcvfs_mystruct_New’ was not declared in this scope

And referencing a defined struct:
Code:
void test(struct __stat64 *s);

generates code with incorrect syntax:
Code:
__stat64 * s ;


Does this groovy codegenerator not support structs yet? Do I have to make a full blown class for this? Because, if I'm not mistaken, swig would generate this code for structs automagically.

Reply
#7
It's not full SWIG and can't be used out of the box to solve the general codegeneration case. It's meant to tie the well defined API to different bindings. You have three problems with your two examples.

1) The generated code assumes any api class (or struct) instances inherit from AddonClass.
2) You need a single constructor. (I can fix it so that it handles a default constructor if there isn't any) but if you inherit from AddonClass you'll be required to supply one anyway.
3) It doesn't handle absolutely every type (SWIG does this by shuffling around opaque references). That's overkill for this API.

I tried for quite a while to get straight SWIG code to run directly. The code it generated was unstable when run embedded with multiple interpreters and very bulky and awkward (a necessary effect of trying to solve the general case). The Groovy piece gives us much more fine grained control over the generated code but it's not meant to solve the general case of any C++ code you can imagine. Some restrictions apply (like 1 through 3 above for a rough sampling).

It will handle "Dictionary's" (see interfaces/legacy/Dictionary.h), std::map's, std::vector's and a Tuple (see interfaces/legacy/Tuple.h). Feel free to extend the template if you want.

EDIT: I supplied those examples as alternatives to your struct. Not as the full suite of what it will currently handle. /EDIT
Reply
#8
For anyone interested, I added a section to the wiki to describe how to extend the existing API:

http://wiki.xbmc.org/index.php?title=Cod...Python_API
Reply
#9
Thanks! That's very helpful
Reply
#10
If you're considering adding Callbacks, I just added a section that describes how to do that properly within XBMC:

http://wiki.xbmc.org/index.php?title=Cod...sm_in_XBMC
Reply
#11
Are there any plans on supporting fields? I mean I can wrap my 10 fields in methods no problem, but is that something you would accept in a patch?
Reply
#12

You can do read-only fields (constants) now. I am actually going to add fields. Yes. I'm just not sure when. For the time being I'd suggest wrapping them in getters and setters.
Reply
#13
I meant fields as in class members. You saying you can already can do that? How?
Reply
#14
Nope it's not yet possible but we plan to add it.
Always read the online manual (wiki), FAQ (wiki) and search the forum before posting.
Do not e-mail Team Kodi members directly asking for support. Read/follow the forum rules (wiki).
Please read the pages on troubleshooting (wiki) and bug reporting (wiki) before reporting issues.
Reply

Logout Mark Read Team Forum Stats Members Help
Extending new generated api0