137a09cd7Sopenharmony_ci/*
237a09cd7Sopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
337a09cd7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
437a09cd7Sopenharmony_ci * you may not use this file except in compliance with the License.
537a09cd7Sopenharmony_ci * You may obtain a copy of the License at
637a09cd7Sopenharmony_ci *
737a09cd7Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
837a09cd7Sopenharmony_ci *
937a09cd7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1037a09cd7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1137a09cd7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1237a09cd7Sopenharmony_ci * See the License for the specific language governing permissions and
1337a09cd7Sopenharmony_ci * limitations under the License.
1437a09cd7Sopenharmony_ci */
1537a09cd7Sopenharmony_ci
1637a09cd7Sopenharmony_ci#include "napi_utils.h"
1737a09cd7Sopenharmony_ci#include "thermal_log.h"
1837a09cd7Sopenharmony_ci
1937a09cd7Sopenharmony_cinamespace OHOS {
2037a09cd7Sopenharmony_cinamespace PowerMgr {
2137a09cd7Sopenharmony_cinapi_value NapiUtils::GetCallbackInfo(napi_env& env, napi_callback_info& info, size_t& argc, napi_value argv[])
2237a09cd7Sopenharmony_ci{
2337a09cd7Sopenharmony_ci    napi_value thisVar = nullptr;
2437a09cd7Sopenharmony_ci    void* data = nullptr;
2537a09cd7Sopenharmony_ci    if (napi_ok != napi_get_cb_info(env, info, &argc, argv, &thisVar, &data)) {
2637a09cd7Sopenharmony_ci        THERMAL_HILOGW(COMP_APP, "Failed to get the input parameter");
2737a09cd7Sopenharmony_ci    }
2837a09cd7Sopenharmony_ci    return thisVar;
2937a09cd7Sopenharmony_ci}
3037a09cd7Sopenharmony_ci
3137a09cd7Sopenharmony_cibool NapiUtils::CheckValueType(napi_env& env, napi_value& value, napi_valuetype checkType)
3237a09cd7Sopenharmony_ci{
3337a09cd7Sopenharmony_ci    napi_valuetype valueType = napi_undefined;
3437a09cd7Sopenharmony_ci    napi_typeof(env, value, &valueType);
3537a09cd7Sopenharmony_ci    if (valueType != checkType) {
3637a09cd7Sopenharmony_ci        THERMAL_HILOGW(COMP_APP, "Parameter type error");
3737a09cd7Sopenharmony_ci        return false;
3837a09cd7Sopenharmony_ci    }
3937a09cd7Sopenharmony_ci    return true;
4037a09cd7Sopenharmony_ci}
4137a09cd7Sopenharmony_ci} // namespace PowerMgr
4237a09cd7Sopenharmony_ci} // namespace OHOS
43