2 * Copyright (c) 2014 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 "script-plugin-proxy.h"
22 #include <dali/integration-api/debug.h>
36 ScriptPluginProxy::ScriptPluginProxy( const std::string& sharedObjectName)
38 mCreatePluginFunctionPtr(NULL),
39 mDestroyPluginFunctionPtr(NULL),
40 mScriptingPlugin(NULL),
41 mSharedObjectName(sharedObjectName),
47 ScriptPluginProxy::~ScriptPluginProxy()
52 void ScriptPluginProxy::SetFlags(const std::string& flags)
56 mScriptingPlugin->SetFlags( flags );
60 void ScriptPluginProxy::ExecuteBuffer(const std::string &buffer, const std::string &filename)
64 mScriptingPlugin->ExecuteBuffer( buffer, filename );
68 void ScriptPluginProxy::ExecuteFile(const std::string &filename)
72 mScriptingPlugin->ExecuteFile( filename );
76 bool ScriptPluginProxy::IsInitialized() const
78 return mIsInitialized;
82 void ScriptPluginProxy::Initialize()
89 // dl library maintains link counts if you call this twice on the same library
90 // (so its okay to do but we should close every handle we get too)
91 mLibHandle = dlopen( mSharedObjectName.c_str(), RTLD_NOW | RTLD_GLOBAL );
94 DALI_LOG_ERROR( "Cannot load dali script plugin. %s\n", dlerror() );
102 mCreatePluginFunctionPtr = reinterpret_cast<ScriptPlugin::Create*>( dlsym( mLibHandle, "CreateScriptPlugin" ) );
103 if( !mCreatePluginFunctionPtr )
105 DALI_LOG_ERROR( "Cannot load symbol CreateScriptPlugin(). %s\n", dlerror() );
112 mDestroyPluginFunctionPtr = reinterpret_cast<ScriptPlugin::Destroy*>( dlsym( mLibHandle, "DestroyScriptPlugin" ) );
113 if( !mDestroyPluginFunctionPtr )
115 DALI_LOG_ERROR( "Cannot load symbol:DestroyScriptPlugin(). %s\n", dlerror() );
122 mScriptingPlugin = mCreatePluginFunctionPtr();
124 if( !mScriptingPlugin )
126 DALI_LOG_ERROR( "Call to function CreateFeedbackPlugin() failed\n" );
130 mIsInitialized = true;
133 void ScriptPluginProxy::UnInitialize()
135 if( mScriptingPlugin )
137 mDestroyPluginFunctionPtr( mScriptingPlugin );
142 if( dlclose( mLibHandle ) )
144 DALI_LOG_ERROR( "Error closing dali plugin library: %s\n", dlerror() );
147 mIsInitialized = false;
149 } // namespace Adaptor
151 } // namespace Internal