Kodi Development 19.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 ATTRIBUTE_DLL_IMPORT __declspec(dllimport)
66#define ATTRIBUTE_DLL_EXPORT __declspec(dllexport)
67#define ATTRIBUTE_DLL_LOCAL
68#else
69#if __GNUC__ >= 4
70#define ATTRIBUTE_DLL_IMPORT __attribute__ ((visibility ("default")))
71#define ATTRIBUTE_DLL_EXPORT __attribute__ ((visibility ("default")))
72#define ATTRIBUTE_DLL_LOCAL __attribute__ ((visibility ("hidden")))
73#else
74#define ATTRIBUTE_DLL_IMPORT
75#define ATTRIBUTE_DLL_EXPORT
76#define ATTRIBUTE_DLL_LOCAL
77#endif
78#endif
79#define ATTRIBUTE_HIDDEN ATTRIBUTE_DLL_LOCAL // Fallback to old
81
82// Hardware specific device context interface
83#define ADDON_HARDWARE_CONTEXT void*
84
85/*
86 * To have a on add-on and kodi itself handled string always on known size!
87 */
88#define ADDON_STANDARD_STRING_LENGTH 1024
89#define ADDON_STANDARD_STRING_LENGTH_SMALL 256
90
91#ifdef __cplusplus
92extern "C"
93{
94#endif /* __cplusplus */
95
96 //============================================================================
104 typedef enum ADDON_STATUS
105 {
108
111
114
117
120
123
124 /* internal used return error if function becomes not used from child on
125 * addon */
126 ADDON_STATUS_NOT_IMPLEMENTED
127 } ADDON_STATUS;
129 //----------------------------------------------------------------------------
130
131 //============================================================================
148 typedef enum AddonLog
149 {
152
155
158
161
167 //----------------------------------------------------------------------------
168
170 typedef void* KODI_HANDLE;
171
176 {
180 };
181 typedef struct ADDON_HANDLE_STRUCT* ADDON_HANDLE;
182
193 {
194 // Pointer inside Kodi, used on callback functions to give related handle
195 // class, for this ADDON::CAddonDll inside Kodi.
196 KODI_HANDLE kodiBase;
197
198 // Function addresses used for callbacks from addon to Kodi
199 char* (*get_type_version)(void* kodiBase, int type);
200
201 void (*free_string)(void* kodiBase, char* str);
202 void (*free_string_array)(void* kodiBase, char** arr, int numElements);
203 char* (*get_addon_path)(void* kodiBase);
204 char* (*get_base_user_path)(void* kodiBase);
205 void (*addon_log_msg)(void* kodiBase, const int loglevel, const char* msg);
206
207 bool (*get_setting_bool)(void* kodiBase, const char* id, bool* value);
208 bool (*get_setting_int)(void* kodiBase, const char* id, int* value);
209 bool (*get_setting_float)(void* kodiBase, const char* id, float* value);
210 bool (*get_setting_string)(void* kodiBase, const char* id, char** value);
211
212 bool (*set_setting_bool)(void* kodiBase, const char* id, bool value);
213 bool (*set_setting_int)(void* kodiBase, const char* id, int value);
214 bool (*set_setting_float)(void* kodiBase, const char* id, float value);
215 bool (*set_setting_string)(void* kodiBase, const char* id, const char* value);
216
217 void* (*get_interface)(void* kodiBase, const char* name, const char* version);
218
219 struct AddonToKodiFuncTable_kodi* kodi;
220 struct AddonToKodiFuncTable_kodi_audioengine* kodi_audioengine;
221 struct AddonToKodiFuncTable_kodi_filesystem* kodi_filesystem;
222 struct AddonToKodiFuncTable_kodi_gui* kodi_gui;
223 struct AddonToKodiFuncTable_kodi_network* kodi_network;
224
225 // Move up by min version change about
226 bool (*is_setting_using_default)(void* kodiBase, const char* id);
228
233 {
234 void (*destroy)();
235 ADDON_STATUS (*get_status)(); // TODO unused remove by next min version increase
236 ADDON_STATUS(*create_instance)
237 (int instanceType,
238 const char* instanceID,
239 KODI_HANDLE instance,
240 const char* version,
241 KODI_HANDLE* addonInstance,
242 KODI_HANDLE parent);
243 void (*destroy_instance)(int instanceType, KODI_HANDLE instance);
244 ADDON_STATUS (*set_setting)(const char* settingName, const void* settingValue);
246
251 typedef struct AddonGlobalInterface
252 {
253 // String with full path where add-on is installed (without his name on end)
254 // Set from Kodi!
255 const char* libBasePath;
256
257 // Master API version of Kodi itself (ADDON_GLOBAL_VERSION_MAIN)
258 const char* kodi_base_api_version;
259
260 // Pointer of first created instance, used in case this add-on goes with single way
261 // Set from Kodi!
262 KODI_HANDLE firstKodiInstance;
263
264 // Pointer to master base class inside add-on
265 // Set from addon header (kodi::addon::CAddonBase)!
266 KODI_HANDLE addonBase;
267
268 // Pointer to a instance used on single way (together with this class)
269 // Set from addon header (kodi::addon::IAddonInstance)!
270 KODI_HANDLE globalSingleInstance;
271
272 // Callback function tables from addon to Kodi
273 // Set from Kodi!
275
276 // Function tables from Kodi to addon
277 // Set from addon header!
280
281#ifdef __cplusplus
282}
283#endif /* __cplusplus */
284
285#endif /* !C_API_ADDON_BASE_H */
AddonLog
Definition: addon_base.h:149
@ ADDON_LOG_FATAL
4 : To notify fatal unrecoverable errors, which can may also indicate upcoming crashes.
Definition: addon_base.h:164
@ ADDON_LOG_WARNING
2 : To write warnings in the log file.
Definition: addon_base.h:157
@ ADDON_LOG_INFO
1 : To include information messages in the log file.
Definition: addon_base.h:154
@ ADDON_LOG_DEBUG
0 : To include debug information in the log file.
Definition: addon_base.h:151
@ ADDON_LOG_ERROR
3 : To report error messages in the log file.
Definition: addon_base.h:160
ADDON_STATUS
Definition: addon_base.h:105
@ ADDON_STATUS_NEED_SETTINGS
Necessary settings are not yet set.
Definition: addon_base.h:116
@ ADDON_STATUS_LOST_CONNECTION
A needed connection was lost.
Definition: addon_base.h:110
@ ADDON_STATUS_OK
For everything OK and no error.
Definition: addon_base.h:107
@ ADDON_STATUS_NEED_RESTART
Addon needs a restart inside Kodi.
Definition: addon_base.h:113
@ ADDON_STATUS_UNKNOWN
Unknown and incomprehensible error.
Definition: addon_base.h:119
@ ADDON_STATUS_PERMANENT_FAILURE
Permanent failure, like failing to resolve methods.
Definition: addon_base.h:122
Handle used to return data from the PVR add-on to CPVRClient.
Definition: addon_base.h:176
int dataIdentifier
Definition: addon_base.h:179
void * dataAddress
Definition: addon_base.h:178
void * callerAddress
Definition: addon_base.h:177
Main structure passed from kodi to addon with basic information needed to create add-on.
Definition: addon_base.h:252
Definition: addon_base.h:193
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:233