Add new class for managing activated mode 61/279161/5
authorSuyeon Hwang <stom.hwang@samsung.com>
Thu, 28 Jul 2022 11:44:59 +0000 (20:44 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Wed, 17 Aug 2022 02:55:35 +0000 (11:55 +0900)
- 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 <stom.hwang@samsung.com>
server/ActivatedModes.cpp [new file with mode: 0644]
server/ActivatedModes.h [new file with mode: 0644]
server/CMakeLists.txt
server/ttsd_data.cpp
server/ttsd_data.h

diff --git a/server/ActivatedModes.cpp b/server/ActivatedModes.cpp
new file mode 100644 (file)
index 0000000..1d03a25
--- /dev/null
@@ -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<int>(mode);
+
+       if (index < static_cast<int>(TTSD_MODE_DEFAULT) || index > static_cast<int>(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 (file)
index 0000000..030e0ef
--- /dev/null
@@ -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_ */
index bce84254c412f6654eaba768fe4bd658df8c5844..706021a371aba8a22ac166f2559ed96ac0d478f5 100644 (file)
@@ -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
index 7d08828c3d4b2a3b4d78834fb601b1af85104ee3..b00ad33018637320e4ebed68351211392077f7f9 100644 (file)
@@ -17,6 +17,8 @@
 #include <vector>
 #include <atomic>
 
+#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<ttsd_synthesis_control_e> 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<mutex> lock(g_app_data_mutex);
index b9c5e988178b86be11af99b4f6d6f1d79d9b6d96..a3dc88b2872e67ed6229573302babb3899af0ebc 100644 (file)
@@ -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);