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 #pragma once
10 
11 #ifndef C_API_ADDON_BASE_H
12 #define C_API_ADDON_BASE_H
13 
14 #include "stdbool.h"
15 #include "stdint.h"
16 
17 #ifndef TARGET_WINDOWS
18 #ifndef __cdecl
19 #define __cdecl
20 #endif
21 #ifndef __declspec
22 #define __declspec(X)
23 #endif
24 #endif
25 
26 #undef ATTRIBUTE_PACKED
27 #undef PRAGMA_PACK_BEGIN
28 #undef PRAGMA_PACK_END
29 
30 #if defined(__GNUC__)
31 #define ATTRIBUTE_PACKED __attribute__((packed))
32 #define PRAGMA_PACK 0
33 #define ATTRIBUTE_HIDDEN __attribute__((visibility("hidden")))
34 #endif
35 
36 #if !defined(ATTRIBUTE_PACKED)
37 #define ATTRIBUTE_PACKED
38 #define PRAGMA_PACK 1
39 #endif
40 
41 #if !defined(ATTRIBUTE_HIDDEN)
42 #define ATTRIBUTE_HIDDEN
43 #endif
44 
45 #ifdef _MSC_VER
46 #define ATTRIBUTE_FORCEINLINE __forceinline
47 #elif defined(__GNUC__)
48 #define ATTRIBUTE_FORCEINLINE inline __attribute__((__always_inline__))
49 #elif defined(__CLANG__)
50 #if __has_attribute(__always_inline__)
51 #define ATTRIBUTE_FORCEINLINE inline __attribute__((__always_inline__))
52 #else
53 #define ATTRIBUTE_FORCEINLINE inline
54 #endif
55 #else
56 #define ATTRIBUTE_FORCEINLINE inline
57 #endif
58 
59 // Hardware specific device context interface
60 #define ADDON_HARDWARE_CONTEXT void*
61 
62 /*
63  * To have a on add-on and kodi itself handled string always on known size!
64  */
65 #define ADDON_STANDARD_STRING_LENGTH 1024
66 #define ADDON_STANDARD_STRING_LENGTH_SMALL 256
67 
68 #ifdef __cplusplus
69 extern "C"
70 {
71 #endif /* __cplusplus */
72 
73  //============================================================================
79  typedef enum ADDON_STATUS
80  {
83 
86 
89 
92 
95 
98 
99  /* internal used return error if function becomes not used from child on
100  * addon */
101  ADDON_STATUS_NOT_IMPLEMENTED
102  } ADDON_STATUS;
104  //----------------------------------------------------------------------------
105 
106  //============================================================================
123  typedef enum AddonLog
124  {
127 
130 
133 
136 
139  ADDON_LOG_FATAL = 4
142  //----------------------------------------------------------------------------
143 
145  typedef void* KODI_HANDLE;
146 
151  {
153  void* dataAddress;
155  };
156  typedef struct ADDON_HANDLE_STRUCT* ADDON_HANDLE;
157 
168  {
169  // Pointer inside Kodi, used on callback functions to give related handle
170  // class, for this ADDON::CAddonDll inside Kodi.
171  KODI_HANDLE kodiBase;
172 
173  // Function addresses used for callbacks from addon to Kodi
174  char* (*get_type_version)(void* kodiBase, int type);
175 
176  void (*free_string)(void* kodiBase, char* str);
177  void (*free_string_array)(void* kodiBase, char** arr, int numElements);
178  char* (*get_addon_path)(void* kodiBase);
179  char* (*get_base_user_path)(void* kodiBase);
180  void (*addon_log_msg)(void* kodiBase, const int loglevel, const char* msg);
181 
182  bool (*get_setting_bool)(void* kodiBase, const char* id, bool* value);
183  bool (*get_setting_int)(void* kodiBase, const char* id, int* value);
184  bool (*get_setting_float)(void* kodiBase, const char* id, float* value);
185  bool (*get_setting_string)(void* kodiBase, const char* id, char** value);
186 
187  bool (*set_setting_bool)(void* kodiBase, const char* id, bool value);
188  bool (*set_setting_int)(void* kodiBase, const char* id, int value);
189  bool (*set_setting_float)(void* kodiBase, const char* id, float value);
190  bool (*set_setting_string)(void* kodiBase, const char* id, const char* value);
191 
192  void* (*get_interface)(void* kodiBase, const char* name, const char* version);
193 
194  struct AddonToKodiFuncTable_kodi* kodi;
195  struct AddonToKodiFuncTable_kodi_audioengine* kodi_audioengine;
196  struct AddonToKodiFuncTable_kodi_filesystem* kodi_filesystem;
197  struct AddonToKodiFuncTable_kodi_gui* kodi_gui;
198  struct AddonToKodiFuncTable_kodi_network* kodi_network;
199 
200  // Move up by min version change about
201  bool (*is_setting_using_default)(void* kodiBase, const char* id);
203 
208  {
209  void (*destroy)();
210  ADDON_STATUS (*get_status)();
211  ADDON_STATUS(*create_instance)
212  (int instanceType,
213  const char* instanceID,
214  KODI_HANDLE instance,
215  const char* version,
216  KODI_HANDLE* addonInstance,
217  KODI_HANDLE parent);
218  void (*destroy_instance)(int instanceType, KODI_HANDLE instance);
219  ADDON_STATUS (*set_setting)(const char* settingName, const void* settingValue);
221 
226  typedef struct AddonGlobalInterface
227  {
228  // String with full path where add-on is installed (without his name on end)
229  // Set from Kodi!
230  const char* libBasePath;
231 
232  // Master API version of Kodi itself (ADDON_GLOBAL_VERSION_MAIN)
233  const char* kodi_base_api_version;
234 
235  // Pointer of first created instance, used in case this add-on goes with single way
236  // Set from Kodi!
237  KODI_HANDLE firstKodiInstance;
238 
239  // Pointer to master base class inside add-on
240  // Set from addon header (kodi::addon::CAddonBase)!
241  KODI_HANDLE addonBase;
242 
243  // Pointer to a instance used on single way (together with this class)
244  // Set from addon header (kodi::addon::IAddonInstance)!
245  KODI_HANDLE globalSingleInstance;
246 
247  // Callback function tables from addon to Kodi
248  // Set from Kodi!
250 
251  // Function tables from Kodi to addon
252  // Set from addon header!
255 
256 #ifdef __cplusplus
257 }
258 #endif /* __cplusplus */
259 
260 #endif /* !C_API_ADDON_BASE_H */
ADDON_LOG_INFO
@ ADDON_LOG_INFO
1 : To include information messages in the log file.
Definition: addon_base.h:129
AddonToKodiFuncTable_kodi_network
Definition: network.h:33
AddonGlobalInterface
Main structure passed from kodi to addon with basic information needed to create add-on.
Definition: addon_base.h:227
ADDON_LOG_DEBUG
@ ADDON_LOG_DEBUG
0 : To include debug information in the log file.
Definition: addon_base.h:126
AddonToKodiFuncTable_Addon
Definition: addon_base.h:168
ADDON_LOG_WARNING
@ ADDON_LOG_WARNING
2 : To write warnings in the log file.
Definition: addon_base.h:132
ADDON_LOG_FATAL
@ ADDON_LOG_FATAL
4 : To notify fatal unrecoverable errors, which can may also indicate upcoming crashes.
Definition: addon_base.h:139
KodiToAddonFuncTable_Addon
Function tables from Kodi to addon.
Definition: addon_base.h:208
ADDON_STATUS_LOST_CONNECTION
@ ADDON_STATUS_LOST_CONNECTION
A needed connection was lost.
Definition: addon_base.h:85
ADDON_STATUS_PERMANENT_FAILURE
@ ADDON_STATUS_PERMANENT_FAILURE
Permanent failure, like failing to resolve methods.
Definition: addon_base.h:97
ADDON_HANDLE_STRUCT
Handle used to return data from the PVR add-on to CPVRClient.
Definition: addon_base.h:151
AddonToKodiFuncTable_kodi_filesystem
Definition: filesystem.h:249
ADDON_HANDLE_STRUCT::dataAddress
void * dataAddress
Definition: addon_base.h:153
ADDON_HANDLE_STRUCT::callerAddress
void * callerAddress
Definition: addon_base.h:152
ADDON_LOG_ERROR
@ ADDON_LOG_ERROR
3 : To report error messages in the log file.
Definition: addon_base.h:135
ADDON_STATUS
ADDON_STATUS
Return value of functions in kodi::addon::CAddonBase and associated classes.
Definition: addon_base.h:80
ADDON_STATUS_NEED_RESTART
@ ADDON_STATUS_NEED_RESTART
Addon needs a restart inside Kodi.
Definition: addon_base.h:88
AddonLog
AddonLog
Definition: addon_base.h:124
AddonToKodiFuncTable_kodi
Definition: general.h:90
ADDON_STATUS_NEED_SETTINGS
@ ADDON_STATUS_NEED_SETTINGS
Necessary settings are not yet set.
Definition: addon_base.h:91
ADDON_STATUS_OK
@ ADDON_STATUS_OK
For everything OK and no error.
Definition: addon_base.h:82
AddonToKodiFuncTable_kodi_audioengine
Definition: audio_engine.h:269
ADDON_HANDLE_STRUCT::dataIdentifier
int dataIdentifier
Definition: addon_base.h:154
AddonToKodiFuncTable_kodi_gui
Definition: definitions.h:54
ADDON_STATUS_UNKNOWN
@ ADDON_STATUS_UNKNOWN
Unknown and incomprehensible error.
Definition: addon_base.h:94