[dali_2.3.31] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / dali / internal / system / common / sound-player-impl.h
1 #ifndef DALI_INTERNAL_SOUND_PLAYER_H
2 #define DALI_INTERNAL_SOUND_PLAYER_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/base-object.h>
23 #include <string>
24
25 // INTERNAL INCLUDES
26 #include <dali/devel-api/adaptor-framework/sound-player.h>
27 #include <dali/internal/haptics/common/feedback-plugin-proxy.h>
28
29 namespace Dali
30 {
31 namespace Internal
32 {
33 namespace Adaptor
34 {
35 /**
36  * Plays haptic effects.
37  */
38 class SoundPlayer : public Dali::BaseObject
39 {
40 public:
41   typedef Dali::SoundPlayer::SoundPlayFinishedSignalType SoundPlayFinishedSignalType;
42
43   /**
44    * Create a SoundPlayer.
45    * @return A newly created SoundPlayer.
46    */
47   static Dali::SoundPlayer New();
48
49   /**
50    * Retrieve a handle to the SoundPlayer. This creates an instance if none has been created.
51    * @return A handle to the SoundPlayer.
52    */
53   static Dali::SoundPlayer Get();
54
55   /**
56    * @copydoc Dali::SoundPlayer::PlaySound()
57    */
58   int PlaySound(const std::string fileName);
59
60   /**
61    * @copydoc Dali::SoundPlayer::Stop()
62    */
63   void Stop(int handle);
64
65   /**
66    * @copydoc Dali::SoundPlayer::SoundPlayFinishedSignal()
67    */
68   SoundPlayFinishedSignalType& SoundPlayFinishedSignal();
69
70   /**
71    * Connects a callback function with the object's signals.
72    * @param[in] object The object providing the signal.
73    * @param[in] tracker Used to disconnect the signal.
74    * @param[in] signalName The signal to connect to.
75    * @param[in] functor A newly allocated FunctorDelegate.
76    * @return True if the signal was connected.
77    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
78    */
79   static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
80
81 private:
82   /**
83    * Private Constructor; see also soundPlayer::New()
84    * @param[in]  soundPlayer  The public sound player class
85    */
86   SoundPlayer();
87
88   /**
89    * Destructor
90    */
91   ~SoundPlayer() override;
92
93   /**
94    * Emits the SoundPlayFinished signal.
95    */
96   void EmitSoundPlayFinishedSignal();
97
98   // Undefined
99   SoundPlayer(const SoundPlayer&);
100
101   // Undefined
102   SoundPlayer& operator=(SoundPlayer&);
103
104 private:
105   FeedbackPluginProxy         mPlugin;
106   SoundPlayFinishedSignalType mSoundPlayFinishedSignal;
107 };
108
109 } // namespace Adaptor
110
111 } // namespace Internal
112
113 // Helpers for public-api forwarding methods
114
115 inline Internal::Adaptor::SoundPlayer& GetImplementation(Dali::SoundPlayer& player)
116 {
117   DALI_ASSERT_ALWAYS(player && "SoundPlayer handle is empty");
118
119   BaseObject& handle = player.GetBaseObject();
120
121   return static_cast<Internal::Adaptor::SoundPlayer&>(handle);
122 }
123
124 inline const Internal::Adaptor::SoundPlayer& GetImplementation(const Dali::SoundPlayer& player)
125 {
126   DALI_ASSERT_ALWAYS(player && "SoundPlayer handle is empty");
127
128   const BaseObject& handle = player.GetBaseObject();
129
130   return static_cast<const Internal::Adaptor::SoundPlayer&>(handle);
131 }
132
133 } // namespace Dali
134
135 #endif // DALI_INTERNAL_SOUND_PLAYER_H