2 * Copyright (c) 2016 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.
17 #include <dali/devel-api/adaptor-framework/feedback-player.h>
18 #include <dali/devel-api/adaptor-framework/singleton-service.h>
19 #include <dali/public-api/object/base-object.h>
32 class FeedbackPlayer : public Dali::BaseObject
35 static Dali::FeedbackPlayer New()
37 Dali::FeedbackPlayer player = Dali::FeedbackPlayer( new FeedbackPlayer() );
41 static Dali::FeedbackPlayer Get()
43 Dali::FeedbackPlayer player;
44 Dali::SingletonService service( Dali::SingletonService::Get() );
47 // Check whether the singleton is already created
48 Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::FeedbackPlayer ) );
51 player = Dali::FeedbackPlayer( dynamic_cast< FeedbackPlayer* >( handle.GetObjectPtr() ) );
55 player = Dali::FeedbackPlayer( New() );
56 service.Register( typeid( player ), player );
61 void PlayMonotone(unsigned int duration)
65 void PlayFile( const std::string& filePath )
73 int PlaySound( const std::string& fileName )
78 void StopSound( int handle )
82 void PlayFeedbackPattern( int type, int pattern )
86 bool LoadFile(const std::string& filename, std::string& data)
96 virtual ~FeedbackPlayer()
100 FeedbackPlayer(const FeedbackPlayer&)
104 FeedbackPlayer& operator=(FeedbackPlayer&)
113 inline Internal::Adaptor::FeedbackPlayer& GetImplementation(Dali::FeedbackPlayer& player)
115 DALI_ASSERT_ALWAYS( player && "FeedbackPlayer handle is empty" );
116 BaseObject& handle = player.GetBaseObject();
117 return static_cast<Internal::Adaptor::FeedbackPlayer&>(handle);
120 inline const Internal::Adaptor::FeedbackPlayer& GetImplementation(const Dali::FeedbackPlayer& player)
122 DALI_ASSERT_ALWAYS( player && "FeedbackPlayer handle is empty" );
123 const BaseObject& handle = player.GetBaseObject();
124 return static_cast<const Internal::Adaptor::FeedbackPlayer&>(handle);
127 FeedbackPlayer::FeedbackPlayer()
131 FeedbackPlayer FeedbackPlayer::Get()
133 return Internal::Adaptor::FeedbackPlayer::Get();
136 FeedbackPlayer::~FeedbackPlayer()
140 void FeedbackPlayer::PlayMonotone(unsigned int duration)
142 GetImplementation(*this).PlayMonotone(duration);
145 void FeedbackPlayer::PlayFile(const std::string filePath)
147 GetImplementation(*this).PlayFile(filePath);
150 void FeedbackPlayer::Stop()
152 GetImplementation(*this).Stop();
155 int FeedbackPlayer::PlaySound( const std::string& fileName )
157 return GetImplementation(*this).PlaySound(fileName);
160 void FeedbackPlayer::StopSound( int handle )
162 GetImplementation(*this).StopSound(handle);
165 void FeedbackPlayer::PlayFeedbackPattern( int type, int pattern )
167 GetImplementation(*this).PlayFeedbackPattern(type, pattern);
170 bool FeedbackPlayer::LoadFile(const std::string& filename, std::string& data)
172 return GetImplementation(*this).LoadFile(filename, data);
175 FeedbackPlayer::FeedbackPlayer( Internal::Adaptor::FeedbackPlayer* player )
176 : BaseHandle( player )