1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
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  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_MULTIMODAL_MULTIMODAL_SCENE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_MULTIMODAL_MULTIMODAL_SCENE_H
18 
19 #include <unordered_map>
20 #include <unordered_set>
21 #include <vector>
22 
23 #include "base/memory/ace_type.h"
24 #include "base/utils/event_callback.h"
25 #include "core/event/multimodal/multimodal_subscriber.h"
26 
27 namespace OHOS::Ace {
28 
29 class MultiModalScene final : public AceType {
DECLARE_ACE_TYPE(MultiModalScene,AceType)30     DECLARE_ACE_TYPE(MultiModalScene, AceType)
31 
32 public:
33     MultiModalScene(int32_t pageId, const RefPtr<MultimodalSubscriber>& subscriber)
34         : subscriber_(subscriber), pageId_(pageId) {}
35     ~MultiModalScene() override;
36 
37     std::string GetAvailableSubscriptId();
38     std::string GetCurrentMaxSubscriptId();
39     void RemoveSubscriptId(const std::string& subscriptId);
40 
41     bool SubscribeVoiceEvent(const VoiceEvent& voiceEvent, const MultimodalEventCallback& callback);
42     void UnSubscribeVoiceEvent(const VoiceEvent& voiceEvent);
43     void SubscribeSubscriptSwitchEvent(const EventCallback<void(bool)>& callback);
44     void UnSubscribeSubscriptSwitchEvent(const EventCallback<void(bool)>& callback);
45     void OnNotifyMultimodalEvent(const AceMultimodalEvent& event);
46     void UnSubscribeAllEvents();
47 
48     void Hide();
49     void Resume();
50 
GetPageId()51     int32_t GetPageId() const
52     {
53         return pageId_;
54     }
55 
56     void Dump() const;
57 
58 private:
59     std::unordered_set<std::string> cachedIds_;
60     std::vector<VoiceEvent> voiceEvents_;
61     std::vector<EventCallback<void(bool)>> subscriptSwitchListeners_;
62     std::unordered_map<std::string, MultimodalEventCallback> voiceEventCallbacks_;
63     RefPtr<MultimodalSubscriber> subscriber_;
64     int32_t currentAvailableId_ = 1;
65     int32_t pageId_ = -1;
66     bool badgeFlag_ = false;
67 };
68 
69 } // namespace OHOS::Ace
70 
71 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_MULTIMODAL_MULTIMODAL_SCENE_H
72