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