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 <dali/internal/haptics/common/feedback-plugin-proxy.h>
22 #include <dali/integration-api/debug.h>
31 const char* const FeedbackPluginProxy::DEFAULT_OBJECT_NAME("libdali2-feedback-plugin.so");
33 FeedbackPluginProxy::FeedbackPluginProxy(const std::string& sharedObjectName)
34 : mInitializeAttempted(false),
36 mSharedObjectName(sharedObjectName),
37 mCreatePluginFunctionPtr(NULL),
40 // Lazily initialize when sound/haptic is first played
43 FeedbackPluginProxy::~FeedbackPluginProxy()
47 delete mFeedbackPlugin;
48 mFeedbackPlugin = NULL;
50 if(mLibHandle && dlclose(mLibHandle))
52 DALI_LOG_ERROR("Error closing dali feedback plugin library: %s\n", dlerror());
57 void FeedbackPluginProxy::PlayHaptic(const std::string& filePath)
59 // Lazy initialization
64 mFeedbackPlugin->PlayHaptic(filePath);
68 void FeedbackPluginProxy::PlayHapticMonotone(unsigned int duration)
70 // Lazy initialization
75 mFeedbackPlugin->PlayHapticMonotone(duration);
79 void FeedbackPluginProxy::StopHaptic()
81 // Must already have been initialized to play haptic
84 mFeedbackPlugin->StopHaptic();
88 int FeedbackPluginProxy::PlaySound(const std::string& fileName)
90 // Lazy initialization
95 return mFeedbackPlugin->PlaySound(fileName);
101 void FeedbackPluginProxy::StopSound(int handle)
103 // Must already have been initialized to play sound
106 mFeedbackPlugin->StopSound(handle);
110 void FeedbackPluginProxy::PlayFeedbackPattern(int type, int pattern)
112 // Lazy initialization
117 mFeedbackPlugin->PlayFeedbackPattern(type, pattern);
121 void FeedbackPluginProxy::Initialize()
123 // Only attempt to load dll once
124 if(!mInitializeAttempted)
126 mInitializeAttempted = true;
128 mLibHandle = dlopen(mSharedObjectName.c_str(), RTLD_NOW | RTLD_GLOBAL);
131 DALI_LOG_ERROR("Cannot load dali feedback plugin library error: %s\n", dlerror());
139 mCreatePluginFunctionPtr = reinterpret_cast<CreateFeedbackPlugin*>(dlsym(mLibHandle, "CreateFeedbackPlugin"));
140 if(!mCreatePluginFunctionPtr)
142 DALI_LOG_ERROR("Cannot load symbol CreateFeedbackPlugin(): %s\n", dlerror());
149 mFeedbackPlugin = mCreatePluginFunctionPtr();
153 DALI_LOG_ERROR("Call to function CreateFeedbackPlugin() failed\n");
158 } // namespace Adaptor
160 } // namespace Internal