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 <feedback/feedback-plugin-proxy.h>
23 #include <dali/integration-api/debug.h>
34 #if _GLIBCXX_USE_CXX11_ABI
35 const char * const FeedbackPluginProxy::DEFAULT_OBJECT_NAME( "libdali-feedback-plugin.so" );
37 const char * const FeedbackPluginProxy::DEFAULT_OBJECT_NAME( "libdali-feedback-plugin-cxx03.so" );
40 FeedbackPluginProxy::FeedbackPluginProxy( const std::string& sharedObjectName )
41 : mInitializeAttempted( false ),
43 mSharedObjectName( sharedObjectName ),
44 mCreatePluginFunctionPtr( NULL ),
45 mFeedbackPlugin( NULL )
47 // Lazily initialize when sound/haptic is first played
50 FeedbackPluginProxy::~FeedbackPluginProxy()
54 delete mFeedbackPlugin;
55 mFeedbackPlugin = NULL;
57 if( mLibHandle && dlclose( mLibHandle ) )
59 DALI_LOG_ERROR( "Error closing dali feedback plugin library: %s\n", dlerror() );
64 void FeedbackPluginProxy::PlayHaptic( const std::string& filePath )
66 // Lazy initialization
71 mFeedbackPlugin->PlayHaptic( filePath );
75 void FeedbackPluginProxy::PlayHapticMonotone( unsigned int duration )
77 // Lazy initialization
82 mFeedbackPlugin->PlayHapticMonotone( duration );
86 void FeedbackPluginProxy::StopHaptic()
88 // Must already have been initialized to play haptic
91 mFeedbackPlugin->StopHaptic();
95 int FeedbackPluginProxy::PlaySound( const std::string& fileName )
97 // Lazy initialization
100 if( mFeedbackPlugin )
102 return mFeedbackPlugin->PlaySound( fileName );
108 void FeedbackPluginProxy::StopSound( int handle )
110 // Must already have been initialized to play sound
111 if ( mFeedbackPlugin )
113 mFeedbackPlugin->StopSound( handle );
117 void FeedbackPluginProxy::PlayFeedbackPattern( int type, int pattern )
119 // Lazy initialization
122 if( mFeedbackPlugin )
124 mFeedbackPlugin->PlayFeedbackPattern( type, pattern );
128 void FeedbackPluginProxy::Initialize()
130 // Only attempt to load dll once
131 if ( !mInitializeAttempted )
133 mInitializeAttempted = true;
135 mLibHandle = dlopen( mSharedObjectName.c_str(), RTLD_NOW | RTLD_GLOBAL );
138 DALI_LOG_ERROR( "Cannot load dali feedback plugin library error: %s\n", dlerror() );
146 mCreatePluginFunctionPtr = reinterpret_cast<CreateFeedbackPlugin*>(dlsym(mLibHandle, "CreateFeedbackPlugin"));
147 if(!mCreatePluginFunctionPtr)
149 DALI_LOG_ERROR("Cannot load symbol CreateFeedbackPlugin(): %s\n", dlerror());
156 mFeedbackPlugin = mCreatePluginFunctionPtr();
160 DALI_LOG_ERROR("Call to function CreateFeedbackPlugin() failed\n");
165 } // namespace Adaptor
167 } // namespace Internal