AddOn manager
[platform/core/uifw/dali-adaptor.git] / dali / internal / addons / linux / addon-manager-impl-linux.h
1 #ifndef DALI_ADDON_MANAGER_IMPL_LINUX
2 #define DALI_ADDON_MANAGER_IMPL_LINUX
3 /*
4  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 // INTERNAL INCLUDES
21 #include <dali/internal/addons/common/addon-manager-impl.h>
22 #include <dali/internal/addons/common/addon-manager.h>
23
24 // EXTERNAL INCLUDES
25 #include <dali/public-api/common/vector-wrapper.h>
26
27 #include <string>
28 #include <memory>
29
30 namespace Dali
31 {
32 namespace Internal
33 {
34
35 /**
36  * Implementation of AddOnManager for Linux based platforms (ie. Tizen, Ubuntu)
37  */
38 class AddOnManagerLinux : public Internal::AddOnManager
39 {
40 public:
41
42   /**
43    * @copydoc Dali::Internal::AddOnManager()
44    */
45   AddOnManagerLinux();
46
47   /**
48    * @copydoc Dali::Internal::~AddOnManager()
49    */
50   ~AddOnManagerLinux() override;
51
52   /**
53    * @copydoc Dali::Internal::AddOnManager::RegisterAddOnDispatchTable()
54    */
55   void RegisterAddOnDispatchTable( const AddOnDispatchTable* dispatchTable ) override;
56
57   /**
58    * @copydoc Dali::Internal::AddOnManager::EnumerateAddOns()
59    */
60   std::vector<std::string> EnumerateAddOns() override;
61
62   /**
63    * @copydoc Dali::Internal::AddOnManager::GetAddOnInfo()
64    */
65   bool GetAddOnInfo(const std::string& name, AddOnInfo& info ) override;
66
67   /**
68    * @copydoc Dali::Internal::AddOnManager::LoadAddOns()
69    */
70   std::vector<Dali::AddOnLibrary> LoadAddOns( const std::vector<std::string>& extensionNames ) override;
71
72   /**
73    * @copydoc Dali::Internal::AddOnManager::GetGlobalProc()
74    */
75   void* GetGlobalProc( const Dali::AddOnLibrary& addonHandle, const char* procName ) override;
76
77   /**
78    * @copydoc Dali::Internal::AddOnManager::GetInstanceProc()
79    */
80   void* GetInstanceProc( const Dali::AddOnLibrary& addonHandle, const char* procName ) override;
81
82   /**
83    * @copydoc Dali::Internal::AddOnManager::Pause()
84    */
85   void Pause() override;
86
87   /**
88    * @copydoc Dali::Internal::AddOnManager::Resume()
89    */
90   void Resume() override;
91
92   /**
93    * @copydoc Dali::Internal::AddOnManager::Start()
94    */
95   void Start() override;
96
97   /**
98    * @copydoc Dali::Internal::AddOnManager::Stop()
99    */
100   void Stop() override;
101
102 private:
103
104   /**
105    * @brief Invokes lifecycle event handling function based on incoming event
106    * @param[in] lifecycleEvent The lifecycle event
107    */
108   void InvokeLifecycleFunction( uint32_t lifecycleEvent );
109
110   /**
111    * @struct Lifecycle callback structure
112    * The instance of the LifecycleCallback handles a single lifecycle
113    * event and is bound to an AddOn lifecycle function. The lifecycle
114    * function is optional and in case it doesn't exist, the event
115    * will be ignored.
116    */
117   struct LifecycleCallback
118   {
119     const static uint32_t EVENT_PAUSE = 0u; ///< pause event
120     const static uint32_t EVENT_RESUME = 1u; ///< resume event
121     const static uint32_t EVENT_START = 2u; ///< start event
122     const static uint32_t EVENT_STOP = 3u; ///< stop event
123
124     /**
125      * @brief Constructor
126      * @param[in] funcName name of the lifecycle function
127      */
128     explicit LifecycleCallback(const char* funcName)
129     {
130       functionName = funcName;
131     }
132
133     std::string functionName; ///< Name of lifecycle function
134     void(*function)() = nullptr; ///< Lifecycle function pointer
135     bool initialized { false }; ///< Flag indicates whether LifecycleCallback is initialized
136   };
137
138   /**
139    * @struct AddOnCacheEntry
140    * @brief Instance of AddOnCacheEntry stores AddOn essential
141    * function pointers and library handle.
142    */
143   struct AddOnCacheEntry
144   {
145     std::string addOnLib{};
146     AddOnInfo info{};
147
148     // library handle
149     void* libHandle {nullptr};
150
151     // main function pointers
152     void(*GetAddOnInfo)(AddOnInfo& ) = nullptr; ///< Returns AddOnInfo structure
153     void*(*GetInstanceProc)( const char* ) = nullptr; ///< Returns pointer of instance function (member funtion)
154     void*(*GetGlobalProc)( const char* ) = nullptr; ///< Returns pointer of global function (non-member function)
155
156     // lifecycle functions
157     std::vector<LifecycleCallback> lifecycleCallbacks =
158                                      {
159                                        LifecycleCallback{ "OnPause" },
160                                        LifecycleCallback{ "OnResume" },
161                                        LifecycleCallback{ "OnStart" },
162                                        LifecycleCallback{ "OnStop" },
163                                      };
164     bool opened{false};
165   };
166
167   std::vector<AddOnCacheEntry> mAddOnCache;
168   std::vector<std::string> mAddOnNames;
169 };
170
171
172 }
173 }
174 #endif //DALI_CMAKE_EXTENSION_MANAGER_IMPL_UBUNTU