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 DALI_ADDONS_PATH
24 #define DALI_ADDONS_PATH ""
32 std::vector<std::string> AddOnManager::EnumerateAddOns()
34 std::string listFileName(DALI_ADDONS_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];
42 memset( lineBuf, 0, 256 );
44 while( getline( &lineBuf, &n, fin ) > 0 )
49 if( *c == '\n' || *c == '\r' )
56 tet_printf("Adding %s\n", lineBuf);
57 addons.emplace_back( lineBuf );
58 memset( lineBuf, 0, 256 );
62 std::vector<std::string> retval{};
64 for( auto& name : addons )
66 std::string path(DALI_ADDONS_PATH);
70 mAddOnCache.emplace_back();
71 mAddOnCache.back().handle = dlopen( path.c_str(), RTLD_DEEPBIND|RTLD_LAZY );
72 if( !mAddOnCache.back().handle )
74 mAddOnCache.back().valid = false;
75 tet_printf( "Can't open addon lib: %s, error: '%s'\n", path.c_str(), dlerror());
78 // Here addon must self register
79 if( !mAddOnCache.back().valid )
81 puts("Addon invalid!");
85 tet_printf( "Valid AddOn: %s\n", mAddOnCache.back().name.c_str() );
86 retval.emplace_back( mAddOnCache.back().name );
93 * Check for self-registering addons
97 void AddOnManager::RegisterAddOnDispatchTable( const AddOnDispatchTable* dispatchTable )
99 // Register the dispatch table
100 auto& entry = mAddOnCache.back();
101 entry.name = dispatchTable->name;
102 tet_printf( "Registering AddOn: %s\n", entry.name.c_str());
103 entry.GetGlobalProc = dispatchTable->GetGlobalProc;
104 entry.GetInstanceProc = dispatchTable->GetInstanceProc;
105 entry.GetAddOnInfo = dispatchTable->GetAddOnInfo;
106 entry.OnStart = dispatchTable->OnStart;
107 entry.OnStop = dispatchTable->OnStop;
108 entry.OnPause = dispatchTable->OnPause;
109 entry.OnResume = dispatchTable->OnResume;
113 bool AddOnManager::GetAddOnInfo(const std::string& name, AddOnInfo& info )
116 std::find_if( mAddOnCache.begin(), mAddOnCache.end(),
117 [&retval, name, &info]( AddOnCacheEntry& entry )
119 if(entry.name == name)
121 entry.GetAddOnInfo( info );
130 std::vector<AddOnLibrary> AddOnManager::LoadAddOns( const std::vector<std::string>& addonNames )
132 if(mAddOnCache.empty())
137 std::vector<AddOnLibrary> retval{};
138 for( auto& name : addonNames)
141 auto iter = std::find_if( mAddOnCache.begin(), mAddOnCache.end(),
142 [&retval, name, &index]( AddOnCacheEntry& entry )
145 if(entry.name == name)
151 if( iter != mAddOnCache.end() )
153 retval.emplace_back( *reinterpret_cast<void**>( &index ) );
157 retval.emplace_back( nullptr );
164 void* AddOnManager::GetGlobalProc( const Dali::AddOnLibrary& addOnLibrary, const char* procName )
166 auto index = *reinterpret_cast<const size_t*>( &addOnLibrary );
167 return mAddOnCache[index-1].GetGlobalProc( procName );
170 void* AddOnManager::GetInstanceProc( const Dali::AddOnLibrary& addOnLibrary, const char* procName )
172 auto index = *reinterpret_cast<const size_t*>( &addOnLibrary );
173 return mAddOnCache[index-1].GetInstanceProc( procName );
176 void AddOnManager::Start()
178 for( auto& entry : mAddOnCache )
187 void AddOnManager::Resume()
189 for( auto& entry : mAddOnCache )
198 void AddOnManager::Stop()
200 for( auto& entry : mAddOnCache )
209 void AddOnManager::Pause()
211 for( auto& entry : mAddOnCache )