2 * Copyright (c) 2019 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-player-impl.h>
22 #include <dali/public-api/object/type-registry.h>
23 #include <dali/devel-api/adaptor-framework/file-loader.h>
24 #include <dali/integration-api/debug.h>
27 #include <dali/internal/system/common/singleton-service-impl.h>
38 namespace // unnamed namespace
42 Dali::BaseHandle Create()
44 return FeedbackPlayer::Get();
47 Dali::TypeRegistration FEEDBACK_PLAYER_TYPE( typeid(Dali::FeedbackPlayer), typeid(Dali::BaseHandle), Create );
49 } // unnamed namespace
51 Dali::FeedbackPlayer FeedbackPlayer::New()
53 Dali::FeedbackPlayer player = Dali::FeedbackPlayer( new FeedbackPlayer() );
57 Dali::FeedbackPlayer FeedbackPlayer::Get()
59 Dali::FeedbackPlayer player;
61 Dali::SingletonService service( SingletonService::Get() );
64 // Check whether the singleton is already created
65 Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::FeedbackPlayer ) );
68 // If so, downcast the handle
69 player = Dali::FeedbackPlayer( dynamic_cast< FeedbackPlayer* >( handle.GetObjectPtr() ) );
73 player = Dali::FeedbackPlayer( New() );
74 service.Register( typeid( player ), player );
81 void FeedbackPlayer::PlayMonotone( unsigned int duration )
83 mPlugin.PlayHapticMonotone( duration );
86 void FeedbackPlayer::PlayFile( const std::string& filePath )
88 mPlugin.PlayHaptic( filePath );
91 void FeedbackPlayer::Stop()
96 int FeedbackPlayer::PlaySound( const std::string& filename )
98 return mPlugin.PlaySound(filename);
101 void FeedbackPlayer::StopSound( int handle )
103 mPlugin.StopSound(handle);
106 void FeedbackPlayer::PlayFeedbackPattern( int type, int pattern )
108 mPlugin.PlayFeedbackPattern(type, pattern);
111 bool FeedbackPlayer::LoadFile(const std::string& filename, std::string& data)
115 std::streampos bufferSize = 0;
116 Dali::Vector<char> fileBuffer;
117 if( Dali::FileLoader::ReadFile( filename, bufferSize, fileBuffer, FileLoader::FileType::TEXT ) )
119 data.assign( &fileBuffer[0], bufferSize );
126 FeedbackPlayer::FeedbackPlayer()
127 : mPlugin( FeedbackPluginProxy::DEFAULT_OBJECT_NAME )
131 FeedbackPlayer::~FeedbackPlayer()
135 } // namespace Adaptor
137 } // namespace Internal