Kodi Documentation 22.0
Kodi is an open source media player and entertainment hub.
Loading...
Searching...
No Matches
class CAddonBase

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. More...

Topics

 Definitions, structures and enumerators
 General definition values
 

Functions

 kodi::addon::CAddonBase::CAddonBase ()
 Addon base class constructor.
 
virtual kodi::addon::CAddonBase::~CAddonBase ()=default
 Destructor.
 
virtual ADDON_STATUS kodi::addon::CAddonBase::Create ()
 Main addon creation function.
 
virtual ADDON_STATUS kodi::addon::CAddonBase::SetSetting (const std::string &settingName, const kodi::addon::CSettingValue &settingValue)
 To inform addon about changed settings values.
 
virtual ADDON_STATUS kodi::addon::CAddonBase::CreateInstance (const kodi::addon::IInstanceInfo &instance, KODI_ADDON_INSTANCE_HDL &hdl)
 Instance created.
 
virtual void kodi::addon::CAddonBase::DestroyInstance (const IInstanceInfo &instance, const KODI_ADDON_INSTANCE_HDL hdl)
 Instance destroy.
 

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.

Function Documentation

◆ CAddonBase()

kodi::addon::CAddonBase::CAddonBase ( )
inline

Addon base class constructor.

◆ Create()

virtual ADDON_STATUS kodi::addon::CAddonBase::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.

◆ CreateInstance()

virtual ADDON_STATUS kodi::addon::CAddonBase::CreateInstance ( const kodi::addon::IInstanceInfo & instance,
KODI_ADDON_INSTANCE_HDL & hdl )
inlinevirtual

Instance created.

Parameters
[in]instanceInstance informations about
[out]hdlThe 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(const kodi::addon::IInstanceInfo& instance,
{
{
kodi::Log(ADDON_LOG_INFO, "Creating my Screensaver");
hdl = new CMyScreensaver(instance);
}
{
kodi::Log(ADDON_LOG_INFO, "Creating my Visualization");
hdl = new CMyVisualization(instance);
}
else if (...)
{
...
}
}
...
void * KODI_ADDON_INSTANCE_HDL
Definition addon_base.h:121
KODI_ADDON_HDL * hdl
Definition addon_base.h:344
Definition kodi-dev-kit/include/kodi/AddonBase.h:498
@ ADDON_LOG_INFO
1 : To include information messages in the log file.
Definition addon_base.h:187
@ ADDON_STATUS_OK
For everything OK and no error.
Definition addon_base.h:140
@ ADDON_STATUS_UNKNOWN
Unknown and incomprehensible error.
Definition addon_base.h:152
@ ADDON_INSTANCE_VISUALIZATION
Music visualization instance, see kodi::addon::CInstanceVisualization.
Definition versions.h:240
@ ADDON_INSTANCE_SCREENSAVER
Screen saver instance, see kodi::addon::CInstanceScreensaver.
Definition versions.h:237
void ATTR_DLL_LOCAL Log(const ADDON_LOG loglevel, const char *format,...)
Add a message to Kodi's log.
Definition kodi-dev-kit/include/kodi/AddonBase.h:1938
Definition addon_base.h:268

◆ DestroyInstance()

virtual void kodi::addon::CAddonBase::DestroyInstance ( const IInstanceInfo & instance,
const KODI_ADDON_INSTANCE_HDL hdl )
inlinevirtual

Instance destroy.

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

Parameters
[in]instanceInstance informations about
[in]hdlThe 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.

◆ SetSetting()

virtual ADDON_STATUS kodi::addon::CAddonBase::SetSetting ( const std::string & settingName,
const kodi::addon::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::addon::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 kodi-dev-kit/include/kodi/AddonBase.h:437
ADDON_STATUS
Definition addon_base.h:138
const std::string & GetString() const
To get settings value as string.
Definition kodi-dev-kit/include/kodi/AddonBase.h:460
bool GetBoolean() const
To get settings value as boolean.
Definition kodi-dev-kit/include/kodi/AddonBase.h:469
float GetFloat() const
To get settings value as floating point.
Definition kodi-dev-kit/include/kodi/AddonBase.h:472
enumType GetEnum() const
To get settings value as enum.
Definition kodi-dev-kit/include/kodi/AddonBase.h:477
int GetInt() const
To get settings value as integer.
Definition kodi-dev-kit/include/kodi/AddonBase.h:463
Note
The asked type should match the type used on settings.xml.

◆ ~CAddonBase()

virtual kodi::addon::CAddonBase::~CAddonBase ( )
virtualdefault

Destructor.