*/
DALI_ADAPTOR_API const char * GetEnvironmentVariable( const char * variable );
+/**
+ * @brief Create or overwrite (when it does not exist) an environment variable.
+ *
+ * @param[in] variable Null-terminated character string identifying the name of the environmental variable.
+ * @param[in] value Null-terminated character string to set as a value.
+ * @return True on success, false on error.
+ */
+DALI_ADAPTOR_API bool SetEnvironmentVariable( const char * variable, const char * value );
+
} // namespace EnvironmentVariable
} // namespace Dali
// EXTERNAL INCLUDES
#include <dlfcn.h>
#include <dali/integration-api/debug.h>
-#include <dali/public-api/adaptor-framework/native-image-source.h>
#include <dali/public-api/object/type-registry.h>
+#include <sstream>
+
+// INTERNAL INCLUDES
+#include <dali/devel-api/adaptor-framework/environment-variable.h>
+#include <dali/internal/system/common/environment-variables.h>
+#include <dali/public-api/adaptor-framework/native-image-source.h>
namespace Dali
{
namespace // unnamed namespace
{
-const char* WEB_ENGINE_PLUGIN_SO( "libdali-web-engine-plugin.so" );
+constexpr char const * const kPluginFullNamePrefix = "libdali-web-engine-";
+constexpr char const * const kPluginFullNamePostfix = "-plugin.so";
+constexpr char const * const kPluginFullNameDefault = "libdali-web-engine-plugin.so";
+
+// Note: Dali WebView policy does not allow to use multiple web engines in an application.
+// So once pluginName is set to non-empty string, it will not change.
+std::string pluginName;
+
+std::string MakePluginName( const char* environmentName )
+{
+ std::stringstream fullName;
+ fullName << kPluginFullNamePrefix << environmentName << kPluginFullNamePostfix;
+ return std::move( fullName.str() );
+}
Dali::BaseHandle Create()
{
}
}
+bool WebEngine::InitializePluginHandle()
+{
+ if ( pluginName.length() == 0 )
+ {
+ // pluginName is not initialized yet.
+ const char* name = EnvironmentVariable::GetEnvironmentVariable( DALI_ENV_WEB_ENGINE_NAME );
+ if ( name )
+ {
+ pluginName = MakePluginName( name );
+ mHandle = dlopen( pluginName.c_str(), RTLD_LAZY );
+ if ( mHandle )
+ {
+ return true;
+ }
+ }
+ pluginName = std::string( kPluginFullNameDefault );
+ }
+
+ mHandle = dlopen( pluginName.c_str(), RTLD_LAZY );
+ if ( !mHandle )
+ {
+ DALI_LOG_ERROR( "Can't load %s : %s\n", pluginName.c_str(), dlerror() );
+ return false;
+ }
+
+ return true;
+}
+
bool WebEngine::Initialize()
{
char* error = NULL;
- mHandle = dlopen( WEB_ENGINE_PLUGIN_SO, RTLD_LAZY );
-
- error = dlerror();
- if( mHandle == NULL || error != NULL )
+ if ( !InitializePluginHandle() )
{
- DALI_LOG_ERROR( "WebEngine::Initialize(), dlopen error: %s\n", error );
return false;
}
*/
bool Initialize();
+ /**
+ * @brief Initializes library handle by loading web engine plugin.
+ *
+ * @return Whether the initialization succeed or not.
+ */
+ bool InitializePluginHandle();
+
private:
- Dali::WebEnginePlugin* mPlugin; ///< WebEngine plugin handle
+ Dali::WebEnginePlugin* mPlugin; ///< WebEnginePlugin instance
void* mHandle; ///< Handle for the loaded library
typedef Dali::WebEnginePlugin* (*CreateWebEngineFunction)();