Dali 3D User Interface Engine
feedback-plugin-proxy.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 
18 // CLASS HEADER
20 
21 // EXTERNAL INCLUDES
22 #include <dlfcn.h>
24 
25 namespace Dali
26 {
27 
28 namespace Internal
29 {
30 
31 namespace Adaptor
32 {
33 
34 const char * const FeedbackPluginProxy::DEFAULT_OBJECT_NAME( "libdali-feedback-plugin.so" );
35 
36 FeedbackPluginProxy::FeedbackPluginProxy( const std::string& sharedObjectName )
37 : mInitializeAttempted( false ),
38  mLibHandle( NULL ),
39  mSharedObjectName( sharedObjectName ),
40  mCreatePluginFunctionPtr( NULL ),
41  mFeedbackPlugin( NULL )
42 {
43  // Lazily initialize when sound/haptic is first played
44 }
45 
47 {
48  if( mFeedbackPlugin )
49  {
50  delete mFeedbackPlugin;
51  mFeedbackPlugin = NULL;
52 
53  if( mLibHandle && dlclose( mLibHandle ) )
54  {
55  DALI_LOG_ERROR( "Error closing dali feedback plugin library: %s\n", dlerror() );
56  }
57  }
58 }
59 
60 void FeedbackPluginProxy::PlayHaptic( const std::string& filePath )
61 {
62  // Lazy initialization
63  Initialize();
64 
65  if( mFeedbackPlugin )
66  {
67  mFeedbackPlugin->PlayHaptic( filePath );
68  }
69 }
70 
71 void FeedbackPluginProxy::PlayHapticMonotone( unsigned int duration )
72 {
73  // Lazy initialization
74  Initialize();
75 
76  if( mFeedbackPlugin )
77  {
78  mFeedbackPlugin->PlayHapticMonotone( duration );
79  }
80 }
81 
83 {
84  // Must already have been initialized to play haptic
85  if( mFeedbackPlugin )
86  {
87  mFeedbackPlugin->StopHaptic();
88  }
89 }
90 
91 int FeedbackPluginProxy::PlaySound( const std::string& fileName )
92 {
93  // Lazy initialization
94  Initialize();
95 
96  if( mFeedbackPlugin )
97  {
98  return mFeedbackPlugin->PlaySound( fileName );
99  }
100 
101  return 0;
102 }
103 
105 {
106  // Must already have been initialized to play sound
107  if ( mFeedbackPlugin )
108  {
109  mFeedbackPlugin->StopSound( handle );
110  }
111 }
112 
113 void FeedbackPluginProxy::PlayFeedbackPattern( int type, int pattern )
114 {
115  // Lazy initialization
116  Initialize();
117 
118  if( mFeedbackPlugin )
119  {
120  mFeedbackPlugin->PlayFeedbackPattern( type, pattern );
121  }
122 }
123 
125 {
126  // Only attempt to load dll once
127  if ( !mInitializeAttempted )
128  {
129  mInitializeAttempted = true;
130 
131  mLibHandle = dlopen( mSharedObjectName.c_str(), RTLD_NOW | RTLD_GLOBAL );
132  if( !mLibHandle )
133  {
134  DALI_LOG_ERROR( "Cannot load dali feedback plugin library error: %s\n", dlerror() );
135  return;
136  }
137 
138  // reset errors
139  dlerror();
140 
141  // load plugin
142  mCreatePluginFunctionPtr = reinterpret_cast<CreateFeedbackPlugin*>(dlsym(mLibHandle, "CreateFeedbackPlugin"));
144  {
145  DALI_LOG_ERROR("Cannot load symbol CreateFeedbackPlugin(): %s\n", dlerror());
146  return;
147  }
148 
149  // reset errors
150  dlerror();
151 
153 
154  if(!mFeedbackPlugin)
155  {
156  DALI_LOG_ERROR("Call to function CreateFeedbackPlugin() failed\n");
157  }
158  }
159 }
160 
161 } // namespace Adaptor
162 
163 } // namespace Internal
164 
165 } // namespace Dali
Dali Docs Home
Read more about Dali