1 #ifndef DALI_INTEGRATION_ADDON_MANAGER_H
2 #define DALI_INTEGRATION_ADDON_MANAGER_H
5 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/object/base-handle.h>
33 // Type of extensions (may be used internally)
41 * @brief Helper function building the version number as 32-bit integer.
42 * The return value should be used to encode AddOnInfo::version field.
44 * @param[in] maj Major version number
45 * @param[in] min Minor version number
46 * @param[in] rev Revision version number
47 * @return returns 32-bit version number
49 constexpr uint32_t DALI_ADDON_VERSION( uint32_t maj, uint32_t min, uint32_t rev )
51 return ((maj&0xff) << 24) | ((min & 0xfff) << 16);
55 * Structure describes AddOn details
59 AddOnType type; /// may be use in order to classify extension
60 void* next; /// holds pointer to additional data-structures
62 std::string name; /// Name of the extension
66 * Structure contains details of build
70 uint32_t libCoreVersion;
71 uint32_t libAdaptorVersion;
72 uint32_t libToolkitVersion;
77 * The structure contains essential function pointers which AddOnManager
78 * requires in order to use AddOns.
80 struct AddOnDispatchTable
83 void (*GetAddOnInfo)( Dali::AddOnInfo&) = nullptr;
84 void*(*GetGlobalProc)(const char*) = nullptr;
85 void*(*GetInstanceProc)(const char*) = nullptr;
87 // Lifecycle callbacks
88 void(*OnStart)() = nullptr;
89 void(*OnResume)() = nullptr;
90 void(*OnPause)() = nullptr;
91 void(*OnStop)() = nullptr;
95 * The AddOnLibrary type represents fully opaque object which hides
96 * the actual handle to the library and other related data.
98 typedef void* AddOnLibrary;
100 namespace Integration
105 * Handles DALi AddOn support. The object of AddOnManager exists as a singleton and
106 * is created by the Adaptor. The AddOnManager is used by:
108 * 1) Application - query the AddOns and obtain AddOn interfaces
109 * 2) DALi - handling lifecycle events
110 * 3) AddOn - self-registering the AddOn dispatch table
112 * It is up to the implementation how the AddOn libraries are enumerated and opened. Any
113 * caching (functions, open libraries) must be handled by the implementation.
115 class DALI_CORE_API AddOnManager
119 * @brief Constructor, initialised by the Adaptor
128 virtual ~AddOnManager();
130 // Functions called by the application
133 * @brief Retrieves list of the available AddOns
134 * @return List of AddOn names
136 virtual std::vector<std::string> EnumerateAddOns() = 0;
139 * @brief Returns AddOnInfo structure for specified AddOn name
140 * @param[in] name Name of AddOn
141 * @param[out]] info Output reference
142 * @return True on success, False if extension info cannot be retrieved
144 virtual bool GetAddOnInfo(const std::string& name, AddOnInfo& info ) = 0;
147 * @brief Loads and initialises specified extensions
148 * @param[in] extensionNames Array of extension names
149 * @return vector of initialised extension handles
151 virtual std::vector<AddOnLibrary> LoadAddOns( const std::vector<std::string>& addonNames ) = 0;
154 * @brief Loads AddOn with specified name
155 * @param[in] addOnName Name of AddOn to be acquired
156 * @return Returns a valid handle or nullptr
158 inline AddOnLibrary GetAddOn( const std::string& addonName )
160 return LoadAddOns( { addonName } )[0];
164 * @brief Returns AddOn global function pointer
165 * @param[in] addOnLibrary valid AddOn library object
166 * @param[in] procName Name of the function to retrieve
167 * @return Pointer to the function or null if function doesn't exist
169 virtual void* GetGlobalProc( const Dali::AddOnLibrary& addOnLibrary, const char* procName ) = 0;
172 * @brief Returns addon instance function pointer
173 * @param[in] addOnLibrary valid AddOn library object
174 * @param[in] procName Name of the function to retrieve
175 * @return Pointer to the function or null if function doesn't exist
177 virtual void* GetInstanceProc( const Dali::AddOnLibrary& addOnLibrary, const char* procName ) = 0;
180 * @brief Returns addon global function of specified type
181 * @param[in] addOnLibrary valid AddOn library object
182 * @param[in] procName Name of the function to retrieve
183 * @return std::function object or null if function doesn't exist
186 DALI_INTERNAL std::function<T> GetGlobalProc( const Dali::AddOnLibrary& addonlibrary, const char* procName )
188 auto ptr = GetGlobalProc( addonlibrary, procName );
191 return std::function<T>( *reinterpret_cast<T**>(&ptr) );
197 * @brief Returns AddOn instance function of specified type
198 * @param[in] addOnLibrary valid AddOn library object
199 * @param[in] procName Name of the function to retrieve
200 * @return std::function object or null if function doesn't exist
203 DALI_INTERNAL std::function<T> GetInstanceProc( const Dali::AddOnLibrary& addOnLibrary, const char* procName )
205 auto ptr = GetInstanceProc( addOnLibrary, procName );
208 return std::function<T>( *reinterpret_cast<T**>(&ptr) );
214 * @brief Invokes global function by name
215 * @param[in] addOnLibrary valid AddOn library object
216 * @param[in] functionName Name of function to be called
217 * @param args[in] Arguments
218 * @return Result of called function
220 template<class R, class... Args>
221 DALI_INTERNAL R InvokeGlobalProc( AddOnLibrary addOnLibrary, const char* functionName, Args&&... args)
223 return std::move(GetGlobalProc<R(Args...)>( addOnLibrary, functionName )( args... ));
226 // Lifecycle events, functions are called by the Adaptor
230 * @brief Lifecycle pause function
232 virtual void Pause() = 0;
235 * @brief Lifecycle resume function
237 virtual void Resume() = 0;
240 * @brief Lifecycle start function
242 virtual void Start() = 0;
245 * @brief Lifecycle stop function
247 virtual void Stop() = 0;
249 // Functions called by the AddOn
253 * @brief Registers the dispatch table with AddOnManager.
255 * The function must be called by the AddOn in order to self-register and add
256 * the dispatch table. The platform-dependent implementation must override it
257 * in order to store the dispatch table. The way the dispatch table is stored
258 * depends on the implementation.
260 * @param[in] dispatchTable Pointer to the valid dispatch table
262 virtual void RegisterAddOnDispatchTable( const AddOnDispatchTable* dispatchTable ) = 0;
265 * @brief Retrieves AddOnManager singleton
266 * @return pointer to the AddOnManager
268 static AddOnManager* Get();
272 static AddOnManager* mSingleton; ///< Singleton storing an instance of AddOnManager
274 } // namespace Integration
277 #endif // DALI_INTEGRATION_ADDON_MANAGER