2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "test-addon-manager.h"
19 #include <dali-test-suite-utils.h>
23 #ifndef ADDON_LIBS_PATH
24 #define ADDON_LIBS_PATH ""
32 std::vector<std::string> AddOnManager::EnumerateAddOns()
34 std::string listFileName(ADDON_LIBS_PATH);
35 listFileName += "/addons.txt";
37 // Read list of available test addons
38 tet_printf("Enumerating addons, file: %s\n", listFileName.c_str());
39 std::vector<std::string> addons{};
40 auto* fin = fopen( listFileName.c_str(), "r" );
41 char* lineBuf = new char[256];
43 while( getline( &lineBuf, &n, fin ) > 0 )
45 tet_printf("Adding %s\n", lineBuf);
46 addons.emplace_back( lineBuf );
50 std::vector<std::string> retval{};
52 for( auto& name : addons )
54 std::string path(ADDON_LIBS_PATH);
58 mAddOnCache.emplace_back();
59 mAddOnCache.back().handle = dlopen( path.c_str(), RTLD_DEEPBIND|RTLD_LAZY );
60 if( !mAddOnCache.back().handle )
62 mAddOnCache.back().valid = false;
63 tet_printf( "Can't open addon lib: %s\n", path.c_str());
66 // Here addon must self register
67 if( !mAddOnCache.back().valid )
69 puts("Addon invalid!");
73 tet_printf( "Valid AddOn: %s\n", mAddOnCache.back().name.c_str() );
74 retval.emplace_back( mAddOnCache.back().name );
81 * Check for self-registering addons
85 void AddOnManager::RegisterAddOnDispatchTable( const AddOnDispatchTable* dispatchTable )
87 // Register the dispatch table
88 auto& entry = mAddOnCache.back();
89 entry.name = dispatchTable->name;
90 tet_printf( "Registering AddOn: %s\n", entry.name.c_str());
91 entry.GetGlobalProc = dispatchTable->GetGlobalProc;
92 entry.GetInstanceProc = dispatchTable->GetInstanceProc;
93 entry.GetAddOnInfo = dispatchTable->GetAddOnInfo;
94 entry.OnStart = dispatchTable->OnStart;
95 entry.OnStop = dispatchTable->OnStop;
96 entry.OnPause = dispatchTable->OnPause;
97 entry.OnResume = dispatchTable->OnResume;
101 bool AddOnManager::GetAddOnInfo(const std::string& name, AddOnInfo& info )
104 std::find_if( mAddOnCache.begin(), mAddOnCache.end(),
105 [&retval, name, &info]( AddOnCacheEntry& entry )
107 if(entry.name == name)
109 entry.GetAddOnInfo( info );
118 std::vector<AddOnLibrary> AddOnManager::LoadAddOns( const std::vector<std::string>& addonNames )
120 if(mAddOnCache.empty())
125 std::vector<AddOnLibrary> retval{};
126 for( auto& name : addonNames)
129 auto iter = std::find_if( mAddOnCache.begin(), mAddOnCache.end(),
130 [&retval, name, &index]( AddOnCacheEntry& entry )
133 if(entry.name == name)
139 if( iter != mAddOnCache.end() )
141 retval.emplace_back( *reinterpret_cast<void**>( &index ) );
145 retval.emplace_back( nullptr );
152 void* AddOnManager::GetGlobalProc( const Dali::AddOnLibrary& addOnLibrary, const char* procName )
154 auto index = *reinterpret_cast<const size_t*>( &addOnLibrary );
155 return mAddOnCache[index-1].GetGlobalProc( procName );
158 void* AddOnManager::GetInstanceProc( const Dali::AddOnLibrary& addOnLibrary, const char* procName )
160 auto index = *reinterpret_cast<const size_t*>( &addOnLibrary );
161 return mAddOnCache[index-1].GetInstanceProc( procName );
164 void AddOnManager::Start()
166 for( auto& entry : mAddOnCache )
175 void AddOnManager::Resume()
177 for( auto& entry : mAddOnCache )
186 void AddOnManager::Stop()
188 for( auto& entry : mAddOnCache )
197 void AddOnManager::Pause()
199 for( auto& entry : mAddOnCache )