v17 Binary Non-PVR Addon (Service/Script) is it possible?
#1
Hi,

I was wondering is it possible (supported by KODI) to create non-pvr binary addon - like script or service but using c++ instead od python. I want to create my own service addon for I2C communication along with RDS Radio program plugin (I do not particularly like PVR approach which is - imho - not suitable for Car Radio touch screen application).

Is there any guide on what functions/methods do I need to implement in my dll/so for the addon and how to prepare addon.xml (on wiki I could not even find extension point for xbmc.pvrclient which is used by other PVR plugins, so I think it's a little outdated)? Even a "Hello World" plugin like this provided for python would help me a lot.

Thanks a lot
~Kamilos

P.S.: I have been searching for answers for a long time, but could not find any thread that could satisfy my needs so I decided to create this thread

EDIT: Ok, after manually going through forums, I have found thread that answers my question. http://forum.kodi.tv/showthread.php?tid=302260

Unfortunately I cannot delete this thread.
Reply
#2
As I said in another topic, even with Python addons you can write almost everything in C/C++, except for a small launcher script that is needed to launch your addon like a normal Python addon. Below is an example of such Python/C++ addon based on "Hello World" addon and written using Pybind11 library (I don't like the raw Python/C API which is too complex for me).

hello.cpp:
Code:
#include <pybind11/pybind11.h>
#include <string>

namespace py = pybind11;

void show_hello()
{
    py::object addon = py::module::import("xbmcaddon").attr("Addon")();
    py::str py_addonname = addon.attr("getAddonInfo")("name");
    std::string addonname{ py_addonname };

    std::string line1 = "Hello World!";
    std::string line2 = "We can write anything we want here";
    std::string line3 = "using C++";

    py::object dialog = py::module::import("xbmcgui").attr("Dialog")();
    dialog.attr("ok")(addonname, line1, line2, line3);
}

PYBIND11_PLUGIN(hello)
{
    py::module mod("hello");

    mod.def("show_hello", &show_hello);

    return mod.ptr();
}

Pybind11 is a header-only library (means no linking against pre-built libs like with Boost.Python) that allows you to write binary Python modules using modern C++. The code from above needs to be compiled into a binary Python extension (basically, a shared library) for your target platform and put inside the addon folder. The addon.py from the "Hello World" addon should look like this:

Code:
from hello import show_hello

show_hello()

The rest is the same as in the example from the "Your 1st Add-On: Hello World!" forum topic.

This should work on all platforms except Android where importing binary modules is FUBAR (although possible with some magic tricks).

BTW, the code above does not need to be linked against Kodi (except on Android) so I guess it can even be closed source (not sure about API calls via string names though).
Reply
#3
That's awesome, I did not know about that, thank you very much for the example
Reply

Logout Mark Read Team Forum Stats Members Help
Binary Non-PVR Addon (Service/Script) is it possible?0