Merge "Fix descriptions according to checking header tools" into tizen
[platform/core/uifw/tts.git] / server / PlayerThread.h
1 /*
2 *  Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
3 *  Licensed under the Apache License, Version 2.0 (the "License");
4 *  you may not use this file except in compliance with the License.
5 *  You may obtain a copy of the License at
6 *  http://www.apache.org/licenses/LICENSE-2.0
7 *  Unless required by applicable law or agreed to in writing, software
8 *  distributed under the License is distributed on an "AS IS" BASIS,
9 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 *  See the License for the specific language governing permissions and
11 *  limitations under the License.
12 */
13
14
15 #ifndef __TTSD_PLAYER_MANAGER_H_
16 #define __TTSD_PLAYER_MANAGER_H_
17
18
19 #include <mutex>
20 #include <condition_variable>
21 #include <thread>
22 #include <atomic>
23 #include <queue>
24
25 class PlayerThread {
26 public:
27         typedef void (*PlayUtteranceCallback)(PlayerThread* player_instance, unsigned int uid);
28
29         PlayerThread(PlayUtteranceCallback threadFucntion);
30         ~PlayerThread();
31
32         unsigned int getCurrentUid();
33         bool isCurrentUid(unsigned int uid);
34
35         void requestPlay(unsigned int uid);
36         void requestStop();
37 private:
38         static void runThread(PlayerThread* player);
39
40         void runPlayer();
41         void tryToStopPlayer();
42         bool isPlayerAvailable();
43         bool isThreadStopped();
44
45 private:
46         std::atomic<unsigned int> mCurrentUid;
47         std::atomic<bool> mPlayerAvailable;
48
49         std::thread mPlayerThread;
50         std::mutex mThreadMutex;
51         std::mutex mControlMutex;
52         std::mutex mStopCheckMutex;
53         std::condition_variable mThreadCond;
54         std::condition_variable mStopCheckCond;
55
56         PlayUtteranceCallback mPlayUtterance;
57 };
58
59
60 #endif /* __TTSD_PLAYER_MANAGER_H_ */