Kodi Development 22.0
for Binary and Script based Add-Ons
 
Loading...
Searching...
No Matches
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 <stddef.h>
18#include <stdint.h>
19
20#ifndef TARGET_WINDOWS
21#ifndef __cdecl
22#define __cdecl
23#endif
24#ifndef __declspec
25#define __declspec(X)
26#endif
27#endif
28
29// Generic helper definitions for smallest possible alignment
31#undef ATTR_PACKED
32#undef PRAGMA_PACK_BEGIN
33#undef PRAGMA_PACK_END
34
35#if defined(__GNUC__)
36#define ATTR_PACKED __attribute__((packed))
37#define PRAGMA_PACK 0
38#endif
39
40#if !defined(ATTR_PACKED)
41#define ATTR_PACKED
42#define PRAGMA_PACK 1
43#endif
45
46// Generic helper definitions for inline function support
48#ifdef _MSC_VER
49#define ATTR_FORCEINLINE __forceinline
50#elif defined(__GNUC__)
51#define ATTR_FORCEINLINE inline __attribute__((__always_inline__))
52#elif defined(__CLANG__)
53#if __has_attribute(__always_inline__)
54#define ATTR_FORCEINLINE inline __attribute__((__always_inline__))
55#else
56#define ATTR_FORCEINLINE inline
57#endif
58#else
59#define ATTR_FORCEINLINE inline
60#endif
62
63// Generic helper definitions for shared library support
65#if defined _WIN32 || defined _WIN64 || defined __CYGWIN__
66#define ATTR_DLL_IMPORT __declspec(dllimport)
67#define ATTR_DLL_EXPORT __declspec(dllexport)
68#define ATTR_DLL_LOCAL
69#ifdef _WIN64
70#define ATTR_APIENTRY __stdcall
71#else
72#define ATTR_APIENTRY __cdecl
73#endif
74#else
75#if __GNUC__ >= 4
76#define ATTR_DLL_IMPORT __attribute__((visibility("default")))
77#define ATTR_DLL_EXPORT __attribute__((visibility("default")))
78#ifndef SWIG
79#define ATTR_DLL_LOCAL __attribute__((visibility("hidden")))
80#else
81#define ATTR_DLL_LOCAL
82#endif
83#else
84#define ATTR_DLL_IMPORT
85#define ATTR_DLL_EXPORT
86#define ATTR_DLL_LOCAL
87#endif
88#define ATTR_APIENTRY
89#endif
90
91#ifndef ATTR_APIENTRYP
92#define ATTR_APIENTRYP ATTR_APIENTRY*
93#endif
95
96#ifdef _WIN32 // windows
97#if !defined(_SSIZE_T_DEFINED) && !defined(HAVE_SSIZE_T)
98#include <BaseTsd.h>
99typedef SSIZE_T ssize_t;
100#define _SSIZE_T_DEFINED
101#endif // !_SSIZE_T_DEFINED
102#ifndef SSIZE_MAX
103#define SSIZE_MAX INTPTR_MAX
104#endif // !SSIZE_MAX
105#else // Linux, Mac, FreeBSD
106#include <sys/types.h>
107#endif // TARGET_POSIX
108
109/*
110 * To have a on add-on and kodi itself handled string always on known size!
111 */
112#define ADDON_STANDARD_STRING_LENGTH 1024
113#define ADDON_STANDARD_STRING_LENGTH_SMALL 256
114
115#ifdef __cplusplus
116extern "C"
117{
118#endif /* __cplusplus */
119
120 typedef void* KODI_ADDON_HDL;
121 typedef void* KODI_ADDON_BACKEND_HDL;
122 typedef void* KODI_ADDON_INSTANCE_HDL;
123 typedef void* KODI_ADDON_INSTANCE_BACKEND_HDL;
124
125 // Hardware specific device context interface
126 typedef void* ADDON_HARDWARE_CONTEXT;
127
128 typedef void* KODI_ADDON_FUNC_DUMMY;
129
130 //============================================================================
138 typedef enum ADDON_STATUS
139 {
142
145
148
151
154
157
158 /* internal used return error if function becomes not used from child on
159 * addon */
160 ADDON_STATUS_NOT_IMPLEMENTED
161 } ADDON_STATUS;
163 //----------------------------------------------------------------------------
164
165 //============================================================================
201 //----------------------------------------------------------------------------
202
203 typedef enum ADDON_STATUS(ATTR_APIENTRYP PFN_KODI_ADDON_INSTANCE_SETTING_CHANGE_STRING_V1)(
204 const KODI_ADDON_INSTANCE_HDL hdl, const char* name, const char* value);
205 typedef enum ADDON_STATUS(ATTR_APIENTRYP PFN_KODI_ADDON_INSTANCE_SETTING_CHANGE_BOOLEAN_V1)(
206 const KODI_ADDON_INSTANCE_HDL hdl, const char* name, bool value);
207 typedef enum ADDON_STATUS(ATTR_APIENTRYP PFN_KODI_ADDON_INSTANCE_SETTING_CHANGE_INTEGER_V1)(
208 const KODI_ADDON_INSTANCE_HDL hdl, const char* name, int value);
209 typedef enum ADDON_STATUS(ATTR_APIENTRYP PFN_KODI_ADDON_INSTANCE_SETTING_CHANGE_FLOAT_V1)(
210 const KODI_ADDON_INSTANCE_HDL hdl, const char* name, float value);
211
213 {
214 PFN_KODI_ADDON_INSTANCE_SETTING_CHANGE_STRING_V1 instance_setting_change_string;
215 PFN_KODI_ADDON_INSTANCE_SETTING_CHANGE_BOOLEAN_V1 instance_setting_change_boolean;
216 PFN_KODI_ADDON_INSTANCE_SETTING_CHANGE_INTEGER_V1 instance_setting_change_integer;
217 PFN_KODI_ADDON_INSTANCE_SETTING_CHANGE_FLOAT_V1 instance_setting_change_float;
219
221 {
222 char* (*get_instance_user_path)(const KODI_ADDON_INSTANCE_BACKEND_HDL hdl);
223 bool (*is_instance_setting_using_default)(const KODI_ADDON_INSTANCE_BACKEND_HDL hdl,
224 const char* id);
225
226 bool (*get_instance_setting_bool)(const KODI_ADDON_INSTANCE_BACKEND_HDL hdl,
227 const char* id,
228 bool* value);
229 bool (*get_instance_setting_int)(const KODI_ADDON_INSTANCE_BACKEND_HDL hdl,
230 const char* id,
231 int* value);
232 bool (*get_instance_setting_float)(const KODI_ADDON_INSTANCE_BACKEND_HDL hdl,
233 const char* id,
234 float* value);
235 bool (*get_instance_setting_string)(const KODI_ADDON_INSTANCE_BACKEND_HDL hdl,
236 const char* id,
237 char** value);
238
239 bool (*set_instance_setting_bool)(const KODI_ADDON_INSTANCE_BACKEND_HDL hdl,
240 const char* id,
241 bool value);
242 bool (*set_instance_setting_int)(const KODI_ADDON_INSTANCE_BACKEND_HDL hdl,
243 const char* id,
244 int value);
245 bool (*set_instance_setting_float)(const KODI_ADDON_INSTANCE_BACKEND_HDL hdl,
246 const char* id,
247 float value);
248 bool (*set_instance_setting_string)(const KODI_ADDON_INSTANCE_BACKEND_HDL hdl,
249 const char* id,
250 const char* value);
252
253 typedef int KODI_ADDON_INSTANCE_TYPE;
254
256 {
257 KODI_ADDON_INSTANCE_TYPE type;
258 uint32_t number;
259 const char* id;
260 const char* version;
261 KODI_ADDON_INSTANCE_BACKEND_HDL kodi;
262 KODI_ADDON_INSTANCE_HDL parent;
263 bool first_instance;
264
265 struct KODI_ADDON_INSTANCE_FUNC_CB* functions;
267
269 {
270 const KODI_ADDON_INSTANCE_INFO* info;
271
272 KODI_ADDON_INSTANCE_HDL hdl;
273 struct KODI_ADDON_INSTANCE_FUNC* functions;
274 union
275 {
276 KODI_ADDON_FUNC_DUMMY dummy;
277 struct AddonInstance_AudioDecoder* audiodecoder;
278 struct AddonInstance_AudioEncoder* audioencoder;
279 struct AddonInstance_ImageDecoder* imagedecoder;
280 struct AddonInstance_Game* game;
281 struct AddonInstance_InputStream* inputstream;
282 struct AddonInstance_Peripheral* peripheral;
283 struct AddonInstance_PVR* pvr;
284 struct AddonInstance_Screensaver* screensaver;
285 struct AddonInstance_ShaderPreset* shaderpreset;
286 struct AddonInstance_VFSEntry* vfs;
287 struct AddonInstance_VideoCodec* videocodec;
288 struct AddonInstance_Visualization* visualization;
289 };
291
293 typedef void* KODI_HANDLE;
294
296 {
297 char* (*get_addon_path)(const KODI_ADDON_BACKEND_HDL hdl);
298 char* (*get_lib_path)(const KODI_ADDON_BACKEND_HDL hdl);
299 char* (*get_user_path)(const KODI_ADDON_BACKEND_HDL hdl);
300 char* (*get_temp_path)(const KODI_ADDON_BACKEND_HDL hdl);
301
302 char* (*get_localized_string)(const KODI_ADDON_BACKEND_HDL hdl, long label_id);
303
304 bool (*open_settings_dialog)(const KODI_ADDON_BACKEND_HDL hdl);
305 bool (*is_setting_using_default)(const KODI_ADDON_BACKEND_HDL hdl, const char* id);
306
307 bool (*get_setting_bool)(const KODI_ADDON_BACKEND_HDL hdl, const char* id, bool* value);
308 bool (*get_setting_int)(const KODI_ADDON_BACKEND_HDL hdl, const char* id, int* value);
309 bool (*get_setting_float)(const KODI_ADDON_BACKEND_HDL hdl, const char* id, float* value);
310 bool (*get_setting_string)(const KODI_ADDON_BACKEND_HDL hdl, const char* id, char** value);
311
312 bool (*set_setting_bool)(const KODI_ADDON_BACKEND_HDL hdl, const char* id, bool value);
313 bool (*set_setting_int)(const KODI_ADDON_BACKEND_HDL hdl, const char* id, int value);
314 bool (*set_setting_float)(const KODI_ADDON_BACKEND_HDL hdl, const char* id, float value);
315 bool (*set_setting_string)(const KODI_ADDON_BACKEND_HDL hdl, const char* id, const char* value);
316
317 char* (*get_addon_info)(const KODI_ADDON_BACKEND_HDL hdl, const char* id);
318
319 char* (*get_type_version)(const KODI_ADDON_BACKEND_HDL hdl, int type);
320 void* (*get_interface)(const KODI_ADDON_BACKEND_HDL hdl, const char* name, const char* version);
322
328 {
329 // Pointer inside Kodi, used on callback functions to give related handle
330 // class, for this ADDON::CAddonDll inside Kodi.
331 KODI_ADDON_BACKEND_HDL kodiBase;
332
333 void (*free_string)(const KODI_ADDON_BACKEND_HDL hdl, char* str);
334 void (*free_string_array)(const KODI_ADDON_BACKEND_HDL hdl, char** arr, int numElements);
335 void (*addon_log_msg)(const KODI_ADDON_BACKEND_HDL hdl, const int loglevel, const char* msg);
336
337 struct AddonToKodiFuncTable_kodi* kodi;
338 struct AddonToKodiFuncTable_kodi_addon* kodi_addon;
339 struct AddonToKodiFuncTable_kodi_audioengine* kodi_audioengine;
340 struct AddonToKodiFuncTable_kodi_filesystem* kodi_filesystem;
341 struct AddonToKodiFuncTable_kodi_gui* kodi_gui;
342 struct AddonToKodiFuncTable_kodi_network* kodi_network;
344
345 typedef ADDON_STATUS(ATTR_APIENTRYP PFN_KODI_ADDON_CREATE_V1)(
346 const KODI_ADDON_INSTANCE_BACKEND_HDL first_instance, KODI_ADDON_HDL* hdl);
347 typedef void(ATTR_APIENTRYP PFN_KODI_ADDON_DESTROY_V1)(const KODI_ADDON_HDL hdl);
348 typedef ADDON_STATUS(ATTR_APIENTRYP PFN_KODI_ADDON_CREATE_INSTANCE_V1)(
349 const KODI_ADDON_HDL hdl, struct KODI_ADDON_INSTANCE_STRUCT* instance);
350 typedef void(ATTR_APIENTRYP PFN_KODI_ADDON_DESTROY_INSTANCE_V1)(
351 const KODI_ADDON_HDL hdl, struct KODI_ADDON_INSTANCE_STRUCT* instance);
352 typedef enum ADDON_STATUS(ATTR_APIENTRYP PFN_KODI_ADDON_SETTING_CHANGE_STRING_V1)(
353 const KODI_ADDON_HDL hdl, const char* name, const char* value);
354 typedef enum ADDON_STATUS(ATTR_APIENTRYP PFN_KODI_ADDON_SETTING_CHANGE_BOOLEAN_V1)(
355 const KODI_ADDON_HDL hdl, const char* name, bool value);
356 typedef enum ADDON_STATUS(ATTR_APIENTRYP PFN_KODI_ADDON_SETTING_CHANGE_INTEGER_V1)(
357 const KODI_ADDON_HDL hdl, const char* name, int value);
358 typedef enum ADDON_STATUS(ATTR_APIENTRYP PFN_KODI_ADDON_SETTING_CHANGE_FLOAT_V1)(
359 const KODI_ADDON_HDL hdl, const char* name, float value);
360
365 {
366 PFN_KODI_ADDON_CREATE_V1 create;
367 PFN_KODI_ADDON_DESTROY_V1 destroy;
368 PFN_KODI_ADDON_CREATE_INSTANCE_V1 create_instance;
369 PFN_KODI_ADDON_DESTROY_INSTANCE_V1 destroy_instance;
370 PFN_KODI_ADDON_SETTING_CHANGE_STRING_V1 setting_change_string;
371 PFN_KODI_ADDON_SETTING_CHANGE_BOOLEAN_V1 setting_change_boolean;
372 PFN_KODI_ADDON_SETTING_CHANGE_INTEGER_V1 setting_change_integer;
373 PFN_KODI_ADDON_SETTING_CHANGE_FLOAT_V1 setting_change_float;
375
380 typedef struct AddonGlobalInterface
381 {
382 // Pointer of first created instance, used in case this add-on goes with single way
383 // Set from Kodi!
384 struct KODI_ADDON_INSTANCE_STRUCT* firstKodiInstance;
385
386 // Pointer to master base class inside add-on
387 // Set from addon header (kodi::addon::CAddonBase)!
388 KODI_ADDON_HDL addonBase;
389
390 // Pointer to a instance used on single way (together with this class)
391 // Set from addon header (kodi::addon::IAddonInstance)!
392 KODI_ADDON_INSTANCE_HDL globalSingleInstance;
393
394 // Callback function tables from addon to Kodi
395 // Set from Kodi!
397
398 // Function tables from Kodi to addon
399 // Set from addon header!
402
403#ifdef __cplusplus
404}
405#endif /* __cplusplus */
406
407#endif /* !C_API_ADDON_BASE_H */
ADDON_LOG
Definition addon_base.h:183
@ ADDON_LOG_FATAL
4 : To notify fatal unrecoverable errors, which can may also indicate upcoming crashes.
Definition addon_base.h:198
@ ADDON_LOG_WARNING
2 : To write warnings in the log file.
Definition addon_base.h:191
@ ADDON_LOG_INFO
1 : To include information messages in the log file.
Definition addon_base.h:188
@ ADDON_LOG_DEBUG
0 : To include debug information in the log file.
Definition addon_base.h:185
@ ADDON_LOG_ERROR
3 : To report error messages in the log file.
Definition addon_base.h:194
ADDON_STATUS
Definition addon_base.h:139
@ ADDON_STATUS_NEED_SETTINGS
Necessary settings are not yet set.
Definition addon_base.h:150
@ ADDON_STATUS_LOST_CONNECTION
A needed connection was lost.
Definition addon_base.h:144
@ ADDON_STATUS_OK
For everything OK and no error.
Definition addon_base.h:141
@ ADDON_STATUS_NEED_RESTART
Addon needs a restart inside Kodi.
Definition addon_base.h:147
@ ADDON_STATUS_UNKNOWN
Unknown and incomprehensible error.
Definition addon_base.h:153
@ ADDON_STATUS_PERMANENT_FAILURE
Permanent failure, like failing to resolve methods.
Definition addon_base.h:156
Main structure passed from kodi to addon with basic information needed to create add-on.
Definition addon_base.h:381
Definition audiodecoder.h:142
Definition audioencoder.h:65
Game instance.
Definition game.h:1306
Definition imagedecoder.h:441
Definition inputstream.h:735
Definition pvr.h:362
Definition peripheral.h:731
Definition screensaver.h:51
ShaderPreset instance.
Definition shaderpreset.h:298
Definition vfs.h:137
Definition video_codec.h:268
Definition visualization.h:130
Callback function tables from addon to Kodi Set complete from Kodi!
Definition addon_base.h:328
Definition addon_base.h:296
Definition audio_engine.h:267
Definition filesystem.h:256
Definition definitions.h:26
Definition network.h:31
Definition general.h:88
Definition addon_base.h:221
Definition addon_base.h:213
Definition addon_base.h:256
Definition addon_base.h:269
Function tables from Kodi to addon.
Definition addon_base.h:365