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