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/devel-api/common/singleton-service.h>
25 #include <dali/integration-api/debug.h>
36 namespace // unnamed namespace
40 Dali::BaseHandle Create()
42 return FeedbackPlayer::Get();
45 Dali::TypeRegistration FEEDBACK_PLAYER_TYPE( typeid(Dali::FeedbackPlayer), typeid(Dali::BaseHandle), Create );
47 } // unnamed namespace
49 Dali::FeedbackPlayer FeedbackPlayer::New()
51 Dali::FeedbackPlayer player = Dali::FeedbackPlayer( new FeedbackPlayer() );
55 Dali::FeedbackPlayer FeedbackPlayer::Get()
57 Dali::FeedbackPlayer player;
59 Dali::SingletonService service( SingletonService::Get() );
62 // Check whether the singleton is already created
63 Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::FeedbackPlayer ) );
66 // If so, downcast the handle
67 player = Dali::FeedbackPlayer( dynamic_cast< FeedbackPlayer* >( handle.GetObjectPtr() ) );
71 player = Dali::FeedbackPlayer( New() );
72 service.Register( typeid( player ), player );
79 void FeedbackPlayer::PlayMonotone( unsigned int duration )
81 mPlugin.PlayHapticMonotone( duration );
84 void FeedbackPlayer::PlayFile( const std::string& filePath )
86 mPlugin.PlayHaptic( filePath );
89 void FeedbackPlayer::Stop()
94 int FeedbackPlayer::PlaySound( const std::string& filename )
96 return mPlugin.PlaySound(filename);
99 void FeedbackPlayer::StopSound( int handle )
101 mPlugin.StopSound(handle);
104 void FeedbackPlayer::PlayFeedbackPattern( int type, int pattern )
106 mPlugin.PlayFeedbackPattern(type, pattern);
109 bool FeedbackPlayer::LoadFile(const std::string& filename, std::string& data)
113 std::streampos bufferSize = 0;
114 Dali::Vector<char> fileBuffer;
115 if( Dali::FileLoader::ReadFile( filename, bufferSize, fileBuffer, FileLoader::FileType::TEXT ) )
117 data.assign( &fileBuffer[0], bufferSize );
124 FeedbackPlayer::FeedbackPlayer()
125 : mPlugin( FeedbackPluginProxy::DEFAULT_OBJECT_NAME )
129 FeedbackPlayer::~FeedbackPlayer()
133 } // namespace Adaptor
135 } // namespace Internal