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 PANDA_PLUGINS_ETS_RUNTIME_INTEROP_JS_APP_STATE_MANAGER_H 17 #define PANDA_PLUGINS_ETS_RUNTIME_INTEROP_JS_APP_STATE_MANAGER_H 18 19 #include "libpandabase/os/mutex.h" 20 #include "plugins/ets/runtime/app_state.h" 21 22 namespace ark::ets { 23 24 class AppStateManager final { 25 public: Create()26 static void Create() 27 { 28 ASSERT(instance_ == nullptr); 29 instance_ = new AppStateManager(); 30 } 31 Destroy()32 static void Destroy() 33 { 34 delete instance_; 35 instance_ = nullptr; 36 } 37 GetCurrent()38 static AppStateManager *GetCurrent() 39 { 40 return instance_; 41 } 42 UpdateAppState(AppState appState)43 void UpdateAppState(AppState appState) 44 { 45 os::memory::LockHolder lh(appStateLock_); 46 appState_ = appState; 47 } 48 GetAppState()49 AppState GetAppState() const 50 { 51 os::memory::LockHolder lh(appStateLock_); 52 return appState_; 53 } 54 55 private: 56 AppStateManager() = default; 57 ~AppStateManager() = default; 58 NO_COPY_SEMANTIC(AppStateManager); 59 NO_MOVE_SEMANTIC(AppStateManager); 60 61 static inline AppStateManager *instance_ {nullptr}; 62 mutable os::memory::Mutex appStateLock_; 63 AppState appState_; 64 }; 65 66 } // namespace ark::ets 67 68 #endif // !PANDA_PLUGINS_ETS_RUNTIME_INTEROP_JS_APP_STATE_MANAGER_H 69