1 /* 2 * Copyright (c) 2021 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 THERMAL_MANAGER_NAPI_H 17 #define THERMAL_MANAGER_NAPI_H 18 19 #include <mutex> 20 21 #include "napi/native_api.h" 22 #include "napi/native_node_api.h" 23 24 #include "ithermal_level_callback.h" 25 #include "thermal_level_callback_stub.h" 26 #include "thermal_mgr_client.h" 27 28 namespace OHOS { 29 namespace PowerMgr { 30 class ThermalLevelCallback : public ThermalLevelCallbackStub { 31 public: 32 ThermalLevelCallback() = default; 33 virtual ~ThermalLevelCallback(); 34 void UpdateCallback(napi_env env, napi_value jsCallback); 35 void ReleaseCallback(); 36 bool GetThermalLevel(ThermalLevel level) override; 37 void OnThermalLevel(); 38 39 private: 40 ThermalLevel level_ {ThermalLevel::COOL}; 41 napi_ref callbackRef_ {nullptr}; 42 napi_env env_ {nullptr}; 43 std::mutex mutex_; 44 }; 45 46 class ThermalManagerNapi { 47 public: 48 ThermalManagerNapi() = default; 49 virtual ~ThermalManagerNapi() = default; 50 51 static napi_value Init(napi_env env, napi_value exports); 52 static napi_value InitThermalLevel(napi_env env, napi_value exports); 53 static napi_value SubscribeThermalLevel(napi_env env, napi_callback_info info); 54 static napi_value UnSubscribeThermalLevel(napi_env env, napi_callback_info info); 55 static napi_value GetThermalLevel(napi_env env, napi_callback_info info); 56 static napi_value EnumThermalLevelConstructor(napi_env env, napi_callback_info info); 57 }; 58 } // namespace PowerMgr 59 } // namespace OHOS 60 #endif // THERMAL_MANAGER_NAPI_H 61