From ed66d36a14ff46196d0624683f2673f4eca9f327 Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Thu, 28 Jul 2022 20:44:59 +0900 Subject: [PATCH] Add new class for managing activated mode - Requirement: TTS server should manage current activated mode information. This information for the service engine application to help decide behavior of the application. - Solution: In order to store and manage currently activated mode information, this patch adds new class. This new class only manages the currently activated mode information, and other modules can get this information through the methods of this class. Change-Id: I13d47ebcf3b28c18583ac3dbe14302af0438bf94 Signed-off-by: Suyeon Hwang --- server/ActivatedModes.cpp | 67 +++++++++++++++++++++++++++++++++++++++ server/ActivatedModes.h | 40 +++++++++++++++++++++++ server/CMakeLists.txt | 1 + server/ttsd_data.cpp | 12 +++++++ server/ttsd_data.h | 2 ++ 5 files changed, 122 insertions(+) create mode 100644 server/ActivatedModes.cpp create mode 100644 server/ActivatedModes.h diff --git a/server/ActivatedModes.cpp b/server/ActivatedModes.cpp new file mode 100644 index 00000000..1d03a25f --- /dev/null +++ b/server/ActivatedModes.cpp @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* http://www.apache.org/licenses/LICENSE-2.0 +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +#include "ActivatedModes.h" + +ActivatedModes::ActivatedModes() +{ + for (int i = 0; i < __numOfModes; i++) { + __modeCounts[i] = 0; + } + + __modeFlags[0] = TTSE_MODE_MASK_DEFAULT; + __modeFlags[1] = TTSE_MODE_MASK_NOTIFICATION; + __modeFlags[2] = TTSE_MODE_MASK_SCREEN_READER; + __modeFlags[3] = TTSE_MODE_MASK_INTERRUPT; +} + +ActivatedModes::~ActivatedModes() +{ +} + +void ActivatedModes::addMode(ttsd_mode_e mode) +{ + int index = getIndex(mode); + __modeCounts[index]++; +} + +void ActivatedModes::removeMode(ttsd_mode_e mode) +{ + int index = getIndex(mode); + __modeCounts[index]--; +} + +int ActivatedModes::getModes() +{ + int result = 0; + for (int i = 0; i < __numOfModes; i++) { + if (__modeCounts[i] > 0) { + result |= __modeFlags[i]; + } + } + + return result; +} + +int ActivatedModes::getIndex(ttsd_mode_e mode) +{ + int index = static_cast(mode); + + if (index < static_cast(TTSD_MODE_DEFAULT) || index > static_cast(TTSD_MODE_INTERRUPT)) { + SLOG(LOG_WARN, tts_tag(), "[ActivatedModes] mode is invalid (%d). Handle as default.", index); + index = 0; + } + + return index; +} diff --git a/server/ActivatedModes.h b/server/ActivatedModes.h new file mode 100644 index 00000000..030e0efc --- /dev/null +++ b/server/ActivatedModes.h @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* http://www.apache.org/licenses/LICENSE-2.0 +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +#ifndef __TTSD_ACTIVATED_MODES_H_ +#define __TTSD_ACTIVATED_MODES_H_ + +#include "ttsd_main.h" + +class ActivatedModes { +public: + ActivatedModes(); + ~ActivatedModes(); + + void addMode(ttsd_mode_e mode); + void removeMode(ttsd_mode_e mode); + int getModes(); + +private: + int getIndex(ttsd_mode_e mode); + +private: + static const int __numOfModes = 4; + ttse_mode_mask_e __modeFlags[__numOfModes]; + + int __modeCounts[__numOfModes]; +}; + + +#endif /* __TTSD_ACTIVATED_MODES_H_ */ diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index bce84254..706021a3 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -12,6 +12,7 @@ SET(SRCS BackgroundVolume.cpp AudioStream.cpp PlayerThread.cpp + ActivatedModes.cpp ttsd_server.c ../common/tts_config_mgr.c ../common/tts_config_parser.c diff --git a/server/ttsd_data.cpp b/server/ttsd_data.cpp index 7d08828c..b00ad330 100644 --- a/server/ttsd_data.cpp +++ b/server/ttsd_data.cpp @@ -17,6 +17,8 @@ #include #include +#include "ActivatedModes.h" + #include "ttsd_data.h" using namespace std; @@ -54,6 +56,8 @@ static mutex g_app_data_mutex; /* If engine is running */ static atomic g_synth_control; +static ActivatedModes g_activated_modes; + #ifdef DATA_DEBUG static void __data_show_list() { @@ -174,6 +178,7 @@ int ttsd_data_new_client(int pid, unsigned int uid, ttsd_mode_e mode, tts_ipc_me app.paused_data_existing = false; g_app_list.push_back(app); + g_activated_modes.addMode(mode); #ifdef DATA_DEBUG __data_show_list(); @@ -256,7 +261,9 @@ int ttsd_data_delete_client(unsigned int uid) __clean_data(g_app_list[index]); + ttsd_mode_e mode = g_app_list[index].mode; g_app_list.erase(g_app_list.begin() + index); + g_activated_modes.removeMode(mode); #ifdef DATA_DEBUG __data_show_list(); @@ -894,6 +901,11 @@ int ttsd_data_get_same_pid_client_count(int pid) return number; } +int ttsd_data_get_activated_mode() +{ + return g_activated_modes.getModes(); +} + int ttsd_data_save_error_log(unsigned int uid, FILE* fp) { lock_guard lock(g_app_data_mutex); diff --git a/server/ttsd_data.h b/server/ttsd_data.h index b9c5e988..a3dc88b2 100644 --- a/server/ttsd_data.h +++ b/server/ttsd_data.h @@ -145,6 +145,8 @@ bool ttsd_data_is_uttid_valid(unsigned int uid, int uttid); int ttsd_data_get_same_pid_client_count(int pid); +int ttsd_data_get_activated_mode(); + /* For error handing */ int ttsd_data_save_error_log(unsigned int uid, FILE* fp); -- 2.34.1