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 <internal/common/feedback/feedback-plugin-proxy.h>
23 #include <dali/integration-api/debug.h>
34 const char * const FeedbackPluginProxy::DEFAULT_OBJECT_NAME( "libdali-feedback-plugin.so" );
36 FeedbackPluginProxy::FeedbackPluginProxy( const std::string& sharedObjectName )
37 : mInitializeAttempted( false ),
39 mSharedObjectName( sharedObjectName ),
40 mCreatePluginFunctionPtr( NULL ),
41 mFeedbackPlugin( NULL )
43 // Lazily initialize when sound/haptic is first played
46 FeedbackPluginProxy::~FeedbackPluginProxy()
50 delete mFeedbackPlugin;
51 mFeedbackPlugin = NULL;
53 DALI_ASSERT_ALWAYS( mLibHandle );
54 if( dlclose( mLibHandle ) )
56 DALI_LOG_ERROR( "Error closing dali feedback plugin library: %s\n", dlerror() );
61 void FeedbackPluginProxy::PlayHaptic( const std::string& filePath )
63 // Lazy initialization
68 mFeedbackPlugin->PlayHaptic( filePath );
72 void FeedbackPluginProxy::PlayHapticMonotone( unsigned int duration )
74 // Lazy initialization
79 mFeedbackPlugin->PlayHapticMonotone( duration );
83 void FeedbackPluginProxy::StopHaptic()
85 // Must already have been initialized to play haptic
88 mFeedbackPlugin->StopHaptic();
92 int FeedbackPluginProxy::PlaySound( const std::string& fileName )
94 // Lazy initialization
99 return mFeedbackPlugin->PlaySound( fileName );
105 void FeedbackPluginProxy::StopSound( int handle )
107 // Must already have been initialized to play sound
108 if ( mFeedbackPlugin )
110 mFeedbackPlugin->StopSound( handle );
114 void FeedbackPluginProxy::PlayFeedbackPattern( int type, int pattern )
116 // Lazy initialization
119 if( mFeedbackPlugin )
121 mFeedbackPlugin->PlayFeedbackPattern( type, pattern );
125 void FeedbackPluginProxy::Initialize()
127 // Only attempt to load dll once
128 if ( !mInitializeAttempted )
130 mInitializeAttempted = true;
132 mLibHandle = dlopen( mSharedObjectName.c_str(), RTLD_NOW | RTLD_GLOBAL );
135 DALI_LOG_ERROR( "Cannot load dali feedback plugin library error: %s\n", dlerror() );
143 mCreatePluginFunctionPtr = reinterpret_cast<CreateFeedbackPlugin*>(dlsym(mLibHandle, "CreateFeedbackPlugin"));
144 if(!mCreatePluginFunctionPtr)
146 DALI_LOG_ERROR("Cannot load symbol CreateFeedbackPlugin(): %s\n", dlerror());
153 mFeedbackPlugin = mCreatePluginFunctionPtr();
157 DALI_LOG_ERROR("Call to function CreateFeedbackPlugin() failed\n");
162 } // namespace Adaptor
164 } // namespace Internal