1 /* 2 * Copyright (c) 2023 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_RECORDER_EVENT_CONTROLLER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_RECORDER_EVENT_CONTROLLER_H 18 19 #include <shared_mutex> 20 #include <string> 21 #include <unordered_map> 22 #include <vector> 23 24 #include "interfaces/inner_api/ace/ui_event_observer.h" 25 #include "base/utils/noncopyable.h" 26 #include "core/common/recorder/event_config.h" 27 28 namespace OHOS::Ace::Recorder { 29 struct UIEventClient { 30 std::shared_ptr<UIEventObserver> observer; 31 EventConfig config; 32 }; 33 34 class EventController final { 35 public: 36 static EventController& Get(); 37 38 void Register(const std::string& config, const std::shared_ptr<UIEventObserver>& observer); 39 void Unregister(const std::shared_ptr<UIEventObserver>& observer); 40 41 void NotifyEvent(EventCategory category, int32_t eventType, 42 const std::shared_ptr<std::unordered_map<std::string, std::string>>& eventParams); 43 44 void NotifyEventSync(EventCategory category, int32_t eventType, 45 const std::shared_ptr<std::unordered_map<std::string, std::string>>& eventParams); 46 47 private: 48 EventController() = default; 49 ~EventController() = default; 50 void NotifyConfigChange(); 51 void ApplyNewestConfig() const; 52 void ApplyExposureCfgInner(const std::shared_ptr<Config>& config) const; 53 54 std::shared_mutex mutable cacheLock_; 55 std::vector<UIEventClient> clientList_; 56 57 ACE_DISALLOW_COPY_AND_MOVE(EventController); 58 }; 59 } // namespace OHOS::Ace::Recorder 60 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_RECORDER_EVENT_CONTROLLER_H 61