1885b47fbSopenharmony_ci/* 2885b47fbSopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 3885b47fbSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4885b47fbSopenharmony_ci * you may not use this file except in compliance with the License. 5885b47fbSopenharmony_ci * You may obtain a copy of the License at 6885b47fbSopenharmony_ci * 7885b47fbSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8885b47fbSopenharmony_ci * 9885b47fbSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10885b47fbSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11885b47fbSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12885b47fbSopenharmony_ci * See the License for the specific language governing permissions and 13885b47fbSopenharmony_ci * limitations under the License. 14885b47fbSopenharmony_ci */ 15885b47fbSopenharmony_ci 16885b47fbSopenharmony_ci#ifndef ACCESSIBILITY_CONFIG_OBSERVER_H 17885b47fbSopenharmony_ci#define ACCESSIBILITY_CONFIG_OBSERVER_H 18885b47fbSopenharmony_ci 19885b47fbSopenharmony_ci#include <map> 20885b47fbSopenharmony_ci#include <string> 21885b47fbSopenharmony_ci#include <uv.h> 22885b47fbSopenharmony_ci#include "accessibility_config.h" 23885b47fbSopenharmony_ci#include "ffrt.h" 24885b47fbSopenharmony_ci#include "napi/native_api.h" 25885b47fbSopenharmony_ci#include "napi/native_node_api.h" 26885b47fbSopenharmony_ci 27885b47fbSopenharmony_cinamespace OHOS { 28885b47fbSopenharmony_cinamespace Accessibility { 29885b47fbSopenharmony_cinapi_handle_scope TmpOpenScope(napi_env env); 30885b47fbSopenharmony_ci} // namespace Accessibility 31885b47fbSopenharmony_ci} // namespace OHOS 32885b47fbSopenharmony_ci 33885b47fbSopenharmony_ciconst uint32_t CONFIG_START_WORK_ARGS_SIZE = 2; 34885b47fbSopenharmony_ci 35885b47fbSopenharmony_cistruct NAccessibilityConfigObserver { 36885b47fbSopenharmony_cipublic: 37885b47fbSopenharmony_ci NAccessibilityConfigObserver(napi_env env, napi_ref callback, OHOS::AccessibilityConfig::CONFIG_ID id) 38885b47fbSopenharmony_ci : env_(env), handlerRef_(callback), configId_(id) {}; 39885b47fbSopenharmony_ci void OnConfigChanged(const OHOS::AccessibilityConfig::ConfigValue& value); 40885b47fbSopenharmony_ci void OnConfigChangedExtra(const OHOS::AccessibilityConfig::ConfigValue& value); 41885b47fbSopenharmony_ci 42885b47fbSopenharmony_ci void OnDaltonizationColorFilterConfigChanged(); 43885b47fbSopenharmony_ci void NotifyStateChanged2JS(bool enabled); 44885b47fbSopenharmony_ci int NotifyStateChanged(uv_work_t *work); 45885b47fbSopenharmony_ci void NotifyPropertyChanged2JS(const OHOS::AccessibilityConfig::CaptionProperty &caption); 46885b47fbSopenharmony_ci int NotifyPropertyChanged(uv_work_t *work); 47885b47fbSopenharmony_ci void NotifyStringChanged2JS(const std::string& value); 48885b47fbSopenharmony_ci void NotifyStringVectorChanged2JS(std::vector<std::string> value); 49885b47fbSopenharmony_ci int NotifyStringChanged(uv_work_t *work); 50885b47fbSopenharmony_ci int NotifyStringVectorChanged(uv_work_t *work); 51885b47fbSopenharmony_ci void NotifyIntChanged2JS(int32_t value); 52885b47fbSopenharmony_ci int NotifyIntChanged(uv_work_t *work); 53885b47fbSopenharmony_ci void NotifyUintChanged2JS(uint32_t value); 54885b47fbSopenharmony_ci int NotifyUintChanged(uv_work_t *work); 55885b47fbSopenharmony_ci void NotifyFloatChanged2JS(float value); 56885b47fbSopenharmony_ci int NotifyFloatChanged(uv_work_t *work); 57885b47fbSopenharmony_ci 58885b47fbSopenharmony_ci napi_env env_ = nullptr; 59885b47fbSopenharmony_ci napi_ref handlerRef_ = nullptr; 60885b47fbSopenharmony_ci OHOS::AccessibilityConfig::CONFIG_ID configId_ = OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_ID_MAX; 61885b47fbSopenharmony_ci}; 62885b47fbSopenharmony_ci 63885b47fbSopenharmony_ciclass NAccessibilityConfigObserverImpl : public OHOS::AccessibilityConfig::AccessibilityConfigObserver, 64885b47fbSopenharmony_ci public std::enable_shared_from_this<NAccessibilityConfigObserverImpl> { 65885b47fbSopenharmony_cipublic: 66885b47fbSopenharmony_ci NAccessibilityConfigObserverImpl() = default; 67885b47fbSopenharmony_ci virtual void OnConfigChanged( 68885b47fbSopenharmony_ci const OHOS::AccessibilityConfig::CONFIG_ID id, const OHOS::AccessibilityConfig::ConfigValue& value) override; 69885b47fbSopenharmony_ci void SubscribeToFramework(); 70885b47fbSopenharmony_ci void UnsubscribeFromFramework(); 71885b47fbSopenharmony_ci void SubscribeObserver(napi_env env, OHOS::AccessibilityConfig::CONFIG_ID id, napi_value observer); 72885b47fbSopenharmony_ci void UnsubscribeObserver(napi_env env, OHOS::AccessibilityConfig::CONFIG_ID id, napi_value observer); 73885b47fbSopenharmony_ci void UnsubscribeObservers(OHOS::AccessibilityConfig::CONFIG_ID id); 74885b47fbSopenharmony_ci 75885b47fbSopenharmony_ciprivate: 76885b47fbSopenharmony_ci ffrt::mutex mutex_; 77885b47fbSopenharmony_ci std::vector<std::shared_ptr<NAccessibilityConfigObserver>> observers_ = {}; 78885b47fbSopenharmony_ci}; 79885b47fbSopenharmony_ci#endif // ACCESSIBILITY_CONFIG_OBSERVER_H