2 * Copyright (c) 2019 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.
19 #include <dali/internal/system/common/color-controller-impl.h>
23 #include <dali/integration-api/debug.h>
24 #include <dali/public-api/object/type-registry.h>
25 #include <dali/devel-api/common/singleton-service.h>
36 namespace // unnamed namespace
38 const char* COLOR_CONTROLLER_PLUGIN_SO( "libdali-color-controller-plugin.so" );
41 Dali::ColorController ColorController::Get()
43 Dali::ColorController colorController;
45 Dali::SingletonService service( SingletonService::Get() );
48 // Check whether the singleton is already created
49 Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::ColorController ) );
52 // If so, downcast the handle
53 colorController = Dali::ColorController( dynamic_cast< ColorController* >( handle.GetObjectPtr() ) );
57 colorController = Dali::ColorController( new ColorController( ) );
58 service.Register( typeid( colorController ), colorController );
62 return colorController;
65 ColorController::ColorController()
68 mCreateColorControllerPtr( NULL )
73 ColorController::~ColorController()
80 if( mLibHandle && dlclose( mLibHandle ) )
82 DALI_LOG_ERROR( "Error closing color controller plugin library: %s\n", dlerror() );
87 void ColorController::Initialize()
89 mLibHandle = dlopen( COLOR_CONTROLLER_PLUGIN_SO, RTLD_LAZY );
91 char* error = dlerror();
92 if( mLibHandle == NULL || error != NULL )
94 DALI_LOG_ERROR( "ColorController::Initialize: dlopen error [%s]\n", error );
99 mCreateColorControllerPtr = reinterpret_cast< CreateColorControllerFunction >( dlsym( mLibHandle, "CreateColorControllerPlugin" ) );
102 if( mCreateColorControllerPtr == NULL || error != NULL )
104 DALI_LOG_ERROR( "ColorController::Initialize: Cannot load symbol CreateColorControllerPlugin(): %s\n", error );
108 mPlugin = mCreateColorControllerPtr();
111 DALI_LOG_ERROR("ColorController::Initialize: Plugin creation failed\n");
116 bool ColorController::RetrieveColor( const std::string& colorCode, Vector4& colorValue )
120 return mPlugin->RetrieveColor( colorCode, colorValue );
125 bool ColorController::RetrieveColor( const std::string& colorCode , Vector4& textColor, Vector4& textOutlineColor, Vector4& textShadowColor)
129 return mPlugin->RetrieveColor( colorCode, textColor, textOutlineColor, textShadowColor );
134 } // namespace Adaptor
136 } // namespace Internal