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 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 if( mLibHandle && dlclose( mLibHandle ) )
55 DALI_LOG_ERROR( "Error closing dali feedback plugin library: %s\n", dlerror() );
60 void FeedbackPluginProxy::PlayHaptic( const std::string& filePath )
62 // Lazy initialization
67 mFeedbackPlugin->PlayHaptic( filePath );
71 void FeedbackPluginProxy::PlayHapticMonotone( unsigned int duration )
73 // Lazy initialization
78 mFeedbackPlugin->PlayHapticMonotone( duration );
82 void FeedbackPluginProxy::StopHaptic()
84 // Must already have been initialized to play haptic
87 mFeedbackPlugin->StopHaptic();
91 int FeedbackPluginProxy::PlaySound( const std::string& fileName )
93 // Lazy initialization
98 return mFeedbackPlugin->PlaySound( fileName );
104 void FeedbackPluginProxy::StopSound( int handle )
106 // Must already have been initialized to play sound
107 if ( mFeedbackPlugin )
109 mFeedbackPlugin->StopSound( handle );
113 void FeedbackPluginProxy::PlayFeedbackPattern( int type, int pattern )
115 // Lazy initialization
118 if( mFeedbackPlugin )
120 mFeedbackPlugin->PlayFeedbackPattern( type, pattern );
124 void FeedbackPluginProxy::Initialize()
126 // Only attempt to load dll once
127 if ( !mInitializeAttempted )
129 mInitializeAttempted = true;
131 mLibHandle = dlopen( mSharedObjectName.c_str(), RTLD_NOW | RTLD_GLOBAL );
134 DALI_LOG_ERROR( "Cannot load dali feedback plugin library error: %s\n", dlerror() );
142 mCreatePluginFunctionPtr = reinterpret_cast<CreateFeedbackPlugin*>(dlsym(mLibHandle, "CreateFeedbackPlugin"));
143 if(!mCreatePluginFunctionPtr)
145 DALI_LOG_ERROR("Cannot load symbol CreateFeedbackPlugin(): %s\n", dlerror());
152 mFeedbackPlugin = mCreatePluginFunctionPtr();
156 DALI_LOG_ERROR("Call to function CreateFeedbackPlugin() failed\n");
161 } // namespace Adaptor
163 } // namespace Internal