Kodi Development  20.0
for Binary and Script based Add-Ons
class CAddonBase

Detailed Description

Add-on main instance class
This is the addon main class, similar to an int main() in executable and carries out initial work and later management of it.

Modules

 Definitions, structures and enumerators
 General definition values
 

Function Documentation

◆ CAddonBase()

CAddonBase ( )
inline

Addon base class constructor.

◆ ~CAddonBase()

virtual ~CAddonBase ( )
virtualdefault

Destructor.

◆ Create()

virtual ADDON_STATUS Create ( )
inlinevirtual

Main addon creation function.

With this function addon can carry out necessary work which is required at later points or start necessary processes.

This function is optional and necessary work can also be carried out using CreateInstance (if it concerns any instance types).

Returns
ADDON_STATUS_OK if correct, for possible errors see ADDON_STATUS
Note
Terminating the add-on must be carried out using the class destructor given by child.

◆ SetSetting()

virtual ADDON_STATUS SetSetting ( const std::string &  settingName,
const kodi::CSettingValue settingValue 
)
inlinevirtual

To inform addon about changed settings values.

This becomes called for every entry defined inside his settings.xml and as last call the one where last in xml (to identify end of calls).


The following table contains values that can be set with class CSettingValue :

Name Type Get call
Settings value as string std::string GetString
Settings value as integer int GetInt
Settings value as unsigned integer unsigned int GetUInt
Settings value as boolean bool GetBoolean
Settings value as floating point float GetFloat
Settings value as enum enum GetEnum

Here is a code example how this is used:

#include <kodi/AddonBase.h>
enum myEnumValue
{
valueA,
valueB,
valueC
};
std::string m_myStringValue;
int m_myIntegerValue;
bool m_myBooleanValue;
float m_myFloatingPointValue;
myEnumValue m_myEnumValue;
ADDON_STATUS CMyAddon::SetSetting(const std::string& settingName, const kodi::CSettingValue& settingValue)
{
if (settingName == "my_string_value")
m_myStringValue = settingValue.GetString();
else if (settingName == "my_integer_value")
m_myIntegerValue = settingValue.GetInt();
else if (settingName == "my_boolean_value")
m_myBooleanValue = settingValue.GetBoolean();
else if (settingName == "my_float_value")
m_myFloatingPointValue = settingValue.GetFloat();
else if (settingName == "my_enum_value")
m_myEnumValue = settingValue.GetEnum<myEnumValue>();
}
Definition: AddonBase.h:119
ADDON_STATUS
Definition: addon_base.h:128
int GetInt() const
To get settings value as integer.
Definition: AddonBase.h:145
bool GetBoolean() const
To get settings value as boolean.
Definition: AddonBase.h:151
std::string GetString() const
To get settings value as string.
Definition: AddonBase.h:142
float GetFloat() const
To get settings value as floating point.
Definition: AddonBase.h:154
enumType GetEnum() const
To get settings value as enum.
Definition: AddonBase.h:159
Note
The asked type should match the type used on settings.xml.

◆ CreateInstance()

virtual ADDON_STATUS CreateInstance ( int  instanceType,
const std::string &  instanceID,
KODI_HANDLE  instance,
const std::string &  version,
KODI_HANDLE &  addonInstance 
)
inlinevirtual

Instance created.

Parameters
[in]instanceTypeThe requested type of required instance, see ADDON_TYPE.
[in]instanceIDAn individual identification key string given by Kodi.
[in]instanceThe instance handler used by Kodi must be passed to the classes created here. See in the example.
[in]versionThe from Kodi used version of instance. This can be used to allow compatibility to older versions of them. Further is this given to the parent instance that it can handle differences.
[out]addonInstanceThe pointer to instance class created in addon. Needed to be able to identify them on calls.
Returns
ADDON_STATUS_OK if correct, for possible errors see ADDON_STATUS

Here is a code example how this is used:

#include <kodi/AddonBase.h>
...
// If you use only one instance in your add-on, can be instanceType and
// instanceID ignored
ADDON_STATUS CMyAddon::CreateInstance(int instanceType,
const std::string& instanceID,
KODI_HANDLE instance,
const std::string& version,
KODI_HANDLE& addonInstance)
{
if (instanceType == ADDON_INSTANCE_SCREENSAVER)
{
kodi::Log(ADDON_LOG_INFO, "Creating my Screensaver");
addonInstance = new CMyScreensaver(instance);
}
else if (instanceType == ADDON_INSTANCE_VISUALIZATION)
{
kodi::Log(ADDON_LOG_INFO, "Creating my Visualization");
addonInstance = new CMyVisualization(instance);
}
else if (...)
{
...
}
}
...
@ ADDON_LOG_INFO
1 : To include information messages in the log file.
Definition: addon_base.h:177
@ ADDON_STATUS_OK
For everything OK and no error.
Definition: addon_base.h:130
@ ADDON_STATUS_UNKNOWN
Unknown and incomprehensible error.
Definition: addon_base.h:142
@ ADDON_INSTANCE_VISUALIZATION
Music visualization instance, see kodi::addon::CInstanceVisualization.
Definition: versions.h:238
@ ADDON_INSTANCE_SCREENSAVER
PVR client instance, see kodi::addon::CInstanceScreensaver.
Definition: versions.h:235
void ATTRIBUTE_HIDDEN Log(const AddonLog loglevel, const char *format,...)
Add a message to Kodi's log.
Definition: AddonBase.h:749

◆ DestroyInstance()

virtual void DestroyInstance ( int  instanceType,
const std::string &  instanceID,
KODI_HANDLE  addonInstance 
)
inlinevirtual

Instance destroy.

This function is optional and intended to notify addon that the instance is terminating.

Parameters
[in]instanceTypeThe requested type of required instance, see ADDON_TYPE.
[in]instanceIDAn individual identification key string given by Kodi.
[in]addonInstanceThe pointer to instance class created in addon.
Warning
This call is only used to inform that the associated instance is terminated. The deletion is carried out in the background.