1 /* 2 * Copyright (c) 2021-2022 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 AUDIO_COMMON_NAPI_H_ 17 #define AUDIO_COMMON_NAPI_H_ 18 19 #include "napi/native_api.h" 20 #include "napi/native_node_api.h" 21 22 namespace OHOS { 23 namespace AudioStandard { 24 namespace { 25 const std::string INTERRUPT_CALLBACK_NAME = "interrupt"; 26 const std::string STATE_CHANGE_CALLBACK_NAME = "stateChange"; 27 } 28 29 class AudioCommonNapi { 30 public: 31 AudioCommonNapi() = delete; 32 ~AudioCommonNapi() = delete; 33 static std::string GetStringArgument(napi_env env, napi_value value); 34 }; 35 36 struct AutoRef { AutoRefAutoRef37 AutoRef(napi_env env, napi_ref cb) 38 : env_(env), cb_(cb) 39 { 40 } ~AutoRefAutoRef41 ~AutoRef() 42 { 43 if (env_ != nullptr && cb_ != nullptr) { 44 (void)napi_delete_reference(env_, cb_); 45 } 46 } 47 napi_env env_; 48 napi_ref cb_; 49 }; 50 } // namespace AudioStandard 51 } // namespace OHOS 52 #endif // AUDIO_COMMON_NAPI_H_ 53