Kodi Development  20.0
for Binary and Script based Add-Ons
addon_base.h
1 /*
2  * Copyright (C) 2005-2019 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #ifndef C_API_ADDON_BASE_H
10 #define C_API_ADDON_BASE_H
11 
12 #if !defined(NOMINMAX)
13 #define NOMINMAX
14 #endif
15 
16 #include "stdbool.h"
17 #include "stdint.h"
18 
19 #ifndef TARGET_WINDOWS
20 #ifndef __cdecl
21 #define __cdecl
22 #endif
23 #ifndef __declspec
24 #define __declspec(X)
25 #endif
26 #endif
27 
28 // Generic helper definitions for smallest possible alignment
30 #undef ATTRIBUTE_PACKED
31 #undef PRAGMA_PACK_BEGIN
32 #undef PRAGMA_PACK_END
33 
34 #if defined(__GNUC__)
35 #define ATTRIBUTE_PACKED __attribute__((packed))
36 #define PRAGMA_PACK 0
37 #endif
38 
39 #if !defined(ATTRIBUTE_PACKED)
40 #define ATTRIBUTE_PACKED
41 #define PRAGMA_PACK 1
42 #endif
44 
45 // Generic helper definitions for inline function support
47 #ifdef _MSC_VER
48 #define ATTRIBUTE_FORCEINLINE __forceinline
49 #elif defined(__GNUC__)
50 #define ATTRIBUTE_FORCEINLINE inline __attribute__((__always_inline__))
51 #elif defined(__CLANG__)
52 #if __has_attribute(__always_inline__)
53 #define ATTRIBUTE_FORCEINLINE inline __attribute__((__always_inline__))
54 #else
55 #define ATTRIBUTE_FORCEINLINE inline
56 #endif
57 #else
58 #define ATTRIBUTE_FORCEINLINE inline
59 #endif
61 
62 // Generic helper definitions for shared library support
64 #if defined _WIN32 || defined __CYGWIN__
65 #define ATTR_DLL_IMPORT __declspec(dllimport)
66 #define ATTR_DLL_EXPORT __declspec(dllexport)
67 #define ATTR_DLL_LOCAL
68 #define ATTR_APIENTRY __stdcall
69 #else
70 #if __GNUC__ >= 4
71 #define ATTR_DLL_IMPORT __attribute__((visibility("default")))
72 #define ATTR_DLL_EXPORT __attribute__((visibility("default")))
73 #define ATTR_DLL_LOCAL __attribute__((visibility("hidden")))
74 #else
75 #define ATTR_DLL_IMPORT
76 #define ATTR_DLL_EXPORT
77 #define ATTR_DLL_LOCAL
78 #endif
79 #define ATTR_APIENTRY
80 #endif
81 
82 #ifndef ATTR_APIENTRYP
83 #define ATTR_APIENTRYP ATTR_APIENTRY*
84 #endif
85 
86 // Fallbacks to old
87 #define ATTRIBUTE_DLL_IMPORT ATTR_DLL_IMPORT
88 #define ATTRIBUTE_DLL_EXPORT ATTR_DLL_EXPORT
89 #define ATTRIBUTE_DLL_LOCAL ATTR_DLL_LOCAL
90 #define ATTRIBUTE_HIDDEN ATTR_DLL_LOCAL
92 
93 #ifdef _WIN32 // windows
94 #if !defined(_SSIZE_T_DEFINED) && !defined(HAVE_SSIZE_T)
95 typedef intptr_t ssize_t;
96 #define _SSIZE_T_DEFINED
97 #endif // !_SSIZE_T_DEFINED
98 #ifndef SSIZE_MAX
99 #define SSIZE_MAX INTPTR_MAX
100 #endif // !SSIZE_MAX
101 #else // Linux, Mac, FreeBSD
102 #include <sys/types.h>
103 #endif // TARGET_POSIX
104 
105 // Hardware specific device context interface
106 #define ADDON_HARDWARE_CONTEXT void*
107 
108 /*
109  * To have a on add-on and kodi itself handled string always on known size!
110  */
111 #define ADDON_STANDARD_STRING_LENGTH 1024
112 #define ADDON_STANDARD_STRING_LENGTH_SMALL 256
113 
114 #ifdef __cplusplus
115 extern "C"
116 {
117 #endif /* __cplusplus */
118 
119  //============================================================================
127  typedef enum ADDON_STATUS
128  {
131 
134 
137 
140 
143 
146 
147  /* internal used return error if function becomes not used from child on
148  * addon */
149  ADDON_STATUS_NOT_IMPLEMENTED
150  } ADDON_STATUS;
152  //----------------------------------------------------------------------------
153 
154  //============================================================================
171  typedef enum AddonLog
172  {
175 
178 
181 
184 
187  ADDON_LOG_FATAL = 4
190  //----------------------------------------------------------------------------
191 
193  typedef void* KODI_HANDLE;
194 
199  {
201  void* dataAddress;
203  };
204  typedef struct ADDON_HANDLE_STRUCT* ADDON_HANDLE;
205 
216  {
217  // Pointer inside Kodi, used on callback functions to give related handle
218  // class, for this ADDON::CAddonDll inside Kodi.
219  KODI_HANDLE kodiBase;
220 
221  // Function addresses used for callbacks from addon to Kodi
222  char* (*get_type_version)(void* kodiBase, int type);
223 
224  void (*free_string)(void* kodiBase, char* str);
225  void (*free_string_array)(void* kodiBase, char** arr, int numElements);
226  char* (*get_addon_path)(void* kodiBase);
227  char* (*get_base_user_path)(void* kodiBase);
228  void (*addon_log_msg)(void* kodiBase, const int loglevel, const char* msg);
229 
230  bool (*get_setting_bool)(void* kodiBase, const char* id, bool* value);
231  bool (*get_setting_int)(void* kodiBase, const char* id, int* value);
232  bool (*get_setting_float)(void* kodiBase, const char* id, float* value);
233  bool (*get_setting_string)(void* kodiBase, const char* id, char** value);
234 
235  bool (*set_setting_bool)(void* kodiBase, const char* id, bool value);
236  bool (*set_setting_int)(void* kodiBase, const char* id, int value);
237  bool (*set_setting_float)(void* kodiBase, const char* id, float value);
238  bool (*set_setting_string)(void* kodiBase, const char* id, const char* value);
239 
240  void* (*get_interface)(void* kodiBase, const char* name, const char* version);
241 
242  struct AddonToKodiFuncTable_kodi* kodi;
243  struct AddonToKodiFuncTable_kodi_audioengine* kodi_audioengine;
244  struct AddonToKodiFuncTable_kodi_filesystem* kodi_filesystem;
245  struct AddonToKodiFuncTable_kodi_gui* kodi_gui;
246  struct AddonToKodiFuncTable_kodi_network* kodi_network;
247 
248  // Move up by min version change about
249  bool (*is_setting_using_default)(void* kodiBase, const char* id);
251 
256  {
257  void (*destroy)();
258  ADDON_STATUS (*get_status)(); // TODO unused remove by next min version increase
259  ADDON_STATUS(*create_instance)
260  (int instanceType,
261  const char* instanceID,
262  KODI_HANDLE instance,
263  const char* version,
264  KODI_HANDLE* addonInstance,
265  KODI_HANDLE parent);
266  void (*destroy_instance)(int instanceType, KODI_HANDLE instance);
267  ADDON_STATUS (*set_setting)(const char* settingName, const void* settingValue);
269 
274  typedef struct AddonGlobalInterface
275  {
276  // String with full path where add-on is installed (without his name on end)
277  // Set from Kodi!
278  const char* libBasePath;
279 
280  // Master API version of Kodi itself (ADDON_GLOBAL_VERSION_MAIN)
281  const char* kodi_base_api_version;
282 
283  // Pointer of first created instance, used in case this add-on goes with single way
284  // Set from Kodi!
285  KODI_HANDLE firstKodiInstance;
286 
287  // Pointer to master base class inside add-on
288  // Set from addon header (kodi::addon::CAddonBase)!
289  KODI_HANDLE addonBase;
290 
291  // Pointer to a instance used on single way (together with this class)
292  // Set from addon header (kodi::addon::IAddonInstance)!
293  KODI_HANDLE globalSingleInstance;
294 
295  // Callback function tables from addon to Kodi
296  // Set from Kodi!
298 
299  // Function tables from Kodi to addon
300  // Set from addon header!
303 
304 #ifdef __cplusplus
305 }
306 #endif /* __cplusplus */
307 
308 #endif /* !C_API_ADDON_BASE_H */
AddonLog
Definition: addon_base.h:172
@ ADDON_LOG_FATAL
4 : To notify fatal unrecoverable errors, which can may also indicate upcoming crashes.
Definition: addon_base.h:187
@ ADDON_LOG_WARNING
2 : To write warnings in the log file.
Definition: addon_base.h:180
@ ADDON_LOG_INFO
1 : To include information messages in the log file.
Definition: addon_base.h:177
@ ADDON_LOG_DEBUG
0 : To include debug information in the log file.
Definition: addon_base.h:174
@ ADDON_LOG_ERROR
3 : To report error messages in the log file.
Definition: addon_base.h:183
ADDON_STATUS
Definition: addon_base.h:128
@ ADDON_STATUS_NEED_SETTINGS
Necessary settings are not yet set.
Definition: addon_base.h:139
@ ADDON_STATUS_LOST_CONNECTION
A needed connection was lost.
Definition: addon_base.h:133
@ ADDON_STATUS_OK
For everything OK and no error.
Definition: addon_base.h:130
@ ADDON_STATUS_NEED_RESTART
Addon needs a restart inside Kodi.
Definition: addon_base.h:136
@ ADDON_STATUS_UNKNOWN
Unknown and incomprehensible error.
Definition: addon_base.h:142
@ ADDON_STATUS_PERMANENT_FAILURE
Permanent failure, like failing to resolve methods.
Definition: addon_base.h:145
Handle used to return data from the PVR add-on to CPVRClient.
Definition: addon_base.h:199
int dataIdentifier
Definition: addon_base.h:202
void * dataAddress
Definition: addon_base.h:201
void * callerAddress
Definition: addon_base.h:200
Main structure passed from kodi to addon with basic information needed to create add-on.
Definition: addon_base.h:275
Definition: addon_base.h:216
Definition: audio_engine.h:267
Definition: filesystem.h:246
Definition: definitions.h:52
Definition: network.h:31
Definition: general.h:88
Function tables from Kodi to addon.
Definition: addon_base.h:256