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)
98typedef intptr_t ssize_t;
99#define _SSIZE_T_DEFINED
100#endif // !_SSIZE_T_DEFINED
101#ifndef SSIZE_MAX
102#define SSIZE_MAX INTPTR_MAX
103#endif // !SSIZE_MAX
104#else // Linux, Mac, FreeBSD
105#include <sys/types.h>
106#endif // TARGET_POSIX
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
115extern "C"
116{
117#endif /* __cplusplus */
118
119 typedef void* KODI_ADDON_HDL;
120 typedef void* KODI_ADDON_BACKEND_HDL;
121 typedef void* KODI_ADDON_INSTANCE_HDL;
122 typedef void* KODI_ADDON_INSTANCE_BACKEND_HDL;
123
124 // Hardware specific device context interface
125 typedef void* ADDON_HARDWARE_CONTEXT;
126
127 typedef void* KODI_ADDON_FUNC_DUMMY;
128
129 //============================================================================
137 typedef enum ADDON_STATUS
138 {
141
144
147
150
153
156
157 /* internal used return error if function becomes not used from child on
158 * addon */
159 ADDON_STATUS_NOT_IMPLEMENTED
160 } ADDON_STATUS;
162 //----------------------------------------------------------------------------
163
164 //============================================================================
200 //----------------------------------------------------------------------------
201
202 typedef enum ADDON_STATUS(ATTR_APIENTRYP PFN_KODI_ADDON_INSTANCE_SETTING_CHANGE_STRING_V1)(
203 const KODI_ADDON_INSTANCE_HDL hdl, const char* name, const char* value);
204 typedef enum ADDON_STATUS(ATTR_APIENTRYP PFN_KODI_ADDON_INSTANCE_SETTING_CHANGE_BOOLEAN_V1)(
205 const KODI_ADDON_INSTANCE_HDL hdl, const char* name, bool value);
206 typedef enum ADDON_STATUS(ATTR_APIENTRYP PFN_KODI_ADDON_INSTANCE_SETTING_CHANGE_INTEGER_V1)(
207 const KODI_ADDON_INSTANCE_HDL hdl, const char* name, int value);
208 typedef enum ADDON_STATUS(ATTR_APIENTRYP PFN_KODI_ADDON_INSTANCE_SETTING_CHANGE_FLOAT_V1)(
209 const KODI_ADDON_INSTANCE_HDL hdl, const char* name, float value);
210
212 {
213 PFN_KODI_ADDON_INSTANCE_SETTING_CHANGE_STRING_V1 instance_setting_change_string;
214 PFN_KODI_ADDON_INSTANCE_SETTING_CHANGE_BOOLEAN_V1 instance_setting_change_boolean;
215 PFN_KODI_ADDON_INSTANCE_SETTING_CHANGE_INTEGER_V1 instance_setting_change_integer;
216 PFN_KODI_ADDON_INSTANCE_SETTING_CHANGE_FLOAT_V1 instance_setting_change_float;
218
220 {
221 char* (*get_instance_user_path)(const KODI_ADDON_INSTANCE_BACKEND_HDL hdl);
222 bool (*is_instance_setting_using_default)(const KODI_ADDON_INSTANCE_BACKEND_HDL hdl,
223 const char* id);
224
225 bool (*get_instance_setting_bool)(const KODI_ADDON_INSTANCE_BACKEND_HDL hdl,
226 const char* id,
227 bool* value);
228 bool (*get_instance_setting_int)(const KODI_ADDON_INSTANCE_BACKEND_HDL hdl,
229 const char* id,
230 int* value);
231 bool (*get_instance_setting_float)(const KODI_ADDON_INSTANCE_BACKEND_HDL hdl,
232 const char* id,
233 float* value);
234 bool (*get_instance_setting_string)(const KODI_ADDON_INSTANCE_BACKEND_HDL hdl,
235 const char* id,
236 char** value);
237
238 bool (*set_instance_setting_bool)(const KODI_ADDON_INSTANCE_BACKEND_HDL hdl,
239 const char* id,
240 bool value);
241 bool (*set_instance_setting_int)(const KODI_ADDON_INSTANCE_BACKEND_HDL hdl,
242 const char* id,
243 int value);
244 bool (*set_instance_setting_float)(const KODI_ADDON_INSTANCE_BACKEND_HDL hdl,
245 const char* id,
246 float value);
247 bool (*set_instance_setting_string)(const KODI_ADDON_INSTANCE_BACKEND_HDL hdl,
248 const char* id,
249 const char* value);
251
252 typedef int KODI_ADDON_INSTANCE_TYPE;
253
255 {
256 KODI_ADDON_INSTANCE_TYPE type;
257 uint32_t number;
258 const char* id;
259 const char* version;
260 KODI_ADDON_INSTANCE_BACKEND_HDL kodi;
261 KODI_ADDON_INSTANCE_HDL parent;
262 bool first_instance;
263
264 struct KODI_ADDON_INSTANCE_FUNC_CB* functions;
266
268 {
269 const KODI_ADDON_INSTANCE_INFO* info;
270
271 KODI_ADDON_INSTANCE_HDL hdl;
272 struct KODI_ADDON_INSTANCE_FUNC* functions;
273 union
274 {
275 KODI_ADDON_FUNC_DUMMY dummy;
276 struct AddonInstance_AudioDecoder* audiodecoder;
277 struct AddonInstance_AudioEncoder* audioencoder;
278 struct AddonInstance_ImageDecoder* imagedecoder;
279 struct AddonInstance_Game* game;
280 struct AddonInstance_InputStream* inputstream;
281 struct AddonInstance_Peripheral* peripheral;
282 struct AddonInstance_PVR* pvr;
283 struct AddonInstance_Screensaver* screensaver;
284 struct AddonInstance_VFSEntry* vfs;
285 struct AddonInstance_VideoCodec* videocodec;
286 struct AddonInstance_Visualization* visualization;
287 };
289
291 typedef void* KODI_HANDLE;
292
294 {
295 char* (*get_addon_path)(const KODI_ADDON_BACKEND_HDL hdl);
296 char* (*get_lib_path)(const KODI_ADDON_BACKEND_HDL hdl);
297 char* (*get_user_path)(const KODI_ADDON_BACKEND_HDL hdl);
298 char* (*get_temp_path)(const KODI_ADDON_BACKEND_HDL hdl);
299
300 char* (*get_localized_string)(const KODI_ADDON_BACKEND_HDL hdl, long label_id);
301
302 bool (*open_settings_dialog)(const KODI_ADDON_BACKEND_HDL hdl);
303 bool (*is_setting_using_default)(const KODI_ADDON_BACKEND_HDL hdl, const char* id);
304
305 bool (*get_setting_bool)(const KODI_ADDON_BACKEND_HDL hdl, const char* id, bool* value);
306 bool (*get_setting_int)(const KODI_ADDON_BACKEND_HDL hdl, const char* id, int* value);
307 bool (*get_setting_float)(const KODI_ADDON_BACKEND_HDL hdl, const char* id, float* value);
308 bool (*get_setting_string)(const KODI_ADDON_BACKEND_HDL hdl, const char* id, char** value);
309
310 bool (*set_setting_bool)(const KODI_ADDON_BACKEND_HDL hdl, const char* id, bool value);
311 bool (*set_setting_int)(const KODI_ADDON_BACKEND_HDL hdl, const char* id, int value);
312 bool (*set_setting_float)(const KODI_ADDON_BACKEND_HDL hdl, const char* id, float value);
313 bool (*set_setting_string)(const KODI_ADDON_BACKEND_HDL hdl, const char* id, const char* value);
314
315 char* (*get_addon_info)(const KODI_ADDON_BACKEND_HDL hdl, const char* id);
316
317 char* (*get_type_version)(const KODI_ADDON_BACKEND_HDL hdl, int type);
318 void* (*get_interface)(const KODI_ADDON_BACKEND_HDL hdl, const char* name, const char* version);
320
326 {
327 // Pointer inside Kodi, used on callback functions to give related handle
328 // class, for this ADDON::CAddonDll inside Kodi.
329 KODI_ADDON_BACKEND_HDL kodiBase;
330
331 void (*free_string)(const KODI_ADDON_BACKEND_HDL hdl, char* str);
332 void (*free_string_array)(const KODI_ADDON_BACKEND_HDL hdl, char** arr, int numElements);
333 void (*addon_log_msg)(const KODI_ADDON_BACKEND_HDL hdl, const int loglevel, const char* msg);
334
335 struct AddonToKodiFuncTable_kodi* kodi;
336 struct AddonToKodiFuncTable_kodi_addon* kodi_addon;
337 struct AddonToKodiFuncTable_kodi_audioengine* kodi_audioengine;
338 struct AddonToKodiFuncTable_kodi_filesystem* kodi_filesystem;
339 struct AddonToKodiFuncTable_kodi_gui* kodi_gui;
340 struct AddonToKodiFuncTable_kodi_network* kodi_network;
342
343 typedef ADDON_STATUS(ATTR_APIENTRYP PFN_KODI_ADDON_CREATE_V1)(
344 const KODI_ADDON_INSTANCE_BACKEND_HDL first_instance, KODI_ADDON_HDL* hdl);
345 typedef void(ATTR_APIENTRYP PFN_KODI_ADDON_DESTROY_V1)(const KODI_ADDON_HDL hdl);
346 typedef ADDON_STATUS(ATTR_APIENTRYP PFN_KODI_ADDON_CREATE_INSTANCE_V1)(
347 const KODI_ADDON_HDL hdl, struct KODI_ADDON_INSTANCE_STRUCT* instance);
348 typedef void(ATTR_APIENTRYP PFN_KODI_ADDON_DESTROY_INSTANCE_V1)(
349 const KODI_ADDON_HDL hdl, struct KODI_ADDON_INSTANCE_STRUCT* instance);
350 typedef enum ADDON_STATUS(ATTR_APIENTRYP PFN_KODI_ADDON_SETTING_CHANGE_STRING_V1)(
351 const KODI_ADDON_HDL hdl, const char* name, const char* value);
352 typedef enum ADDON_STATUS(ATTR_APIENTRYP PFN_KODI_ADDON_SETTING_CHANGE_BOOLEAN_V1)(
353 const KODI_ADDON_HDL hdl, const char* name, bool value);
354 typedef enum ADDON_STATUS(ATTR_APIENTRYP PFN_KODI_ADDON_SETTING_CHANGE_INTEGER_V1)(
355 const KODI_ADDON_HDL hdl, const char* name, int value);
356 typedef enum ADDON_STATUS(ATTR_APIENTRYP PFN_KODI_ADDON_SETTING_CHANGE_FLOAT_V1)(
357 const KODI_ADDON_HDL hdl, const char* name, float value);
358
363 {
364 PFN_KODI_ADDON_CREATE_V1 create;
365 PFN_KODI_ADDON_DESTROY_V1 destroy;
366 PFN_KODI_ADDON_CREATE_INSTANCE_V1 create_instance;
367 PFN_KODI_ADDON_DESTROY_INSTANCE_V1 destroy_instance;
368 PFN_KODI_ADDON_SETTING_CHANGE_STRING_V1 setting_change_string;
369 PFN_KODI_ADDON_SETTING_CHANGE_BOOLEAN_V1 setting_change_boolean;
370 PFN_KODI_ADDON_SETTING_CHANGE_INTEGER_V1 setting_change_integer;
371 PFN_KODI_ADDON_SETTING_CHANGE_FLOAT_V1 setting_change_float;
373
378 typedef struct AddonGlobalInterface
379 {
380 // Pointer of first created instance, used in case this add-on goes with single way
381 // Set from Kodi!
382 struct KODI_ADDON_INSTANCE_STRUCT* firstKodiInstance;
383
384 // Pointer to master base class inside add-on
385 // Set from addon header (kodi::addon::CAddonBase)!
386 KODI_ADDON_HDL addonBase;
387
388 // Pointer to a instance used on single way (together with this class)
389 // Set from addon header (kodi::addon::IAddonInstance)!
390 KODI_ADDON_INSTANCE_HDL globalSingleInstance;
391
392 // Callback function tables from addon to Kodi
393 // Set from Kodi!
395
396 // Function tables from Kodi to addon
397 // Set from addon header!
400
401#ifdef __cplusplus
402}
403#endif /* __cplusplus */
404
405#endif /* !C_API_ADDON_BASE_H */
ADDON_LOG
Definition addon_base.h:182
@ ADDON_LOG_FATAL
4 : To notify fatal unrecoverable errors, which can may also indicate upcoming crashes.
Definition addon_base.h:197
@ ADDON_LOG_WARNING
2 : To write warnings in the log file.
Definition addon_base.h:190
@ ADDON_LOG_INFO
1 : To include information messages in the log file.
Definition addon_base.h:187
@ ADDON_LOG_DEBUG
0 : To include debug information in the log file.
Definition addon_base.h:184
@ ADDON_LOG_ERROR
3 : To report error messages in the log file.
Definition addon_base.h:193
ADDON_STATUS
Definition addon_base.h:138
@ ADDON_STATUS_NEED_SETTINGS
Necessary settings are not yet set.
Definition addon_base.h:149
@ ADDON_STATUS_LOST_CONNECTION
A needed connection was lost.
Definition addon_base.h:143
@ ADDON_STATUS_OK
For everything OK and no error.
Definition addon_base.h:140
@ ADDON_STATUS_NEED_RESTART
Addon needs a restart inside Kodi.
Definition addon_base.h:146
@ ADDON_STATUS_UNKNOWN
Unknown and incomprehensible error.
Definition addon_base.h:152
@ ADDON_STATUS_PERMANENT_FAILURE
Permanent failure, like failing to resolve methods.
Definition addon_base.h:155
Main structure passed from kodi to addon with basic information needed to create add-on.
Definition addon_base.h:379
Definition audiodecoder.h:142
Definition audioencoder.h:65
Game instance.
Definition game.h:1279
Definition imagedecoder.h:441
Definition inputstream.h:698
Definition pvr.h:362
Definition peripheral.h:731
Definition screensaver.h:51
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:326
Definition addon_base.h:294
Definition audio_engine.h:267
Definition filesystem.h:255
Definition definitions.h:26
Definition network.h:31
Definition general.h:88
Definition addon_base.h:220
Definition addon_base.h:212
Definition addon_base.h:255
Definition addon_base.h:268
Function tables from Kodi to addon.
Definition addon_base.h:363