62084d5e658976d930469ad4f3a86dcb8da42950
[platform/core/uifw/dali-adaptor.git] / dali / internal / system / common / sound-player-impl.cpp
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
19 #include <dali/internal/system/common/sound-player-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/type-registry.h>
23
24 // INTERNAL INCLUDES
25 #include <dali/internal/system/common/singleton-service-impl.h>
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 namespace Adaptor
34 {
35
36 namespace // unnamed namespace
37 {
38
39 const char* const SIGNAL_SOUND_PLAY_FINISHED = "soundPlayFinished";
40
41 // Type Registration
42 Dali::BaseHandle GetInstance()
43 {
44   return SoundPlayer::Get();
45 }
46
47 Dali::TypeRegistration SOUND_PLAYER_TYPE( typeid(Dali::SoundPlayer), typeid(Dali::BaseHandle), GetInstance );
48
49 Dali::SignalConnectorType SIGNAL_CONNECTOR_1( SOUND_PLAYER_TYPE, SIGNAL_SOUND_PLAY_FINISHED, Dali::Internal::Adaptor::SoundPlayer::DoConnectSignal );
50
51 } // unnamed namespace
52
53 Dali::SoundPlayer SoundPlayer::New()
54 {
55   Dali::SoundPlayer player = Dali::SoundPlayer( new SoundPlayer() );
56   return player;
57 }
58
59 Dali::SoundPlayer SoundPlayer::Get()
60 {
61   Dali::SoundPlayer player;
62
63   Dali::SingletonService service( SingletonService::Get() );
64   if ( service )
65   {
66     // Check whether the singleton is already created
67     Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::SoundPlayer ) );
68     if ( handle )
69     {
70       // If so, downcast the handle
71       player = Dali::SoundPlayer( dynamic_cast< SoundPlayer* >( handle.GetObjectPtr() ) );
72     }
73     else
74     {
75       player = Dali::SoundPlayer( New() );
76       service.Register( typeid( player ), player );
77     }
78   }
79
80   return player;
81 }
82
83 int SoundPlayer::PlaySound( const std::string fileName )
84 {
85   return mPlugin.PlaySound( fileName );
86 }
87
88 void SoundPlayer::Stop( int handle )
89 {
90   mPlugin.StopSound( handle );
91 }
92
93 SoundPlayer::SoundPlayFinishedSignalType& SoundPlayer::SoundPlayFinishedSignal()
94 {
95   return mSoundPlayFinishedSignal;
96 }
97
98 bool SoundPlayer::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
99 {
100   bool connected( true );
101   SoundPlayer* player = dynamic_cast<SoundPlayer*>( object );
102
103   if( player && ( SIGNAL_SOUND_PLAY_FINISHED == signalName ) )
104   {
105     player->SoundPlayFinishedSignal().Connect( tracker, functor );
106   }
107   else
108   {
109     // signalName does not match any signal
110     connected = false;
111   }
112
113   return connected;
114 }
115
116 SoundPlayer::SoundPlayer()
117 : mPlugin( FeedbackPluginProxy::DEFAULT_OBJECT_NAME )
118 {
119 }
120
121 SoundPlayer::~SoundPlayer()
122 {
123 }
124
125 void SoundPlayer::EmitSoundPlayFinishedSignal()
126 {
127   // Emit SoundPlayFinished signal
128
129   if ( !mSoundPlayFinishedSignal.Empty() )
130   {
131     Dali::SoundPlayer handle( this );
132     mSoundPlayFinishedSignal.Emit( handle );
133   }
134 }
135
136 } // namespace Adaptor
137
138 } // namespace Internal
139
140 } // namespace Dali