summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-dev-kit/include/kodi/AddonBase.h
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2021-03-04 23:36:40 +0100
committermanuel <manuel@mausz.at>2021-03-04 23:36:40 +0100
commit3cb8aa05f8cee9e860cf83531682ff0ed4af6a4f (patch)
tree921f4829b32126f80f9113c124f2e14c0ebce8d9 /xbmc/addons/kodi-dev-kit/include/kodi/AddonBase.h
parentbe933ef2241d79558f91796cc5b3a161f72ebf9c (diff)
downloadkodi-pvr-build-3cb8aa05f8cee9e860cf83531682ff0ed4af6a4f.tar.gz
kodi-pvr-build-3cb8aa05f8cee9e860cf83531682ff0ed4af6a4f.tar.bz2
kodi-pvr-build-3cb8aa05f8cee9e860cf83531682ff0ed4af6a4f.zip
sync with upstreamMatrix
Diffstat (limited to 'xbmc/addons/kodi-dev-kit/include/kodi/AddonBase.h')
-rw-r--r--xbmc/addons/kodi-dev-kit/include/kodi/AddonBase.h216
1 files changed, 174 insertions, 42 deletions
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/AddonBase.h b/xbmc/addons/kodi-dev-kit/include/kodi/AddonBase.h
index 6ab4159..06b22d5 100644
--- a/xbmc/addons/kodi-dev-kit/include/kodi/AddonBase.h
+++ b/xbmc/addons/kodi-dev-kit/include/kodi/AddonBase.h
@@ -32,7 +32,7 @@ namespace kodi
32namespace gui 32namespace gui
33{ 33{
34struct IRenderHelper; 34struct IRenderHelper;
35} // namespace gui 35} /* namespace gui */
36 36
37//============================================================================== 37//==============================================================================
38/// @ingroup cpp_kodi_Defs 38/// @ingroup cpp_kodi_Defs
@@ -65,7 +65,8 @@ using HardwareContext = ADDON_HARDWARE_CONTEXT;
65//============================================================================== 65//==============================================================================
66/// @ingroup cpp_kodi_addon_addonbase_Defs 66/// @ingroup cpp_kodi_addon_addonbase_Defs
67/// @defgroup cpp_kodi_addon_addonbase_Defs_CSettingValue class CSettingValue 67/// @defgroup cpp_kodi_addon_addonbase_Defs_CSettingValue class CSettingValue
68/// @brief Inside addon main instance used helper class to give settings value. 68/// @brief **Setting value handler**\n
69/// Inside addon main instance used helper class to give settings value.
69/// 70///
70/// This is used on @ref addon::CAddonBase::SetSetting() to inform addon about 71/// This is used on @ref addon::CAddonBase::SetSetting() to inform addon about
71/// settings change by used. This becomes then used to give the related value 72/// settings change by used. This becomes then used to give the related value
@@ -311,23 +312,55 @@ private:
311 bool m_owner = false; 312 bool m_owner = false;
312}; 313};
313 314
314/// Add-on main instance class. 315//============================================================================
316/// @addtogroup cpp_kodi_addon_addonbase
317/// @brief **Add-on main instance class**\n
318/// This is the addon main class, similar to an <b>`int main()`</b> in executable and
319/// carries out initial work and later management of it.
320///
315class ATTRIBUTE_HIDDEN CAddonBase 321class ATTRIBUTE_HIDDEN CAddonBase
316{ 322{
317public: 323public:
324 //============================================================================
325 /// @ingroup cpp_kodi_addon_addonbase
326 /// @brief Addon base class constructor.
327 ///
318 CAddonBase() 328 CAddonBase()
319 { 329 {
320 m_interface->toAddon->destroy = ADDONBASE_Destroy; 330 m_interface->toAddon->destroy = ADDONBASE_Destroy;
321 m_interface->toAddon->get_status = ADDONBASE_GetStatus;
322 m_interface->toAddon->create_instance = ADDONBASE_CreateInstance; 331 m_interface->toAddon->create_instance = ADDONBASE_CreateInstance;
323 m_interface->toAddon->destroy_instance = ADDONBASE_DestroyInstance; 332 m_interface->toAddon->destroy_instance = ADDONBASE_DestroyInstance;
324 m_interface->toAddon->set_setting = ADDONBASE_SetSetting; 333 m_interface->toAddon->set_setting = ADDONBASE_SetSetting;
325 } 334 }
335 //----------------------------------------------------------------------------
326 336
337 //============================================================================
338 /// @ingroup cpp_kodi_addon_addonbase
339 /// @brief Destructor.
340 ///
327 virtual ~CAddonBase() = default; 341 virtual ~CAddonBase() = default;
342 //----------------------------------------------------------------------------
328 343
344 //============================================================================
345 /// @ingroup cpp_kodi_addon_addonbase
346 /// @brief Main addon creation function
347 ///
348 /// With this function addon can carry out necessary work which is required
349 /// at later points or start necessary processes.
350 ///
351 /// This function is optional and necessary work can also be carried out
352 /// using @ref CreateInstance (if it concerns any instance types).
353 ///
354 /// @return @ref ADDON_STATUS_OK if correct, for possible errors see
355 /// @ref ADDON_STATUS
356 ///
357 /// @note Terminating the add-on must be carried out using the class destructor
358 /// given by child.
359 ///
329 virtual ADDON_STATUS Create() { return ADDON_STATUS_OK; } 360 virtual ADDON_STATUS Create() { return ADDON_STATUS_OK; }
361 //----------------------------------------------------------------------------
330 362
363 // obsolete
331 virtual ADDON_STATUS GetStatus() { return ADDON_STATUS_OK; } 364 virtual ADDON_STATUS GetStatus() { return ADDON_STATUS_OK; }
332 365
333 //============================================================================ 366 //============================================================================
@@ -391,7 +424,7 @@ public:
391 /// @ingroup cpp_kodi_addon_addonbase 424 /// @ingroup cpp_kodi_addon_addonbase
392 /// @brief Instance created 425 /// @brief Instance created
393 /// 426 ///
394 /// @param[in] instanceType The requested type of required instance, see \ref ADDON_TYPE. 427 /// @param[in] instanceType The requested type of required instance, see @ref ADDON_TYPE.
395 /// @param[in] instanceID An individual identification key string given by Kodi. 428 /// @param[in] instanceID An individual identification key string given by Kodi.
396 /// @param[in] instance The instance handler used by Kodi must be passed to 429 /// @param[in] instance The instance handler used by Kodi must be passed to
397 /// the classes created here. See in the example. 430 /// the classes created here. See in the example.
@@ -401,8 +434,8 @@ public:
401 /// that it can handle differences. 434 /// that it can handle differences.
402 /// @param[out] addonInstance The pointer to instance class created in addon. 435 /// @param[out] addonInstance The pointer to instance class created in addon.
403 /// Needed to be able to identify them on calls. 436 /// Needed to be able to identify them on calls.
404 /// @return \ref ADDON_STATUS_OK if correct, for possible errors 437 /// @return @ref ADDON_STATUS_OK if correct, for possible errors
405 /// see \ref ADDON_STATUS 438 /// see @ref ADDON_STATUS
406 /// 439 ///
407 /// 440 ///
408 /// -------------------------------------------------------------------------- 441 /// --------------------------------------------------------------------------
@@ -414,8 +447,8 @@ public:
414 /// 447 ///
415 /// ... 448 /// ...
416 /// 449 ///
417 /// /* If you use only one instance in your add-on, can be instanceType and 450 /// // If you use only one instance in your add-on, can be instanceType and
418 /// * instanceID ignored */ 451 /// // instanceID ignored
419 /// ADDON_STATUS CMyAddon::CreateInstance(int instanceType, 452 /// ADDON_STATUS CMyAddon::CreateInstance(int instanceType,
420 /// const std::string& instanceID, 453 /// const std::string& instanceID,
421 /// KODI_HANDLE instance, 454 /// KODI_HANDLE instance,
@@ -462,7 +495,7 @@ public:
462 /// This function is optional and intended to notify addon that the instance 495 /// This function is optional and intended to notify addon that the instance
463 /// is terminating. 496 /// is terminating.
464 /// 497 ///
465 /// @param[in] instanceType The requested type of required instance, see \ref ADDON_TYPE. 498 /// @param[in] instanceType The requested type of required instance, see @ref ADDON_TYPE.
466 /// @param[in] instanceID An individual identification key string given by Kodi. 499 /// @param[in] instanceID An individual identification key string given by Kodi.
467 /// @param[in] addonInstance The pointer to instance class created in addon. 500 /// @param[in] addonInstance The pointer to instance class created in addon.
468 /// 501 ///
@@ -483,25 +516,19 @@ public:
483 static AddonGlobalInterface* 516 static AddonGlobalInterface*
484 m_interface; // Interface function table to hold addresses on add-on and from kodi 517 m_interface; // Interface function table to hold addresses on add-on and from kodi
485 518
486 /*private:*/ /* Needed public as long the old call functions becomes used! */ 519private:
487 static inline void ADDONBASE_Destroy() 520 static inline void ADDONBASE_Destroy()
488 { 521 {
489 delete static_cast<CAddonBase*>(m_interface->addonBase); 522 delete static_cast<CAddonBase*>(m_interface->addonBase);
490 m_interface->addonBase = nullptr; 523 m_interface->addonBase = nullptr;
491 } 524 }
492 525
493 static inline ADDON_STATUS ADDONBASE_GetStatus()
494 {
495 return static_cast<CAddonBase*>(m_interface->addonBase)->GetStatus();
496 }
497
498 static inline ADDON_STATUS ADDONBASE_SetSetting(const char* settingName, const void* settingValue) 526 static inline ADDON_STATUS ADDONBASE_SetSetting(const char* settingName, const void* settingValue)
499 { 527 {
500 return static_cast<CAddonBase*>(m_interface->addonBase) 528 return static_cast<CAddonBase*>(m_interface->addonBase)
501 ->SetSetting(settingName, CSettingValue(settingValue)); 529 ->SetSetting(settingName, CSettingValue(settingValue));
502 } 530 }
503 531
504private:
505 static inline ADDON_STATUS ADDONBASE_CreateInstance(int instanceType, 532 static inline ADDON_STATUS ADDONBASE_CreateInstance(int instanceType,
506 const char* instanceID, 533 const char* instanceID,
507 KODI_HANDLE instance, 534 KODI_HANDLE instance,
@@ -591,7 +618,7 @@ private:
591} /* namespace addon */ 618} /* namespace addon */
592 619
593//============================================================================== 620//==============================================================================
594/// @ingroup cpp_kodi_addon 621/// @ingroup cpp_kodi
595/// @brief To get used version inside Kodi itself about asked type. 622/// @brief To get used version inside Kodi itself about asked type.
596/// 623///
597/// This thought to allow a addon a handling of newer addon versions within 624/// This thought to allow a addon a handling of newer addon versions within
@@ -613,6 +640,11 @@ inline std::string ATTRIBUTE_HIDDEN GetKodiTypeVersion(int type)
613//------------------------------------------------------------------------------ 640//------------------------------------------------------------------------------
614 641
615//============================================================================== 642//==============================================================================
643/// @ingroup cpp_kodi
644/// @brief To get the addon system installation folder.
645///
646/// @param[in] append [optional] Path to append to given string
647/// @return Path where addon is installed
616/// 648///
617inline std::string ATTRIBUTE_HIDDEN GetAddonPath(const std::string& append = "") 649inline std::string ATTRIBUTE_HIDDEN GetAddonPath(const std::string& append = "")
618{ 650{
@@ -637,6 +669,14 @@ inline std::string ATTRIBUTE_HIDDEN GetAddonPath(const std::string& append = "")
637//------------------------------------------------------------------------------ 669//------------------------------------------------------------------------------
638 670
639//============================================================================== 671//==============================================================================
672/// @ingroup cpp_kodi
673/// @brief To get the user-related folder of the addon.
674///
675/// @note This folder is not created automatically and has to be created by the
676/// addon the first time.
677///
678/// @param[in] append [optional] Path to append to given string
679/// @return User path of addon
640/// 680///
641inline std::string ATTRIBUTE_HIDDEN GetBaseUserPath(const std::string& append = "") 681inline std::string ATTRIBUTE_HIDDEN GetBaseUserPath(const std::string& append = "")
642{ 682{
@@ -661,6 +701,19 @@ inline std::string ATTRIBUTE_HIDDEN GetBaseUserPath(const std::string& append =
661//------------------------------------------------------------------------------ 701//------------------------------------------------------------------------------
662 702
663//============================================================================== 703//==============================================================================
704/// @ingroup cpp_kodi
705/// @brief This function gives OS associated executable binary path of the addon.
706///
707/// With some systems this can differ from the addon path at @ref GetAddonPath.
708///
709/// As an example on Linux:
710/// - Addon path is at `/usr/share/kodi/addons/YOUR_ADDON_ID`
711/// - Library path is at `/usr/lib/kodi/addons/YOUR_ADDON_ID`
712///
713/// @note In addition, in this function, for a given folder, the add-on path
714/// itself, but its parent.
715///
716/// @return Kodi's sytem library path where related addons are installed.
664/// 717///
665inline std::string ATTRIBUTE_HIDDEN GetLibPath() 718inline std::string ATTRIBUTE_HIDDEN GetLibPath()
666{ 719{
@@ -1223,6 +1276,11 @@ inline void ATTRIBUTE_HIDDEN SetSettingEnum(const std::string& settingName, enum
1223/*!@}*/ 1276/*!@}*/
1224 1277
1225//============================================================================ 1278//============================================================================
1279/// @ingroup cpp_kodi
1280/// @brief Get to related @ref ADDON_STATUS a human readable text.
1281///
1282/// @param[in] status Status value to get name for
1283/// @return Wanted name, as "Unknown" if status not known
1226/// 1284///
1227inline std::string ATTRIBUTE_HIDDEN TranslateAddonStatus(ADDON_STATUS status) 1285inline std::string ATTRIBUTE_HIDDEN TranslateAddonStatus(ADDON_STATUS status)
1228{ 1286{
@@ -1279,16 +1337,102 @@ inline void* GetInterface(const std::string& name, const std::string& version)
1279 1337
1280} /* namespace kodi */ 1338} /* namespace kodi */
1281 1339
1282/*! addon creation macro 1340//==============================================================================
1283 * @todo cleanup this stupid big macro 1341/// @ingroup cpp_kodi_addon_addonbase_Defs
1284 * This macro includes now all for add-on's needed functions. This becomes a bigger 1342/// @defgroup cpp_kodi_addon_addonbase_Defs_ADDONCREATORAddonClass macro ADDONCREATOR(AddonClass)
1285 * rework after everything is done on Kodi itself, currently is this way needed 1343/// @brief **Addon creation macro**\n
1286 * to have compatibility with not reworked interfaces. 1344/// This export the three mandatory "C" functions to have available for Kodi.
1287 * 1345///
1288 * Becomes really cleaned up soon :D 1346/// @note Only this macro can be used on a C++ addon, everything else is done
1289 */ 1347/// automatically.
1348///
1349/// @param[in] AddonClass Used addon class to be exported with CAddonBase as
1350/// parent.
1351///
1352///
1353/// ----------------------------------------------------------------------------
1354///
1355/// **Example:**
1356/// ~~~~~~~~~~~~~{.cpp}
1357///
1358/// #include <kodi/AddonBash.h>
1359///
1360/// class CMyAddon : public kodi::addon::CAddonBase
1361/// {
1362/// public:
1363/// CMyAddon() = default;
1364/// ADDON_STATUS Create() override;
1365/// };
1366///
1367/// ADDON_STATUS CMyAddon::Create()
1368/// {
1369/// // Some work
1370///
1371/// return ADDON_STATUS_OK;
1372/// }
1373///
1374/// ADDONCREATOR(CMyAddon)
1375/// ~~~~~~~~~~~~~
1376///
1377/// ----------------------------------------------------------------------------
1378///
1379/// As information, the following functions are exported using this macro:
1380/// \table_start
1381/// \table_h3{ Function, Use, Description }
1382/// \table_row3{ <b>`ADDON_Create(KODI_HANDLE addonInterface\, const char* globalApiVersion\, void* unused)`</b>,
1383/// \anchor ADDON_Create
1384/// _required_,
1385/// <b>Addon creation call.</b>
1386/// <br>
1387/// Like an `int main()` is this the first on addon called place on his start
1388/// and create within C++ API related class inside addon.
1389/// <br>
1390/// @param[in] addonInterface Handle pointer to get Kodi's given table.
1391/// There have addon needed values and functions
1392/// to Kodi and addon must set his functions there
1393/// for Kodi.
1394/// @param[in] globalApiVersion This give the main version @ref ADDON_GLOBAL_VERSION_MAIN
1395/// where currently on Kodi's side.<br>
1396/// This is unsued on addon as there also other
1397/// special callback functions for.<br>
1398/// Only thought for future use if needed earlier.
1399/// @param[in] unused This is a not used value\, only there to have in case of
1400/// need no Major API version increase where break current.
1401/// @return @ref ADDON_STATUS_OK if correct\, for possible errors see
1402/// @ref ADDON_STATUS.
1403/// <p>
1404/// }
1405/// \table_row3{ <b>`const char* ADDON_GetTypeVersion(int type)`</b>,
1406/// \anchor ADDON_GetTypeVersion
1407/// _required_,
1408/// <b>Ask addon about version of given type.</b>
1409/// <br>
1410/// This is used to query its associated version in the addon before work
1411/// is carried out in it and the Kodi can adapt to it.
1412/// <br>
1413/// @param[in] type With @ref ADDON_TYPE defined type to ask.
1414/// @return Version as string of asked type.
1415/// <p>
1416/// }
1417/// \table_row3{ <b>`const char* ADDON_GetTypeMinVersion(int type)`</b>,
1418/// \anchor ADDON_GetTypeMinVersion
1419/// _optional_,
1420/// <b>Ask addon about minimal version of given type.</b>
1421/// <br>
1422/// This is used to query its associated min version in the addon before work
1423/// is carried out in it and the Kodi can adapt to it.
1424/// <br>
1425/// @note The minimum version is optional\, if it were not available\, the
1426/// major version is used instead.
1427/// <br>
1428/// @param[in] type With @ref ADDON_TYPE defined type to ask.
1429/// @return Min version as string of asked type.
1430/// <p>
1431/// }
1432/// \table_end
1433///
1290#define ADDONCREATOR(AddonClass) \ 1434#define ADDONCREATOR(AddonClass) \
1291 extern "C" __declspec(dllexport) ADDON_STATUS ADDON_Create( \ 1435 extern "C" ATTRIBUTE_DLL_EXPORT ADDON_STATUS ADDON_Create( \
1292 KODI_HANDLE addonInterface, const char* /*globalApiVersion*/, void* /*unused*/) \ 1436 KODI_HANDLE addonInterface, const char* /*globalApiVersion*/, void* /*unused*/) \
1293 { \ 1437 { \
1294 kodi::addon::CAddonBase::m_interface = static_cast<AddonGlobalInterface*>(addonInterface); \ 1438 kodi::addon::CAddonBase::m_interface = static_cast<AddonGlobalInterface*>(addonInterface); \
@@ -1296,27 +1440,15 @@ inline void* GetInterface(const std::string& name, const std::string& version)
1296 return static_cast<kodi::addon::CAddonBase*>(kodi::addon::CAddonBase::m_interface->addonBase) \ 1440 return static_cast<kodi::addon::CAddonBase*>(kodi::addon::CAddonBase::m_interface->addonBase) \
1297 ->Create(); \ 1441 ->Create(); \
1298 } \ 1442 } \
1299 extern "C" __declspec(dllexport) void ADDON_Destroy() \ 1443 extern "C" ATTRIBUTE_DLL_EXPORT const char* ADDON_GetTypeVersion(int type) \
1300 { \
1301 kodi::addon::CAddonBase::ADDONBASE_Destroy(); \
1302 } \
1303 extern "C" __declspec(dllexport) ADDON_STATUS ADDON_GetStatus() \
1304 { \
1305 return kodi::addon::CAddonBase::ADDONBASE_GetStatus(); \
1306 } \
1307 extern "C" __declspec(dllexport) ADDON_STATUS ADDON_SetSetting(const char* settingName, \
1308 const void* settingValue) \
1309 { \
1310 return kodi::addon::CAddonBase::ADDONBASE_SetSetting(settingName, settingValue); \
1311 } \
1312 extern "C" __declspec(dllexport) const char* ADDON_GetTypeVersion(int type) \
1313 { \ 1444 { \
1314 return kodi::addon::GetTypeVersion(type); \ 1445 return kodi::addon::GetTypeVersion(type); \
1315 } \ 1446 } \
1316 extern "C" __declspec(dllexport) const char* ADDON_GetTypeMinVersion(int type) \ 1447 extern "C" ATTRIBUTE_DLL_EXPORT const char* ADDON_GetTypeMinVersion(int type) \
1317 { \ 1448 { \
1318 return kodi::addon::GetTypeMinVersion(type); \ 1449 return kodi::addon::GetTypeMinVersion(type); \
1319 } \ 1450 } \
1320 AddonGlobalInterface* kodi::addon::CAddonBase::m_interface = nullptr; 1451 AddonGlobalInterface* kodi::addon::CAddonBase::m_interface = nullptr;
1452//------------------------------------------------------------------------------
1321 1453
1322#endif /* __cplusplus */ 1454#endif /* __cplusplus */