Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[addons] Thick cleaning up of the C++ API #20710

Merged
merged 17 commits into from Dec 29, 2021
Merged

Conversation

AlwinEsch
Copy link
Member

Description

Since the following requests make it necessary to re-create all add-ons (not absolutely necessary with regard to C++17), I have made a few changes here to clean up, partly to get them in the sandbox (not directly in contact with it) and to have it prepared for a feature on PVR addons to have multiple instances.

For a review, it is better to use the individual commits, as they are only indirectly related and could also come independently (only all breaks the API 😏).

I still have to change and test all addons, so I can't say 100% whether it's running correctly, especially with game addons because there it doesn't have instance support.

Motivation and context

How has this been tested?

What is the effect on users?

Screenshots (if appropriate):

Types of change

  • Bug fix (non-breaking change which fixes an issue)
  • Clean up (non-breaking change which removes non-working, unmaintained functionality)
  • Improvement (non-breaking change which improves existing functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that will cause existing functionality to change)
  • Cosmetic change (non-breaking change that doesn't touch code)
  • None of the above (please explain below)

Checklist:

  • My code follows the Code Guidelines of this project
  • My change requires a change to the documentation, either Doxygen or wiki
  • I have updated the documentation accordingly
  • I have read the Contributing document
  • I have added tests to cover my change
  • All new and existing tests passed

@AlwinEsch AlwinEsch added Type: Feature non-breaking change which adds functionality Type: Cleanup non-breaking change which removes non-working or unmaintained functionality Type: Improvement non-breaking change which improves existing functionality Component: Binary add-ons API change: Binary add-ons v20 Nexus labels Dec 21, 2021
@AlwinEsch AlwinEsch added this to the Nexus 20.0 Alpha 1 milestone Dec 21, 2021
Copy link
Member

@ksooo ksooo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. Just a question, see my review comment

@@ -337,6 +337,7 @@ class ATTR_DLL_LOCAL CAddonBase
///
CAddonBase()
{
CPrivateBase::m_interface->toAddon->create = nullptr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks strange. Where is this set and to what function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is complete unused on C++, only added to have in "C" ABI based addon case available, if becomes needed.
Was come to it as a destroy in structure, but no create and if a "C" based class handling comes somewhere, it looks more clean 😅.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay then, I was just wondering whether this is intended.

In the following changes, a min version increase is necessary, so it makes sense to remove this now because all add-ons need an update anyway.
This has not been used for some time and since the following changes result in a MIN version increase, it can be removed.
In ADDON_Create there were previously two values which are not used, they are removed because a MIN version increase is required.

Part of the previous cleanup of the API.
With the addition of "using namespace" in function, the code becomes cleaner because the line breaks are no longer necessary.
The important reason for this is to have "C" ABI more correctly, where its handling pointer is passed in every function call.

Previously this was stored in a structure on the add-on side, which is not really clean.
It is thought to have cleaner add-ons that are purely based on "C".

There will also be some commits to make it even more correct.
With this, the addon function pointers are set in the structure using typedefs, this makes it cleaner and easier to use in other places in the planned sandbox.

These typedef's are only used for calls from Kodi to addon, in the other way addon to Kodi they stay in the old way.
Previously, it was transferred to all types in one function using a `void*`, but since such use can be very dangerous and it does not work in the sandbox, it is divided into separate functions here.
On the C++ side it remains as before, since it is easier to handle in a class.
This makes a big change, with which the instance function structures are stored in Kodi's `IAddonInstanceHandler` class and a structure with union's instead of "void*" is transferred in" C ". The background is easier to expand and can also be used on the add-on side when creating an instance. The added class `IInstanceInfo` can then be used to query the values.
This makes it easier for extensions because the values in the CreateInstance function do not always have to be changed and updates with changes are required for all add-ons.
The ADDON_HANDLE is only used in PVR, since it should not be used any longer, it has now been moved to "kodi/c-api/addon-instance/pvr/pvr_defines.h" and renamed to PVR_HANDLE.
In the correct "C" ABI these are not necessary, since a `struct` must already be at begin at the positions used. Hence, it can be removed and make the code cleaner.
This revises the places where functions are located, so some of the things are moved from General.h to AddonBase.h and these then use the namespace "kodi :: addon", in the background it is more suitable to the Python addon system, where the here in the C++ moved, already in Python at self.Addon.

In addition, the new structure AddonToKodiFuncTable_kodi_addon has been added to make changes easier and not have to tackle the MIN version in the future.

Unfortunately, the parts in headers had to be moved a bit, which also made it a bit bigger in commit.
The string value kodi_base_api_version stored in the "C" structure is never used and is hereby removed as an adjustment.
With this, own functions are inserted independently of "kodi::addon" in order to call up settings in Kodi using the IAddonInstanceHandler class.
At the moment they still use the same functions as the functions in "kodi::addon::" using the "settings.xml" of the addon.
In the near future these new functions will be revised (only in Kodi's side) to allow addon instances to have their own settings (e.g. in PVR to use several backends in one addon).

The background is when this new support is introduced into Kodi, to avoid that all addons need an update again.
At the moment this call still returns the conventional add-on user class, in future changes the instance will be assigned its own user path, e.g. in the case of planned PVR add-ons which can connect different backends using different settings.

As a note on this and previous commits, the add-on documentation will be introduced and revised in a separate request. To do it in these commits would take a long time to get correct.
Previously the values were set as `void*`, since this is a bit ugly, it is replaced here with `const KODI_ADDON_BACKEND_HDL`.
In principle, this could be done at any point, but it would extremely blown the request. Since this can also be done separately (without addon updates), it is only related to AddonBase.h here.
The background is to be more in the "C" format style.
Related to changes before.

WARNING: All addons need a update about!
@AlwinEsch
Copy link
Member Author

The orgy is through so far, apart from image decoder addons are all now with requests.

I update to imagedecoder addons after this one and the other one (#20508) in Kodi. Otherwise it would be double the work.

The tests so far were OK on my Linux.
Can you then take a look and give your OK or comments?

Copy link
Member

@garbear garbear left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Game and Peripheral changes look good. I don't find m_ifc to be a very clear name, so maybe m_iface or m_interface?

@AlwinEsch
Copy link
Member Author

Also done few tests within Windows and was working too.

About m_ifc, I leave as is, is better for me, as the name only secondary and should by short as possible.
This is e.g. it will come on sandbox project:

int CAudioEncoder::Encode(int nNumBytesRead, uint8_t* pbtStream)
{
  return m_ifc->kodi_addoninstance_audioencoder_h->kodi_addon_audioencoder_encode_v1(m_addonInstance, pbtStream, nNumBytesRead);
}

The names are autogenerated and as kodi_addoninstance_audioencoder_h to part in reference to related header and kodi_addon_audioencoder_encode_v1 the name of related API function.

This both are they primary parts to know and the m_ifc only to have as something available.

@AlwinEsch
Copy link
Member Author

Can someone else look over the request and approve, want to make sure that no bad part is overseen.

@AlwinEsch AlwinEsch merged commit fa6c62e into xbmc:master Dec 29, 2021
@AlwinEsch AlwinEsch deleted the change-API branch December 29, 2021 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API change: Binary add-ons Component: Binary add-ons Type: Cleanup non-breaking change which removes non-working or unmaintained functionality Type: Feature non-breaking change which adds functionality Type: Improvement non-breaking change which improves existing functionality v20 Nexus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants