1 /* 2 * Copyright (c) 2025 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 HIAPPEVENT_FRAMEWORKS_JS_NAPI_INCLUDE_NAPI_ENV_WATCHER_MANAGER_H_ 17 #define HIAPPEVENT_FRAMEWORKS_JS_NAPI_INCLUDE_NAPI_ENV_WATCHER_MANAGER_H_ 18 19 #include <list> 20 #include <mutex> 21 #include <set> 22 23 #include "napi_app_event_watcher.h" 24 #include "napi/native_api.h" 25 26 namespace OHOS { 27 namespace HiviewDFX { 28 29 class EnvWatcherManager { 30 public: 31 static EnvWatcherManager& GetInstance(); 32 33 EnvWatcherManager& operator=(const EnvWatcherManager&) = delete; 34 EnvWatcherManager(const EnvWatcherManager&) = delete; 35 EnvWatcherManager& operator=(const EnvWatcherManager&&) = delete; 36 EnvWatcherManager(const EnvWatcherManager&&) = delete; 37 void RemoveEnvWatcherRecord(const NapiAppEventWatcher* watcher); 38 void AddEnvWatcherRecord(const napi_env env, NapiAppEventWatcher* const watcher); 39 private: 40 ~EnvWatcherManager() = default; 41 EnvWatcherManager() = default; 42 static void OnEnvRemove(void* env); 43 std::mutex mutex_; 44 std::list<std::pair<const napi_env, NapiAppEventWatcher*>> napiEnvWatcherRecords_; 45 std::set<const napi_env> envs_; 46 }; 47 } // namespace HiviewDFX 48 } // namespace OHOS 49 #endif // HIAPPEVENT_FRAMEWORKS_JS_NAPI_INCLUDE_NAPI_ENV_WATCHER_MANAGER_H_ 50