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 <sound-player-impl.h>
22 #include <dali/public-api/object/type-registry.h>
25 #include <singleton-service-impl.h>
36 namespace // unnamed namespace
40 Dali::BaseHandle Create()
42 return SoundPlayer::Get();
45 Dali::TypeRegistration SOUND_PLAYER_TYPE( typeid(Dali::SoundPlayer), typeid(Dali::BaseHandle), Create );
47 Dali::SignalConnectorType SIGNAL_CONNECTOR_1( SOUND_PLAYER_TYPE, Dali::SoundPlayer::SIGNAL_SOUND_PLAY_FINISHED, Dali::Internal::Adaptor::SoundPlayer::DoConnectSignal );
49 } // unnamed namespace
51 Dali::SoundPlayer SoundPlayer::New()
53 Dali::SoundPlayer player = Dali::SoundPlayer( new SoundPlayer() );
57 Dali::SoundPlayer SoundPlayer::Get()
59 Dali::SoundPlayer player;
61 Dali::SingletonService service( SingletonService::Get() );
64 // Check whether the singleton is already created
65 Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::SoundPlayer ) );
68 // If so, downcast the handle
69 player = Dali::SoundPlayer( dynamic_cast< SoundPlayer* >( handle.GetObjectPtr() ) );
73 player = Dali::SoundPlayer( New() );
74 service.Register( typeid( player ), player );
81 int SoundPlayer::PlaySound( const std::string fileName )
83 return mPlugin.PlaySound( fileName );
86 void SoundPlayer::Stop( int handle )
88 mPlugin.StopSound( handle );
91 SoundPlayer::SoundPlayFinishedSignalV2& SoundPlayer::SoundPlayFinishedSignal()
93 return mSoundPlayFinishedSignalV2;
96 bool SoundPlayer::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
98 bool connected( true );
99 SoundPlayer* player = dynamic_cast<SoundPlayer*>( object );
102 Dali::SoundPlayer::SIGNAL_SOUND_PLAY_FINISHED == signalName )
104 player->SoundPlayFinishedSignal().Connect( tracker, functor );
108 // signalName does not match any signal
115 SoundPlayer::SoundPlayer()
116 : mPlugin( FeedbackPluginProxy::DEFAULT_OBJECT_NAME )
120 SoundPlayer::~SoundPlayer()
124 void SoundPlayer::EmitSoundPlayFinishedSignal()
126 // Emit SoundPlayFinished signal
128 if ( !mSoundPlayFinishedSignalV2.Empty() )
130 Dali::SoundPlayer handle( this );
131 mSoundPlayFinishedSignalV2.Emit( handle );
135 } // namespace Adaptor
137 } // namespace Internal