83654f0d865c7f7e54ddb1b905725d4c35835435
[platform/core/uifw/dali-adaptor.git] / adaptors / 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 <sound-player-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/type-registry.h>
23
24 // INTERNAL INCLUDES
25 #include <adaptor-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 // Type Registration
40 Dali::BaseHandle Create()
41 {
42   return SoundPlayer::Get();
43 }
44
45 Dali::TypeRegistration SOUND_PLAYER_TYPE( typeid(Dali::SoundPlayer), typeid(Dali::BaseHandle), Create );
46
47 Dali::SignalConnectorType SIGNAL_CONNECTOR_1( SOUND_PLAYER_TYPE, Dali::SoundPlayer::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   if ( Adaptor::IsAvailable() )
62   {
63     // Check whether the singleton is already created
64     Dali::BaseHandle handle = Adaptor::Get().GetSingleton( typeid( Dali::SoundPlayer ) );
65     if ( handle )
66     {
67       // If so, downcast the handle
68       player = Dali::SoundPlayer( dynamic_cast< SoundPlayer* >( handle.GetObjectPtr() ) );
69     }
70     else
71     {
72       Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) );
73       player = Dali::SoundPlayer( New() );
74       adaptorImpl.RegisterSingleton( 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::SoundPlayFinishedSignalV2& SoundPlayer::SoundPlayFinishedSignal()
92 {
93   return mSoundPlayFinishedSignalV2;
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 &&
102       Dali::SoundPlayer::SIGNAL_SOUND_PLAY_FINISHED == signalName )
103   {
104     player->SoundPlayFinishedSignal().Connect( tracker, functor );
105   }
106   else
107   {
108     // signalName does not match any signal
109     connected = false;
110   }
111
112   return connected;
113 }
114
115 SoundPlayer::SoundPlayer()
116 : mPlugin( FeedbackPluginProxy::DEFAULT_OBJECT_NAME )
117 {
118 }
119
120 SoundPlayer::~SoundPlayer()
121 {
122 }
123
124 void SoundPlayer::EmitSoundPlayFinishedSignal()
125 {
126   // Emit SoundPlayFinished signal
127
128   if ( !mSoundPlayFinishedSignalV2.Empty() )
129   {
130     Dali::SoundPlayer handle( this );
131     mSoundPlayFinishedSignalV2.Emit( handle );
132   }
133 }
134
135 } // namespace Adaptor
136
137 } // namespace Internal
138
139 } // namespace Dali