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