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 bool ScriptPluginProxy::ExecuteBuffer(const std::string &buffer, const std::string &filename)
64 return mScriptingPlugin->ExecuteBuffer( buffer, filename );
69 bool ScriptPluginProxy::ExecuteFile(const std::string &filename)
73 return mScriptingPlugin->ExecuteFile( filename );
78 bool ScriptPluginProxy::IsInitialized() const
80 return mIsInitialized;
83 void ScriptPluginProxy::Initialize()
90 // dl library maintains link counts if you call this twice on the same library
91 // (so its okay to do but we should close every handle we get too)
92 mLibHandle = dlopen( mSharedObjectName.c_str(), RTLD_NOW | RTLD_GLOBAL );
95 DALI_LOG_ERROR( "Cannot load dali script plugin. %s\n", dlerror() );
103 mCreatePluginFunctionPtr = reinterpret_cast<ScriptPlugin::Create*>( dlsym( mLibHandle, "CreateScriptPlugin" ) );
104 if( !mCreatePluginFunctionPtr )
106 DALI_LOG_ERROR( "Cannot load symbol CreateScriptPlugin(). %s\n", dlerror() );
113 mDestroyPluginFunctionPtr = reinterpret_cast<ScriptPlugin::Destroy*>( dlsym( mLibHandle, "DestroyScriptPlugin" ) );
114 if( !mDestroyPluginFunctionPtr )
116 DALI_LOG_ERROR( "Cannot load symbol:DestroyScriptPlugin(). %s\n", dlerror() );
123 mScriptingPlugin = mCreatePluginFunctionPtr();
125 if( !mScriptingPlugin )
127 DALI_LOG_ERROR( "Call to function CreateFeedbackPlugin() failed\n" );
131 mIsInitialized = true;
134 void ScriptPluginProxy::UnInitialize()
136 if( mScriptingPlugin )
138 mDestroyPluginFunctionPtr( mScriptingPlugin );
143 if( dlclose( mLibHandle ) )
145 DALI_LOG_ERROR( "Error closing dali plugin library: %s\n", dlerror() );
148 mIsInitialized = false;
150 } // namespace Adaptor
152 } // namespace Internal