Merge "Changes needed for https://review.tizen.org/gerrit/#/c/191202/" into devel...
[platform/core/uifw/dali-adaptor.git] / dali / internal / accessibility / tizen / tts-player-impl-tizen.h
1 #ifndef DALI_INTERNAL_ACCESSIBILITY_TIZEN_TTS_PLAYER_IMPL_TIZEN_H
2 #define DALI_INTERNAL_ACCESSIBILITY_TIZEN_TTS_PLAYER_IMPL_TIZEN_H
3
4 /*
5  * Copyright (c) 2018 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 <tts.h>
23 #include <string>
24 #include <memory>
25
26 #include <dali/integration-api/debug.h>
27 #include <dali/public-api/object/base-object.h>
28
29 // INTERNAL INCLUDES
30 #include <dali/public-api/adaptor-framework/tts-player.h>
31 #include <dali/internal/accessibility/common/tts-player-impl.h>
32
33 namespace Dali
34 {
35
36 namespace Internal
37 {
38
39 namespace Adaptor
40 {
41
42 /**
43  * Text-to-speech player
44  */
45 class TtsPlayerTizen : public Dali::Internal::Adaptor::TtsPlayer
46 {
47
48 public:
49
50   /**
51    * Create a TtsPlayer with the given mode.
52    * This should only be called once by the Adaptor class for each given mode.
53    * @param mode the mode of tts-player
54    * @return A newly created TtsPlayer.
55    */
56   static std::unique_ptr<TtsPlayerTizen> New(Dali::TtsPlayer::Mode mode);
57
58   /**
59    * @copydoc TtsPlayer::Play()
60    */
61   void Play(const std::string& text) override;
62
63   /**
64    * @copydoc TtsPlayer::Stop()
65    */
66   void Stop() override;
67
68   /**
69    * @copydoc TtsPlayer::Pause()
70    */
71   void Pause() override;
72
73   /**
74    * @copydoc TtsPlayer::Resume()
75    */
76   void Resume() override;
77
78   /**
79    * @copydoc TtsPlayer::GetState()
80    */
81   Dali::TtsPlayer::State GetState() override;
82
83   /**
84    * @copydoc TtsPlayer::StateChangedSignal()
85    */
86   Dali::TtsPlayer::StateChangedSignalType& StateChangedSignal() override;
87
88   /**
89    * Destructor
90    */
91   ~TtsPlayerTizen() override;
92
93 private:
94
95   /**
96    * Private Constructor; see also TtsPlayer::New()
97    * @param mode the mode of tts-player
98    */
99   TtsPlayerTizen(Dali::TtsPlayer::Mode mode);
100
101   /**
102    * Initializes the player.
103    */
104   void Initialize();
105
106   /**
107    * Logs the error code.
108    * @param[in] reason The error code
109    */
110   void LogErrorCode(tts_error_e reason);
111
112   /**
113    * Used to emit the state changed signal from outside the object (EG. A static function).
114    * @param[in] previous The previous state
115    * @param[in] current The current state
116    */
117   void EmitStateChangedSignal( tts_state_e previous, tts_state_e current );
118
119   /**
120    * Called when the state of TTS is changed.
121    *
122    * @param[in] tts The handle for TTS
123    * @param[in] previous A previous state
124    * @param[in] current A current state
125    * @param[in] userData The user data passed from the callback registration function.
126    */
127   static void StateChangedCallback(tts_h tts, tts_state_e previous, tts_state_e current, void *userData);
128
129   // Undefined
130   TtsPlayerTizen(const TtsPlayerTizen&);
131
132   // Undefined
133   TtsPlayerTizen& operator=(TtsPlayerTizen&);
134
135 private:
136
137   Dali::TtsPlayer::StateChangedSignalType mStateChangedSignal; ///< Signal emitted when the TTS state changes
138   bool mInitialized; ///< Whether the TTS player is initialised successfully or not
139   std::string mUnplayedString; ///< The text that can not be played because tts engine is not yet initialized
140   tts_h mTtsHandle;  ///< The handle of TTS
141   int mUtteranceId;  ///< The utterance ID
142
143   Dali::TtsPlayer::Mode mTtsMode; ///< The current mode of tts engine
144
145 #if defined(DEBUG_ENABLED)
146 public:
147   static Debug::Filter* gLogFilter;
148 #endif
149 };
150
151 } // namespace Adaptor
152
153 } // namespace Internal
154
155 } // namespace Dali
156
157 #endif // DALI_INTERNAL_ACCESSIBILITY_TIZEN_TTS_PLAYER_IMPL_TIZEN_H